Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac2aadb

Browse files
committed
add prime numbers
1 parent 8084316 commit ac2aadb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

py3/functional/prime_numbers.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
def main():
5+
for n in primes():
6+
if n < 1000:
7+
print(n)
8+
else:
9+
break
10+
11+
def _odd_iter():
12+
n = 1
13+
while True:
14+
n = n + 2
15+
yield n
16+
17+
def _not_divisible(n):
18+
return lambda x: x % n > 0
19+
20+
def primes():
21+
yield 2
22+
it = _odd_iter()
23+
while True:
24+
n = next(it)
25+
yield n
26+
it = filter(_not_divisible(n), it)
27+
28+
if __name__ == '__main__':
29+
main()

0 commit comments

Comments
 (0)