import numpy as np import matplotlib.pyplot as plt # Question 1 N = 256 A = np.zeros((N, N)) A[0][N/2] = 1 # Question 2 def rule90(world): # For each line for i in range(1, N): # For each column: for j in range(N-1): # Rule 90 if world[i-1][j-1] == world[i-1][j+1]: world[i][j] = 0 else: world[i][j] = 1 return world A = rule90(A) # Question 3 plt.imshow(A) plt.savefig('sierpinski.png') plt.close() # Question 4 ones = np.ones((N)) n_ones = np.dot(A, ones) plt.plot(n_ones) plt.savefig('sierpinski_zero.png') plt.close() # Question 5 def rule110(world): # For each line for i in range(1, N): # For each column: for j in range(N-1): value = world[i-1][j-1] + world[i-1][j] + world[i-1][j+1] # Rule 110 if value == 2: world[i][j] = 1 elif value == 1 and world[i-1][j-1] == 0: world[i][j] = 1 else: world[i][j] = 0 return world # Question 6 B = np.zeros((N, N)) B[0][N/2] = 1 B = rule110(B) # Question 7 plt.imshow(B) plt.savefig('rule110.png') plt.close()