Simulating Rule 110
From Predictive Chemistry
Revision as of 12:51, 4 April 2018 by David M. Rogers (talk | contribs) (Created page with "<source lang="python"> from numpy import * import pylab as plt def update(a,b,c): if b == 0 and c == 0: return 0 if a == 1 and b == 1 and c == 1: retu...")
<source lang="python"> from numpy import * import pylab as plt
def update(a,b,c):
if b == 0 and c == 0: return 0 if a == 1 and b == 1 and c == 1: return 0 return 1
def update_row(A, r):
for i in range(8): A[r+1,i] = update(A[r,i-1], A[r,i], A[r,(i+1)%8])
""" 1. create an empty "output"
2. start with an initial condition 3. for step in times: i. append state to the output ii. update the state
""" A = zeros((17,8)) A[0,7] = 1 for step in range(16):
update_row(A, step)
plt.imshow(1-A, cmap='bone', interpolation='nearest', aspect='auto') plt.show() print( sum(A == 0) / (17.0*8.0) ) </source>