File tree Expand file tree Collapse file tree 1 file changed +69
-0
lines changed
Expand file tree Collapse file tree 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+
4+ import itertools
5+
6+
7+ def intsum ():
8+ u"""Generate a sequence that adds the next integer."""
9+
10+ a = 0
11+ yield a
12+
13+ for i in itertools .count (1 , 1 ):
14+ a = a + i
15+ yield a
16+
17+
18+ def doubler ():
19+ u"""Generate a sequence that doubles the previous value."""
20+
21+ a = 1
22+ yield a
23+
24+ while True :
25+ a = 2 * a
26+ yield a
27+
28+
29+ def fib ():
30+ u"""Generate the fibonacci series."""
31+
32+ a , b = 0 , 1
33+
34+ while True :
35+ a , b = b , a + b
36+ yield a
37+
38+
39+ def prime ():
40+ u"""Simply generate the prime numbers."""
41+
42+ for i in itertools .count (2 , 1 ):
43+ for a in range (2 , i ):
44+ if i % a == 0 :
45+ break
46+ else :
47+ yield i
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
You can’t perform that action at this time.
0 commit comments