annotate ch6ex1.py @ 44:362d4ec7e794

Got a first draft Turing Machine working for chapter 6, exercise 4. Next I have to figure out how to draw it with a TMDrawer class.
author Brian Neal <bgneal@gmail.com>
date Wed, 16 Jan 2013 21:44:02 -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)