Mercurial > public > think_complexity
annotate ch2ex7.py @ 24:5c2c4ce095ef
A stab at the L(p)/L(0) plot.
I still don't quite get how the graphs in the Watts and Strogatz paper were
generated. My results have basically the same shape, but don't converge to 0.
I'm not sure how this is possible if the rewire function does not remove edges.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 03 Jan 2013 18:41:13 -0600 |
parents | aea27d10dd18 |
children |
rev | line source |
---|---|
bgneal@10 | 1 """Chapter 2.7, exercise 7. |
bgneal@10 | 2 |
bgneal@10 | 3 Write a generator that yields an infinite sequence of alpha-numeric identifiers, |
bgneal@10 | 4 starting with a1 through z1, then a2 through z2, and so on. |
bgneal@10 | 5 |
bgneal@10 | 6 """ |
bgneal@10 | 7 import string |
bgneal@10 | 8 |
bgneal@10 | 9 def generate_identifier(): |
bgneal@10 | 10 num = 1 |
bgneal@10 | 11 while True: |
bgneal@10 | 12 for c in string.lowercase: |
bgneal@10 | 13 yield c + str(num) |
bgneal@10 | 14 num += 1 |
bgneal@10 | 15 |
bgneal@10 | 16 |
bgneal@10 | 17 if __name__ == '__main__': |
bgneal@10 | 18 try: |
bgneal@10 | 19 for name in generate_identifier(): |
bgneal@10 | 20 print name |
bgneal@10 | 21 except KeyboardInterrupt: |
bgneal@10 | 22 print "Control-C interrupt" |