Mercurial > public > think_complexity
diff ch7ex2.py @ 47:2b0e229e163c
Chapter 7, exercise 2. R-Pentomino game of life.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 21:53:44 -0500 |
parents | |
children | 98eb01502cf5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ch7ex2.py Thu Jul 25 21:53:44 2013 -0500 @@ -0,0 +1,26 @@ +"""Chapter 7, exercise 2 in Allen Downey's Think Complexity book. + +Start with an r-pentomino as an initial condition and confirm that the results +are consistent with the description above. You might have to adjust the size of +the grid and the boundary behavior. + +""" +import Life + + +class RPentomino(Life.Life): + + def __init__(self, n): + super(RPentomino, self).__init__(n, mode='constant', cval=0, random=False) + + i, j = n / 2, n / 2 + self.array[i, j] = 1 + self.array[i, j - 1] = 1 + self.array[i, j + 1] = 1 + self.array[i - 1, j] = 1 + self.array[i + 1, j - 1] = 1 + +if __name__ == '__main__': + life = RPentomino(150) + viewer = Life.LifeViewer(life, delay=1) + viewer.animate(steps=1200)