Hey Danny,

I think you could use the same sqrt(n) on your algorithm to reduce the
search space. I think you could also increment n += 2 to skip even numbers,
the simplest of sieves.

I think the sieve concept is based on the idea that adding is much less
intensive than dividing, so creating the sieve is fairly quick compared to
all those divides. that said, I might put a timer on your algorithm and
compare them!

Oops: I just did it. Yours won, .23s to .34s. What's more, on certain prime
numbers (with large factors), mine breaks. well never mind then. I'm
blaming Jorge.

Dammit: I forgot to include the i += 2 suggestion I made in the above test
(one also has to start i at 3, hopefully obviously). That improves your
time to .11s. Poor Jorge.

Keith
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to