# HG changeset patch # User Brian Neal # Date 1357960725 21600 # Node ID 49db586c727a9bcbef9236852f82b5a1dae1c39a # Parent d876711b88b59880c814ce830a25155498221a1a Chapter 6, exercise 1: simple program to play with CA and CADrawer. diff -r d876711b88b5 -r 49db586c727a ch6ex1.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ch6ex1.py Fri Jan 11 21:18:45 2013 -0600 @@ -0,0 +1,26 @@ +"""Chapter 6, exercise 1 in Allen Downey's Think Complexity book. + +"Download thinkcomplex.com/CA.py and thinkcomplex.com/CADrawer.py and confirm +that they run on your system; you might have to install additional Python +packages." + +""" +import sys + +import CA +from CADrawer import PyplotDrawer + +def main(script, rule, n): + rule = int(rule) + n = int(n) + ca = CA.CA(rule, n) + ca.start_single() + ca.loop(n - 1) + + drawer = PyplotDrawer() + drawer.draw(ca) + drawer.show() + + +if __name__ == '__main__': + main(*sys.argv)