Created
January 3, 2023 14:48
-
-
Save luabida/c8354e123e425dee4704a8b56b8b496c to your computer and use it in GitHub Desktop.
Recursion & Laziness Evaluation | First 100 positive prime numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def positives(n): | |
| yield n | |
| yield from positives(n+1) | |
| def primes(s): | |
| n = next(s) | |
| yield n | |
| yield from primes(i for i in s if i%n != 0) | |
| p = primes(positives(2)) | |
| for i in range(100): | |
| print(next(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment