Mercurial > public > think_complexity
annotate ch6ex1.py @ 45:1804f09a7adb
Chapter 6, exercise 4, part 4. A Turing Machine drawer.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 19 Jan 2013 14:17:12 -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) |