Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29277
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-01-16 19:56 -0800 |
| References | <4eb1912d-87cd-4e4b-a4b0-5154de752831@googlegroups.com> <87egdhgkfp.fsf@bsb.me.uk> <1bdc5946-5bfb-4b97-8bd9-835390af3331@googlegroups.com> |
| Message-ID | <c6dae50d-ac8e-4edc-aa5e-8ec0c71c7bb1@googlegroups.com> (permalink) |
| Subject | Re: Memory allocation overflow |
| From | jonas.thornvall@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
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web