bgneal@39: """Chapter 6, exercise 1 in Allen Downey's Think Complexity book. bgneal@39: bgneal@39: "Download thinkcomplex.com/CA.py and thinkcomplex.com/CADrawer.py and confirm bgneal@39: that they run on your system; you might have to install additional Python bgneal@39: packages." bgneal@39: bgneal@39: """ bgneal@39: import sys bgneal@39: bgneal@39: import CA bgneal@39: from CADrawer import PyplotDrawer bgneal@39: bgneal@39: def main(script, rule, n): bgneal@39: rule = int(rule) bgneal@39: n = int(n) bgneal@39: ca = CA.CA(rule, n) bgneal@39: ca.start_single() bgneal@39: ca.loop(n - 1) bgneal@39: bgneal@39: drawer = PyplotDrawer() bgneal@39: drawer.draw(ca) bgneal@39: drawer.show() bgneal@39: bgneal@39: bgneal@39: if __name__ == '__main__': bgneal@39: main(*sys.argv)