Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29258 > unrolled thread

Memory allocation overflow

Started byjonas.thornvall@gmail.com
First post2016-01-16 09:58 -0800
Last post2016-01-18 16:09 +0100
Articles 20 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 09:58 -0800
    Re: Memory allocation overflow "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-16 19:52 +0100
      Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 11:03 -0800
        Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 11:05 -0800
          Re: Memory allocation overflow Luuk <luuk@invalid.lan> - 2016-01-16 20:13 +0100
            Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 11:25 -0800
              Re: Memory allocation overflow Luuk <luuk@invalid.lan> - 2016-01-16 21:25 +0100
                Re: Memory allocation overflow Luuk <luuk@invalid.lan> - 2016-01-16 21:31 +0100
                  Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 14:06 -0800
                    Re: Memory allocation overflow John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-17 11:08 +0000
                      Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-17 04:10 -0800
                        Re: Memory allocation overflow Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-17 20:15 +0000
                          Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-17 13:25 -0800
                            Re: Memory allocation overflow Carlos Pedro <carlospedr@gmail.com> - 2016-01-18 08:21 -0800
        Re: Memory allocation overflow "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-16 20:29 +0100
    Re: Memory allocation overflow Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-16 23:43 +0000
      Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 19:30 -0800
        Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 19:56 -0800
          Re: Memory allocation overflow jonas.thornvall@gmail.com - 2016-01-16 20:01 -0800
    Re: Memory allocation overflow Silvio <silvio@internet.com> - 2016-01-18 16:09 +0100

#29258 — Memory allocation overflow

Fromjonas.thornvall@gmail.com
Date2016-01-16 09:58 -0800
SubjectMemory allocation overflow
Message-ID<4eb1912d-87cd-4e4b-a4b0-5154de752831@googlegroups.com>
What could possibly overflow in this?

To me it seems just weird

j=1;
while(j<=base){
prime=false;
i=j;
i=i+base;
while (i<100){
 primeleg=factor_it(i);
 if(primeleg==true){break;}
 i=i+base;
}
outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
j++;
}






The full code below------------------------
<script language="Javascript">

function factor_it(i){
prime=true;
sqroot=Math.floor(Math.sqrt(i));
for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime) {return prime}}
return prime;
}

function main(){
base=10;
outStr="";

//while (base==10) {

j=1;
while(j<=base){
prime=false;
i=j;
i=i+base;
while (i<100){
 primeleg=factor_it(i);
 if(primeleg==true){break;}
 i=i+base;
}
outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
j++;
}

//base++;
//}
document.prime.out.value =outStr;
}
</script>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>

<body onload="main()" bgcolor="gold">
<form name="prime" action="" onsubmit="MAIN(); return false;">
<textarea name="out" cols=80 rows=80></textarea>
</form>
</body>
</html>

[toc] | [next] | [standalone]


#29259

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-01-16 19:52 +0100
Message-ID<XnsA591CA3AF7869eejj99@194.109.6.166>
In reply to#29258
jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:

> What could possibly overflow in this?
> 
> To me it seems just weird
> 
> j=1;
> while(j<=base){

Usually the overflow is that j>base will never be reached.

As I have suggested before, debugging is better than guessing,
so add a console.log() writing each cycle.

And in IMHO you should not ask without those test-results.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#29260

Fromjonas.thornvall@gmail.com
Date2016-01-16 11:03 -0800
Message-ID<bd35a056-a331-44e0-8f8e-c18c77c23088@googlegroups.com>
In reply to#29259
Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
> 
> > What could possibly overflow in this?
> > 
> > To me it seems just weird
> > 
> > j=1;
> > while(j<=base){
> 
> Usually the overflow is that j>base will never be reached.
> 
> As I have suggested before, debugging is better than guessing,
> so add a console.log() writing each cycle.
> 
> And in IMHO you should not ask without those test-results.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
There is two options either you tell me that the inner loop never exceed 100 which seem impossible because here base is constant 10 never change, and i takes on the value of j a counter that start with 1 and as j adds up so does i.

And when i> base which is 10 the loop breaks.
How can you spend so fucking much time writing text that doesn't give a clue to what is wrong?


Why doesn't j reach 10
or 
Why doesn't i reach 100 that is what i would like to know.

I can't see why the adds do not reach the constants values when i add to them, can you see it?

[toc] | [prev] | [next] | [standalone]


#29261

Fromjonas.thornvall@gmail.com
Date2016-01-16 11:05 -0800
Message-ID<6eb593a1-95cd-446f-aa0f-d15a2593ad38@googlegroups.com>
In reply to#29260
Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev jonas.t...@gmail.com:
> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
> > jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
> > 
> > > What could possibly overflow in this?
> > > 
> > > To me it seems just weird
> > > 
> > > j=1;
> > > while(j<=base){
> > 
> > Usually the overflow is that j>base will never be reached.
> > 
> > As I have suggested before, debugging is better than guessing,
> > so add a console.log() writing each cycle.
> > 
> > And in IMHO you should not ask without those test-results.
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> There is two options either you tell me that the inner loop never exceed 100 which seem impossible because here base is constant 10 never change, and i takes on the value of j a counter that start with 1 and as j adds up so does i.
> 
> And when i> base which is 10 the loop breaks.
> How can you spend so fucking much time writing text that doesn't give a clue to what is wrong?
> 
> 
> Why doesn't j reach 10
> or 
> Why doesn't i reach 100 that is what i would like to know.
> 
> I can't see why the adds do not reach the constants values when i add to them, can you see it?

For each innerloop i adds up with base=10
For each outerloop j adds up with 1

So why don't they break?

[toc] | [prev] | [next] | [standalone]


#29262

FromLuuk <luuk@invalid.lan>
Date2016-01-16 20:13 +0100
Message-ID<569a963f$0$23842$e4fe514c@news.xs4all.nl>
In reply to#29261
On 16-01-16 20:05, jonas.thornvall@gmail.com wrote:
> Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev jonas.t...@gmail.com:
>> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
>>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
>>>
>>>> What could possibly overflow in this?
>>>>
>>>> To me it seems just weird
>>>>
>>>> j=1;
>>>> while(j<=base){
>>>
>>> Usually the overflow is that j>base will never be reached.
>>>
>>> As I have suggested before, debugging is better than guessing,
>>> so add a console.log() writing each cycle.
>>>
>>> And in IMHO you should not ask without those test-results.
>>>
>>> --
>>> Evertjan.
>>> The Netherlands.
>>> (Please change the x'es to dots in my emailaddress)
>> There is two options either you tell me that the inner loop never exceed 100 which seem impossible because here base is constant 10 never change, and i takes on the value of j a counter that start with 1 and as j adds up so does i.
>>
>> And when i> base which is 10 the loop breaks.
>> How can you spend so fucking much time writing text that doesn't give a clue to what is wrong?
>>
>>
>> Why doesn't j reach 10
>> or
>> Why doesn't i reach 100 that is what i would like to know.
>>
>> I can't see why the adds do not reach the constants values when i add to them, can you see it?
>
> For each innerloop i adds up with base=10
> For each outerloop j adds up with 1
>
> So why don't they break?
>

In the example code you gave:
- base does not get a value
- outStr also does not get a value
- what is the definition of 'factor_it(i)' ?


so, yes, i am also not giving a clue what is wrong...
and i also do not have a clue what is wrong...

;)

[toc] | [prev] | [next] | [standalone]


#29263

Fromjonas.thornvall@gmail.com
Date2016-01-16 11:25 -0800
Message-ID<d79593b4-64db-4094-b715-eee08067e812@googlegroups.com>
In reply to#29262
Den lördag 16 januari 2016 kl. 20:13:09 UTC+1 skrev Luuk:
> On 16-01-16 20:05, jonas.thornvall@gmail.com wrote:
> > Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev jonas.t...@gmail.com:
> >> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
> >>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
> >>>
> >>>> What could possibly overflow in this?
> >>>>
> >>>> To me it seems just weird
> >>>>
> >>>> j=1;
> >>>> while(j<=base){
> >>>
> >>> Usually the overflow is that j>base will never be reached.
> >>>
> >>> As I have suggested before, debugging is better than guessing,
> >>> so add a console.log() writing each cycle.
> >>>
> >>> And in IMHO you should not ask without those test-results.
> >>>
> >>> --
> >>> Evertjan.
> >>> The Netherlands.
> >>> (Please change the x'es to dots in my emailaddress)
> >> There is two options either you tell me that the inner loop never exceed 100 which seem impossible because here base is constant 10 never change, and i takes on the value of j a counter that start with 1 and as j adds up so does i.
> >>
> >> And when i> base which is 10 the loop breaks.
> >> How can you spend so fucking much time writing text that doesn't give a clue to what is wrong?
> >>
> >>
> >> Why doesn't j reach 10
> >> or
> >> Why doesn't i reach 100 that is what i would like to know.
> >>
> >> I can't see why the adds do not reach the constants values when i add to them, can you see it?
> >
> > For each innerloop i adds up with base=10
> > For each outerloop j adds up with 1
> >
> > So why don't they break?
> >
> 
> In the example code you gave:
> - base does not get a value
> - outStr also does not get a value
> - what is the definition of 'factor_it(i)' ?
> 
> 
> so, yes, i am also not giving a clue what is wrong...
> and i also do not have a clue what is wrong...
> 
> ;)
In the first message of thread if you bothered so scroll down 5 lines was the full script...

I tried to pick out the crucial part and show first...

[toc] | [prev] | [next] | [standalone]


#29265

FromLuuk <luuk@invalid.lan>
Date2016-01-16 21:25 +0100
Message-ID<569aa72a$0$23819$e4fe514c@news.xs4all.nl>
In reply to#29263
On 16-01-16 20:25, jonas.thornvall@gmail.com wrote:
> Den lördag 16 januari 2016 kl. 20:13:09 UTC+1 skrev Luuk:
>> On 16-01-16 20:05, jonas.thornvall@gmail.com wrote:
>>> Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev jonas.t...@gmail.com:
>>>> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
>>>>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
>>>>>
>>>>>> What could possibly overflow in this?
>>>>>>
>>>>>> To me it seems just weird
>>>>>>
>>>>>> j=1;
>>>>>> while(j<=base){
>>>>>
>>>>> Usually the overflow is that j>base will never be reached.
>>>>>
>>>>> As I have suggested before, debugging is better than guessing,
>>>>> so add a console.log() writing each cycle.
>>>>>
>>>>> And in IMHO you should not ask without those test-results.
>>>>>
>>>>> --
>>>>> Evertjan.
>>>>> The Netherlands.
>>>>> (Please change the x'es to dots in my emailaddress)
>>>> There is two options either you tell me that the inner loop never exceed 100 which seem impossible because here base is constant 10 never change, and i takes on the value of j a counter that start with 1 and as j adds up so does i.
>>>>
>>>> And when i> base which is 10 the loop breaks.
>>>> How can you spend so fucking much time writing text that doesn't give a clue to what is wrong?
>>>>
>>>>
>>>> Why doesn't j reach 10
>>>> or
>>>> Why doesn't i reach 100 that is what i would like to know.
>>>>
>>>> I can't see why the adds do not reach the constants values when i add to them, can you see it?
>>>
>>> For each innerloop i adds up with base=10
>>> For each outerloop j adds up with 1
>>>
>>> So why don't they break?
>>>
>>
>> In the example code you gave:
>> - base does not get a value
>> - outStr also does not get a value
>> - what is the definition of 'factor_it(i)' ?
>>
>>
>> so, yes, i am also not giving a clue what is wrong...
>> and i also do not have a clue what is wrong...
>>
>> ;)
> In the first message of thread if you bothered so scroll down 5 lines was the full script...
>
> I tried to pick out the crucial part and show first...
>


maybe you should not post part of the code,
and then the complete code, which is only a bit longer......


and you should read this website:
http://www.w3schools.com.js/......

it has the clue to your problem.... ;)

[toc] | [prev] | [next] | [standalone]


#29266

FromLuuk <luuk@invalid.lan>
Date2016-01-16 21:31 +0100
Message-ID<569aa8a2$0$23819$e4fe514c@news.xs4all.nl>
In reply to#29265
On 16-01-16 21:25, Luuk wrote:
> On 16-01-16 20:25, jonas.thornvall@gmail.com wrote:
>> Den lördag 16 januari 2016 kl. 20:13:09 UTC+1 skrev Luuk:
>>> On 16-01-16 20:05, jonas.thornvall@gmail.com wrote:
>>>> Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev
>>>> jonas.t...@gmail.com:
>>>>> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
>>>>>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in
>>>>>> comp.lang.javascript:
>>>>>>
>>>>>>> What could possibly overflow in this?
>>>>>>>
>>>>>>> To me it seems just weird
>>>>>>>
>>>>>>> j=1;
>>>>>>> while(j<=base){
>>>>>>
>>>>>> Usually the overflow is that j>base will never be reached.
>>>>>>
>>>>>> As I have suggested before, debugging is better than guessing,
>>>>>> so add a console.log() writing each cycle.
>>>>>>
>>>>>> And in IMHO you should not ask without those test-results.
>>>>>>
>>>>>> --
>>>>>> Evertjan.
>>>>>> The Netherlands.
>>>>>> (Please change the x'es to dots in my emailaddress)
>>>>> There is two options either you tell me that the inner loop never
>>>>> exceed 100 which seem impossible because here base is constant 10
>>>>> never change, and i takes on the value of j a counter that start
>>>>> with 1 and as j adds up so does i.
>>>>>
>>>>> And when i> base which is 10 the loop breaks.
>>>>> How can you spend so fucking much time writing text that doesn't
>>>>> give a clue to what is wrong?
>>>>>
>>>>>
>>>>> Why doesn't j reach 10
>>>>> or
>>>>> Why doesn't i reach 100 that is what i would like to know.
>>>>>
>>>>> I can't see why the adds do not reach the constants values when i
>>>>> add to them, can you see it?
>>>>
>>>> For each innerloop i adds up with base=10
>>>> For each outerloop j adds up with 1
>>>>
>>>> So why don't they break?
>>>>
>>>
>>> In the example code you gave:
>>> - base does not get a value
>>> - outStr also does not get a value
>>> - what is the definition of 'factor_it(i)' ?
>>>
>>>
>>> so, yes, i am also not giving a clue what is wrong...
>>> and i also do not have a clue what is wrong...
>>>
>>> ;)
>> In the first message of thread if you bothered so scroll down 5 lines
>> was the full script...
>>
>> I tried to pick out the crucial part and show first...
>>
>
>
> maybe you should not post part of the code,
> and then the complete code, which is only a bit longer......
>
>
> and you should read this website:
> http://www.w3schools.com.js/......
>
> it has the clue to your problem.... ;)


oops, that link should be:
http://www.w3schools.com/js/......

sorry for the typo....

[toc] | [prev] | [next] | [standalone]


#29267

Fromjonas.thornvall@gmail.com
Date2016-01-16 14:06 -0800
Message-ID<648d8d6b-e296-4b52-96e5-8c66e1cb06be@googlegroups.com>
In reply to#29266
Den lördag 16 januari 2016 kl. 21:31:52 UTC+1 skrev Luuk:
> On 16-01-16 21:25, Luuk wrote:
> > On 16-01-16 20:25, jonas.thornvall@gmail.com wrote:
> >> Den lördag 16 januari 2016 kl. 20:13:09 UTC+1 skrev Luuk:
> >>> On 16-01-16 20:05, jonas.thornvall@gmail.com wrote:
> >>>> Den lördag 16 januari 2016 kl. 20:03:33 UTC+1 skrev
> >>>> jonas.t...@gmail.com:
> >>>>> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
> >>>>>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in
> >>>>>> comp.lang.javascript:
> >>>>>>
> >>>>>>> What could possibly overflow in this?
> >>>>>>>
> >>>>>>> To me it seems just weird
> >>>>>>>
> >>>>>>> j=1;
> >>>>>>> while(j<=base){
> >>>>>>
> >>>>>> Usually the overflow is that j>base will never be reached.
> >>>>>>
> >>>>>> As I have suggested before, debugging is better than guessing,
> >>>>>> so add a console.log() writing each cycle.
> >>>>>>
> >>>>>> And in IMHO you should not ask without those test-results.
> >>>>>>
> >>>>>> --
> >>>>>> Evertjan.
> >>>>>> The Netherlands.
> >>>>>> (Please change the x'es to dots in my emailaddress)
> >>>>> There is two options either you tell me that the inner loop never
> >>>>> exceed 100 which seem impossible because here base is constant 10
> >>>>> never change, and i takes on the value of j a counter that start
> >>>>> with 1 and as j adds up so does i.
> >>>>>
> >>>>> And when i> base which is 10 the loop breaks.
> >>>>> How can you spend so fucking much time writing text that doesn't
> >>>>> give a clue to what is wrong?
> >>>>>
> >>>>>
> >>>>> Why doesn't j reach 10
> >>>>> or
> >>>>> Why doesn't i reach 100 that is what i would like to know.
> >>>>>
> >>>>> I can't see why the adds do not reach the constants values when i
> >>>>> add to them, can you see it?
> >>>>
> >>>> For each innerloop i adds up with base=10
> >>>> For each outerloop j adds up with 1
> >>>>
> >>>> So why don't they break?
> >>>>
> >>>
> >>> In the example code you gave:
> >>> - base does not get a value
> >>> - outStr also does not get a value
> >>> - what is the definition of 'factor_it(i)' ?
> >>>
> >>>
> >>> so, yes, i am also not giving a clue what is wrong...
> >>> and i also do not have a clue what is wrong...
> >>>
> >>> ;)
> >> In the first message of thread if you bothered so scroll down 5 lines
> >> was the full script...
> >>
> >> I tried to pick out the crucial part and show first...
> >>
> >
> >
> > maybe you should not post part of the code,
> > and then the complete code, which is only a bit longer......
> >
> >
> > and you should read this website:
> > http://www.w3schools.com.js/......
> >
> > it has the clue to your problem.... ;)
> 
> 
> oops, that link should be:
> http://www.w3schools.com/js/......
> 
> sorry for the typo....

Oh my gosh a monkey doing a parrots job, this must be the shittiest NG in the galayx. Jast saw star wars.

Oh no monkey leave the job to the parrots at least they have the mindset to bring up some heat on the issue, that make me debug the code myself.

But it is so fucking weird that people in this NG are in total refusal to reveal any bug they spot. They just want general questions that they can answer with a yes or no. Asking if the sky is blue can lead draw you into all sort of issues, that it depend upon the wavelength and the medium it pass, and you are refered to a document with maxwells equations...

Well that is just life i guess.


Well

[toc] | [prev] | [next] | [standalone]


#29282

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-01-17 11:08 +0000
Message-ID<3gtm9b9u37e7viv4rvs94cjf49ae9v22nk@4ax.com>
In reply to#29267
On Sat, 16 Jan 2016 14:06:18 -0800 (PST), jonas.thornvall@gmail.com
wrote:

  <snip>
>Oh my gosh a monkey doing a parrots job, this must be the shittiest NG
>in the galayx. Jast saw star wars.
>
>Oh no monkey leave the job to the parrots at least they have the
>mindset to bring up some heat on the issue, that make me debug the
>code myself.
>
>But it is so fucking weird that people in this NG are in total refusal
>to reveal any bug they spot. They just want general questions that
>they can answer with a yes or no.
  <snip>

There speaks someone who expects people to spend an hour on messy code
and work out for themselves what each function should do.

By the way, shouldn't factor_it return false when i/j is an integer,
not true the first time it isn't?

And wouldn't it be simpler to see if the remainder, i%j, is zero?

  John

[toc] | [prev] | [next] | [standalone]


#29284

Fromjonas.thornvall@gmail.com
Date2016-01-17 04:10 -0800
Message-ID<caca3674-66d1-43ad-a079-9b75f41267b0@googlegroups.com>
In reply to#29282
Den söndag 17 januari 2016 kl. 12:08:48 UTC+1 skrev John Harris:
> On Sat, 16 Jan 2016 14:06:18 -0800 (PST), jonas.thornvall@gmail.com
> wrote:
> 
>   <snip>
> >Oh my gosh a monkey doing a parrots job, this must be the shittiest NG
> >in the galayx. Jast saw star wars.
> >
> >Oh no monkey leave the job to the parrots at least they have the
> >mindset to bring up some heat on the issue, that make me debug the
> >code myself.
> >
> >But it is so fucking weird that people in this NG are in total refusal
> >to reveal any bug they spot. They just want general questions that
> >they can answer with a yes or no.
>   <snip>
> 
> There speaks someone who expects people to spend an hour on messy code
> and work out for themselves what each function should do.
> 
> By the way, shouldn't factor_it return false when i/j is an integer,
> not true the first time it isn't?
> 
> And wouldn't it be simpler to see if the remainder, i%j, is zero?
> 
>   John

I think i did read isInteger is faster.

I fixed the script and logic. Feel free to comment if you find the logic absurd. 

http://jt.node365.se/composite.html

<script language="Javascript">

function factor_it(i){
prime=true;
sqroot=Math.floor(Math.sqrt(i));
for (s=2;s<=sqroot;s++){ k=i/s; prime=Number.isInteger(k); if (prime) {
//outStr+=i+" / "+s+" = "+k+" Composite, prime= "+!prime+" \n";
return prime}}
//outStr+="I= "+i+" K= "+k+" Prime break= "+!prime+" \n";
return prime;
}

function main(){
base=3;
outStr="";
reduceleg=0;
while (base<2000) {
outStr+="NEWBASE = "+base+" ------------------------------------------\n";
j=1;

while(j<=base){
i=j;
i=i+base;

while (i<10000){

 prime=factor_it(i);
 primeleg=!prime;
 //outStr+=i+" Prime ="+prime+"\n";
 if(primeleg==true){break;}
 i=i+base;
}
if(primeleg==false)reduceleg++;
//outStr+="primeleg ="+primeleg+"\n\n";
j++;
}
fraction=100*(reduceleg/base);
outStr+="BASE= "+base+" Composite legs= "+fraction+"% ===============\n\n\n";
reduceleg=0;
base++;
}
document.prima.out.value =outStr;
}
</script>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>

<body onload="main()" bgcolor="gold">
<H1>FINDING BASES WITH COMPOSITE LEGS<BR>
 "WILL MAKE A COUNTER THAT REDUCE SEARCHSPACE FOR PRIMES"
<form name="prima" action="" onsubmit="MAIN(); return false;">
<textarea name="out" cols=80 rows=80></textarea>
<textarea name="trash" cols=80 rows=80></textarea>
</form>
</body>
</html>

[toc] | [prev] | [next] | [standalone]


#29292

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-01-17 20:15 +0000
Message-ID<878u3odktt.fsf@bsb.me.uk>
In reply to#29284
jonas.thornvall@gmail.com writes:

> Den söndag 17 januari 2016 kl. 12:08:48 UTC+1 skrev John Harris:
>> On Sat, 16 Jan 2016 14:06:18 -0800 (PST), jonas.thornvall@gmail.com
>> wrote:
>> 
>>   <snip>
>> >Oh my gosh a monkey doing a parrots job, this must be the shittiest NG
>> >in the galayx. Jast saw star wars.
>> >
>> >Oh no monkey leave the job to the parrots at least they have the
>> >mindset to bring up some heat on the issue, that make me debug the
>> >code myself.
>> >
>> >But it is so fucking weird that people in this NG are in total refusal
>> >to reveal any bug they spot. They just want general questions that
>> >they can answer with a yes or no.
>>   <snip>
>> 
>> There speaks someone who expects people to spend an hour on messy code
>> and work out for themselves what each function should do.
>> 
>> By the way, shouldn't factor_it return false when i/j is an integer,
>> not true the first time it isn't?
>> 
>> And wouldn't it be simpler to see if the remainder, i%j, is zero?
>> 
>
> I think i did read isInteger is faster.

Did you test it?  On at least one system, I found that a version of your
function with % rather than / and isInteger was 4 times faster.  (And
you get another factor of 2 by not testing division by all even numbers.
You'll get even more speed if you use a prime sieve.)

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#29294

Fromjonas.thornvall@gmail.com
Date2016-01-17 13:25 -0800
Message-ID<7245c3e3-f47b-4145-965c-ddfdfcf25198@googlegroups.com>
In reply to#29292
Den söndag 17 januari 2016 kl. 21:15:18 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> > Den söndag 17 januari 2016 kl. 12:08:48 UTC+1 skrev John Harris:
> >> On Sat, 16 Jan 2016 14:06:18 -0800 (PST), jonas.thornvall@gmail.com
> >> wrote:
> >> 
> >>   <snip>
> >> >Oh my gosh a monkey doing a parrots job, this must be the shittiest NG
> >> >in the galayx. Jast saw star wars.
> >> >
> >> >Oh no monkey leave the job to the parrots at least they have the
> >> >mindset to bring up some heat on the issue, that make me debug the
> >> >code myself.
> >> >
> >> >But it is so fucking weird that people in this NG are in total refusal
> >> >to reveal any bug they spot. They just want general questions that
> >> >they can answer with a yes or no.
> >>   <snip>
> >> 
> >> There speaks someone who expects people to spend an hour on messy code
> >> and work out for themselves what each function should do.
> >> 
> >> By the way, shouldn't factor_it return false when i/j is an integer,
> >> not true the first time it isn't?
> >> 
> >> And wouldn't it be simpler to see if the remainder, i%j, is zero?
> >> 
> >
> > I think i did read isInteger is faster.
> 
> Did you test it?  On at least one system, I found that a version of your
> function with % rather than / and isInteger was 4 times faster.  (And
> you get another factor of 2 by not testing division by all even numbers.
> You'll get even more speed if you use a prime sieve.)
> 
> <snip>
> -- 
> Ben.

Well it is not a prime sieve it is a composite leg sieve, the legs that is not composite will be stored in an array as the startpoints for counters in the base.

The bases with least legs with only composite is those on the form 3*5*7*11... and so on.

What this script do is finding the base and the canditats to include in the counter while discarding the composit legs.

[toc] | [prev] | [next] | [standalone]


#29311

FromCarlos Pedro <carlospedr@gmail.com>
Date2016-01-18 08:21 -0800
Message-ID<9918ea95-e467-464b-8282-fe4b8d952d8e@googlegroups.com>
In reply to#29294
> What this script do is finding the base and the canditats to include in the counter while discarding the composit legs.

you are not using a single local variable in your script. doing this one should expect sort of unexpected behaviour. this problem exists in most of the scripts in jt.node365.se not just the composit_llegs.html.

[toc] | [prev] | [next] | [standalone]


#29264

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-01-16 20:29 +0100
Message-ID<XnsA591D079B41EFeejj99@194.109.6.166>
In reply to#29260
jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:

> Den lördag 16 januari 2016 kl. 19:52:54 UTC+1 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 16 Jan 2016 in comp.lang.javascript:
>> 
>> > What could possibly overflow in this?
>> > 
>> > To me it seems just weird
>> > 
>> > j=1;
>> > while(j<=base){
>> 
>> Usually the overflow is that j>base will never be reached.
>> 
>> As I have suggested before, debugging is better than guessing,
>> so add a console.log() writing each cycle.
>> 
>> And in IMHO you should not ask without those test-results.

> There is two options either you tell me that the inner loop never exceed

You are the asking party, 
my options are only limited by my imagination,
so do not tell me how I should answer,
that would be somewhat impolite.

How do you know that there are only two,
without debugging what is wrong in your syntax or in your mind?

> 100 which seem impossible because here base is constant 10 never change,
> and i takes on the value of j a counter that start with 1 and as j adds
> up so does i. 

You are wrong here, I am not going to tell you because it your job to debug 
your code, and not to bother us with undebugged code.

> And when i> base which is 10 the loop breaks.

First you wll have to debug and see WHERE things go the other way than you 
think.

> How can you spend so fucking much time writing text that doesn't give a
> clue to what is wrong? 

Me? You are not paying the slightest attention to serious help.

> Why doesn't j reach 10

Unimportant, first debug if it is so.

> or 
> Why doesn't i reach 100 that is what i would like to know.

Unimportant, first debug if.

> I can't see why the adds do not reach the constants values when i add to
> them, can you see it? 

Unimportant, first debug 
and then you will find your syntactical mistake or your logical mistake.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#29270

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-01-16 23:43 +0000
Message-ID<87egdhgkfp.fsf@bsb.me.uk>
In reply to#29258
jonas.thornvall@gmail.com writes:

> What could possibly overflow in this?

The string.

> To me it seems just weird

The best thing to do would be to learn the language yo are using.  Until
you do everything you write is likely to seem weird.  Most of the names
you use refer to properties of the global object, so the j in one place
is the same j used in another.

> j=1;
> while(j<=base){

This test is never false.

> prime=false;
> i=j;
> i=i+base;
> while (i<100){
>  primeleg=factor_it(i);
>  if(primeleg==true){break;}
>  i=i+base;
> }
> outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> j++;
> }

<snip>
> The full code below------------------------
> <script language="Javascript">
>
> function factor_it(i){
> prime=true;
> sqroot=Math.floor(Math.sqrt(i));
> for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime)
> {return prime}}
> return prime;
> }

This function is very odd.  Nothing it does has much to do with the
names used -- prime and factor_it.  It does not factor the number i, nor
does it test for i being prime.  But, crucially, it alters j which you
use elsewhere.

That kind of programming is not sustainable.  You really need to learn
how to write self-contained functions that do their job without messing
up the rest of the program.

> function main(){
> base=10;
> outStr="";
>
> //while (base==10) {
>
> j=1;
> while(j<=base){
> prime=false;
> i=j;
> i=i+base;
> while (i<100){
>  primeleg=factor_it(i);
>  if(primeleg==true){break;}
>  i=i+base;
> }
> outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> j++;
> }
>
> //base++;
> //}
> document.prime.out.value =outStr;
> }

Left for reference.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#29276

Fromjonas.thornvall@gmail.com
Date2016-01-16 19:30 -0800
Message-ID<1bdc5946-5bfb-4b97-8bd9-835390af3331@googlegroups.com>
In reply to#29270
Den söndag 17 januari 2016 kl. 00:43:12 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> > What could possibly overflow in this?
> 
> The string.
> 
> > To me it seems just weird
> 
> The best thing to do would be to learn the language yo are using.  Until
> you do everything you write is likely to seem weird.  Most of the names
> you use refer to properties of the global object, so the j in one place
> is the same j used in another.
> 
> > j=1;
> > while(j<=base){
> 
> This test is never false.
> 
> > prime=false;
> > i=j;
> > i=i+base;
> > while (i<100){
> >  primeleg=factor_it(i);
> >  if(primeleg==true){break;}
> >  i=i+base;
> > }
> > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > j++;
> > }
> 
> <snip>
> > The full code below------------------------
> > <script language="Javascript">
> >
> > function factor_it(i){
> > prime=true;
> > sqroot=Math.floor(Math.sqrt(i));
> > for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime)
> > {return prime}}
> > return prime;
> > }
> 
> This function is very odd.  Nothing it does has much to do with the
> names used -- prime and factor_it.  It does not factor the number i, nor
> does it test for i being prime.  But, crucially, it alters j which you
> use elsewhere.
> 
> That kind of programming is not sustainable.  You really need to learn
> how to write self-contained functions that do their job without messing
> up the rest of the program.
> 
> > function main(){
> > base=10;
> > outStr="";
> >
> > //while (base==10) {
> >
> > j=1;
> > while(j<=base){
> > prime=false;
> > i=j;
> > i=i+base;
> > while (i<100){
> >  primeleg=factor_it(i);
> >  if(primeleg==true){break;}
> >  i=i+base;
> > }
> > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > j++;
> > }
> >
> > //base++;
> > //}
> > document.prime.out.value =outStr;
> > }
> 
> Left for reference.
> 
> -- 
> Ben.

Hello Ben the script is working now i only tried it upto 10, and the best is base 6 there you can create a counter that reduce the composites from the integer field and reduce the integers with 66.666...%


http://jt.node365.se/composit_llegs.html 

But of course there could be bases that reduce the result even more. The none composit legs will be read into an array as start point for the counter but that is later first find the best base.

I try to reduce the number of primes needed to check by finding a base that is suitable. So far i only checked to base 10 with my little script.

But i would like to know is there a known upper limit for the possible reduction of composit counters?

If so what is the base, i noticed in base 6 i can reduce the integer field with 66,666... percent maybe that is the best?

http://jt.node365.se/composit_llegs.html

[toc] | [prev] | [next] | [standalone]


#29277

Fromjonas.thornvall@gmail.com
Date2016-01-16 19:56 -0800
Message-ID<c6dae50d-ac8e-4edc-aa5e-8ec0c71c7bb1@googlegroups.com>
In reply to#29276
Den söndag 17 januari 2016 kl. 04:30:28 UTC+1 skrev jonas.t...@gmail.com:
> Den söndag 17 januari 2016 kl. 00:43:12 UTC+1 skrev Ben Bacarisse:
> > jonas.thornvall@gmail.com writes:
> > 
> > > What could possibly overflow in this?
> > 
> > The string.
> > 
> > > To me it seems just weird
> > 
> > The best thing to do would be to learn the language yo are using.  Until
> > you do everything you write is likely to seem weird.  Most of the names
> > you use refer to properties of the global object, so the j in one place
> > is the same j used in another.
> > 
> > > j=1;
> > > while(j<=base){
> > 
> > This test is never false.
> > 
> > > prime=false;
> > > i=j;
> > > i=i+base;
> > > while (i<100){
> > >  primeleg=factor_it(i);
> > >  if(primeleg==true){break;}
> > >  i=i+base;
> > > }
> > > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > > j++;
> > > }
> > 
> > <snip>
> > > The full code below------------------------
> > > <script language="Javascript">
> > >
> > > function factor_it(i){
> > > prime=true;
> > > sqroot=Math.floor(Math.sqrt(i));
> > > for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime)
> > > {return prime}}
> > > return prime;
> > > }
> > 
> > This function is very odd.  Nothing it does has much to do with the
> > names used -- prime and factor_it.  It does not factor the number i, nor
> > does it test for i being prime.  But, crucially, it alters j which you
> > use elsewhere.
> > 
> > That kind of programming is not sustainable.  You really need to learn
> > how to write self-contained functions that do their job without messing
> > up the rest of the program.
> > 
> > > function main(){
> > > base=10;
> > > outStr="";
> > >
> > > //while (base==10) {
> > >
> > > j=1;
> > > while(j<=base){
> > > prime=false;
> > > i=j;
> > > i=i+base;
> > > while (i<100){
> > >  primeleg=factor_it(i);
> > >  if(primeleg==true){break;}
> > >  i=i+base;
> > > }
> > > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > > j++;
> > > }
> > >
> > > //base++;
> > > //}
> > > document.prime.out.value =outStr;
> > > }
> > 
> > Left for reference.
> > 
> > -- 
> > Ben.
> 
> Hello Ben the script is working now i only tried it upto 10, and the best is base 6 there you can create a counter that reduce the composites from the integer field and reduce the integers with 66.666...%
> 
> 
> http://jt.node365.se/composit_llegs.html 
> 
> But of course there could be bases that reduce the result even more. The none composit legs will be read into an array as start point for the counter but that is later first find the best base.
> 
> I try to reduce the number of primes needed to check by finding a base that is suitable. So far i only checked to base 10 with my little script.
> 
> But i would like to know is there a known upper limit for the possible reduction of composit counters?
> 
> If so what is the base, i noticed in base 6 i can reduce the integer field with 66,666... percent maybe that is the best?
> 
> http://jt.node365.se/composit_llegs.html

I set it to a bit higher and 80 percent reduction seem to be no problem but what is the limit when reducing composites "without actually factoring"

http://jt.node365.se/composite.html

[toc] | [prev] | [next] | [standalone]


#29278

Fromjonas.thornvall@gmail.com
Date2016-01-16 20:01 -0800
Message-ID<3154ad99-ecdc-4a40-a0ff-78e76eec7ff3@googlegroups.com>
In reply to#29277
Den söndag 17 januari 2016 kl. 04:56:39 UTC+1 skrev jonas.t...@gmail.com:
> Den söndag 17 januari 2016 kl. 04:30:28 UTC+1 skrev jonas.t...@gmail.com:
> > Den söndag 17 januari 2016 kl. 00:43:12 UTC+1 skrev Ben Bacarisse:
> > > jonas.thornvall@gmail.com writes:
> > > 
> > > > What could possibly overflow in this?
> > > 
> > > The string.
> > > 
> > > > To me it seems just weird
> > > 
> > > The best thing to do would be to learn the language yo are using.  Until
> > > you do everything you write is likely to seem weird.  Most of the names
> > > you use refer to properties of the global object, so the j in one place
> > > is the same j used in another.
> > > 
> > > > j=1;
> > > > while(j<=base){
> > > 
> > > This test is never false.
> > > 
> > > > prime=false;
> > > > i=j;
> > > > i=i+base;
> > > > while (i<100){
> > > >  primeleg=factor_it(i);
> > > >  if(primeleg==true){break;}
> > > >  i=i+base;
> > > > }
> > > > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > > > j++;
> > > > }
> > > 
> > > <snip>
> > > > The full code below------------------------
> > > > <script language="Javascript">
> > > >
> > > > function factor_it(i){
> > > > prime=true;
> > > > sqroot=Math.floor(Math.sqrt(i));
> > > > for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime)
> > > > {return prime}}
> > > > return prime;
> > > > }
> > > 
> > > This function is very odd.  Nothing it does has much to do with the
> > > names used -- prime and factor_it.  It does not factor the number i, nor
> > > does it test for i being prime.  But, crucially, it alters j which you
> > > use elsewhere.
> > > 
> > > That kind of programming is not sustainable.  You really need to learn
> > > how to write self-contained functions that do their job without messing
> > > up the rest of the program.
> > > 
> > > > function main(){
> > > > base=10;
> > > > outStr="";
> > > >
> > > > //while (base==10) {
> > > >
> > > > j=1;
> > > > while(j<=base){
> > > > prime=false;
> > > > i=j;
> > > > i=i+base;
> > > > while (i<100){
> > > >  primeleg=factor_it(i);
> > > >  if(primeleg==true){break;}
> > > >  i=i+base;
> > > > }
> > > > outStr+="Base="+base+" counterval i = "+i+" P primeleg ="+primeleg+"\n";
> > > > j++;
> > > > }
> > > >
> > > > //base++;
> > > > //}
> > > > document.prime.out.value =outStr;
> > > > }
> > > 
> > > Left for reference.
> > > 
> > > -- 
> > > Ben.
> > 
> > Hello Ben the script is working now i only tried it upto 10, and the best is base 6 there you can create a counter that reduce the composites from the integer field and reduce the integers with 66.666...%
> > 
> > 
> > http://jt.node365.se/composit_llegs.html 
> > 
> > But of course there could be bases that reduce the result even more. The none composit legs will be read into an array as start point for the counter but that is later first find the best base.
> > 
> > I try to reduce the number of primes needed to check by finding a base that is suitable. So far i only checked to base 10 with my little script.
> > 
> > But i would like to know is there a known upper limit for the possible reduction of composit counters?
> > 
> > If so what is the base, i noticed in base 6 i can reduce the integer field with 66,666... percent maybe that is the best?
> > 
> > http://jt.node365.se/composit_llegs.html
> 
> I set it to a bit higher and 80 percent reduction seem to be no problem but what is the limit when reducing composites "without actually factoring"
> 
> http://jt.node365.se/composite.html

Check base 96

[toc] | [prev] | [next] | [standalone]


#29310

FromSilvio <silvio@internet.com>
Date2016-01-18 16:09 +0100
Message-ID<569d0033$0$23809$e4fe514c@news.xs4all.nl>
In reply to#29258
Jonas,

You would really help yourself and everyone else here if you would 
listen when people try to teach you something. I myself and others 
before me have told you to use local variables because it is well neigh 
impossible to write any significant amount of code properly without 
managing the scope of your variables.

Your factor_it function is messing up your j value. Unless you start 
using local variables when they are called for this sort of stuff will 
keep tripping you up.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web