Ops: corrected prime algorithm

John Thingstad john.thingstad at chello.no
Sun Oct 21 17:59:58 EDT 2001


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):
		set = [x for x in set if x == n or x % n != 0]
	return set







More information about the Python-list mailing list