Commits

Shu Zong Chen  committed bea9f1f

added alternative cleaner but slower implementation of prime builder

  • Participants
  • Parent commits d4827ac

Comments (0)

Files changed (1)

File problems/problem7.py

 
 import math
 
+"""
+#This prime_builder is so much cleaner, but SLOOW.
+#Probably because it can't short circuit when p <= lmt
+
+def prime_builder():
+  yield 2
+  i = 3
+  primes = list()
+  while 1:
+    lmt = math.sqrt(i)
+    if not any(i%p == 0 for p in primes if p <= lmt):
+      yield i
+      primes.append(i)
+    i = i + 2
+"""
+
 def prime_builder():
 	"""Generates a list of primes by iterating over all values
 	and checking if the value is a multiple of the current prime list.