Den lördag 16 januari 2016 kl. 23:30:48 UTC+1 skrev Chris Angelico:
> On Sun, Jan 17, 2016 at 9:23 AM,  <jonas.thornv...@gmail.com> wrote:
> > 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;
> > }
> 
> A couple of potential problems here. The first thing that comes to
> mind is that floating point inaccuracy is going to bite you long
> before the numbers "seem huge" to someone who's thinking about 2**53.
> The second is an off-by-one error: a perfect square may come up as
> prime.
> 
> Check for those and see how it looks.
> 
> Also, check your double-use of the 'prime' variable, which also
> appears to be global here.
> 
> ChrisA

Thank you Chris, this is not really for factoring it is meant to create a 
composite sieve. Well all the legs just holding composites will be false.

Regarding the problem no number bigger than 100 is sent to the function, there 
is something weird with either the loop structure or the break.

What should happen...
j=1
i=j

1+10 break (because prime in leg)
j++; well j is 2 and so is i

2+10,2+20,2+30,2+40.2+50,2+60,2+70,2+80,2+90 ((condidion break loop i>100
j++ ->i=3
3+10 break (because prime in leg)
j++

And so on...
And as you can see the outer loop does this until j reaches ***base which is 
10***.
In all it is about 50 operations
So how can it allocate all memory?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to