Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101826
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-01-16 15:25 -0800 |
| References | <d8e5eaf4-c59f-4635-8e73-f4a9a1a84877@googlegroups.com> <mailman.47.1452983435.15297.python-list@python.org> |
| Message-ID | <7625bba2-5c2d-4d28-8b6a-30ec7b490089@googlegroups.com> (permalink) |
| Subject | Re: Keen eyes |
| From | jonas.thornvall@gmail.com |
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.thornvall@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 your comment resolved it double use of j in two different functions and loops.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:23 -0800
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 09:30 +1100
Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:55 -0800
Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 15:25 -0800
Re: Keen eyes Steven D'Aprano <steve@pearwood.info> - 2016-01-17 18:10 +1100
Re: Keen eyes Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-17 00:37 -0700
Re: Keen eyes Paul Rubin <no.email@nospam.invalid> - 2016-01-16 23:52 -0800
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 19:25 +1100
Re: Keen eyes BartC <bc@freeuk.com> - 2016-01-17 11:17 +0000
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 22:32 +1100
csiph-web