Skip to content

Commit

Permalink
lazy erathostenes algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Oct 16, 2023
1 parent f7a424a commit 02087e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FormalDerivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def polyrep(Fx):
s = ["%dx ^ %d" % x for x in Fx]
return " + ".join(s)

fx = [(1,6),(1,0)]
fx = [(-1,6),(1,0)]
print(polyrep(fx))
fx = FormalDerivative(fx)
print(polyrep(fx))
13 changes: 13 additions & 0 deletions lazy_erathostenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from itertools import islice

def nats(n):
yield n
yield from nats(n+1)

def sieve(s):
#print("sieve",s)
n = next(s)
yield n
yield from sieve(i for i in s if i % n != 0)

print(list(islice(sieve(nats(2)), 30)))

0 comments on commit 02087e3

Please sign in to comment.