Browse files

much better way to check for primality

  • Loading branch information...
1 parent 683f9b2 commit 39766d7777307a3da939d0722d28dbca9b4f6bec @glyphobet committed Apr 4, 2012
Showing with 1 addition and 6 deletions.
  1. +1 −6 sieve.py
View
7 sieve.py
@@ -8,12 +8,7 @@ def generate_primes():
while True:
n += 1
- n_factor = factor(n, primes)
- n_factor.next()
- try:
- n_factor.next() # n has two factors, it's not prime
- continue
- except StopIteration: # n has one factor, it's prime
+ if n == factor(n, primes).next(): # if n is its own (first) factor, it's prime
primes.append((n, n**2))
yield primes[-1]

0 comments on commit 39766d7

Please sign in to comment.