annotate ch6ex1.py @ 42:039249efe42f

Chapter 6, exercise 2, #4. Wrote a program to output the center column of a rule 30 CA as a stream of bytes. It is very slow though. It has to run a very long time to produce enough data for dieharder. Committing it now but will have to let it run overnight or something to generate a large file.
author Brian Neal <bgneal@gmail.com>
date Sun, 13 Jan 2013 16:24:00 -0600
parents 49db586c727a
children
rev   line source
bgneal@39 1 """Chapter 6, exercise 1 in Allen Downey's Think Complexity book.
bgneal@39 2
bgneal@39 3 "Download thinkcomplex.com/CA.py and thinkcomplex.com/CADrawer.py and confirm
bgneal@39 4 that they run on your system; you might have to install additional Python
bgneal@39 5 packages."
bgneal@39 6
bgneal@39 7 """
bgneal@39 8 import sys
bgneal@39 9
bgneal@39 10 import CA
bgneal@39 11 from CADrawer import PyplotDrawer
bgneal@39 12
bgneal@39 13 def main(script, rule, n):
bgneal@39 14 rule = int(rule)
bgneal@39 15 n = int(n)
bgneal@39 16 ca = CA.CA(rule, n)
bgneal@39 17 ca.start_single()
bgneal@39 18 ca.loop(n - 1)
bgneal@39 19
bgneal@39 20 drawer = PyplotDrawer()
bgneal@39 21 drawer.draw(ca)
bgneal@39 22 drawer.show()
bgneal@39 23
bgneal@39 24
bgneal@39 25 if __name__ == '__main__':
bgneal@39 26 main(*sys.argv)