Ops: corrected prime algorithm

cqx cqx at nefud.org
Mon Oct 22 00:11:19 EDT 2001


John Thingstad <john.thingstad at chello.no> writes:

> Just checked my own algorithm and found several mistakes.
> Here is the correct algorithm:
> 
> 
> def prime(n):
> 	set = [2] + range(3,n, 2)
> 	for n in range(3, int(math.sqrt(n))+1, 2):
            ^                           ^
 which 'n' is this 'n'?                 and this one?

> 		set = [x for x in set if x == n or x % n != 0]
> 	return set


-cqx



More information about the Python-list mailing list