Skip to content

Instantly share code, notes, and snippets.

@DavidButts
Last active January 13, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidButts/a8846f7efd09d7a7f0362b64fd506233 to your computer and use it in GitHub Desktop.
Save DavidButts/a8846f7efd09d7a7f0362b64fd506233 to your computer and use it in GitHub Desktop.
#Written by David Butts
#This code is an implementation of a Rule 30 Wolfram model written in Python.
import numpy as np
import time
def Rule30_code():
Rule30 = np.zeros((1000,100000)) #initilize an array to run on (timesteps, width)
Rule30[0,50] = 1
for y in range(Rule30.shape[0]-1): #iterate through grid
for x in range(Rule30.shape[1]):
#update the next rows values according to neighbor & self value
right = x + 1
down = y + 1
left = x - 1
if right >= Rule30.shape[1]:
right = 0
if Rule30[y,right] == 1 and Rule30[y,left] == 0:
Rule30[down,x] = 1
elif Rule30[y,x] == 0 and Rule30[y,right] == 0 and Rule30[y,left] == 1:
Rule30[down,x] = 1
elif Rule30[y,x] == 1 and Rule30[y,right] == 0 and Rule30[y,left] == 0:
Rule30[down,x] = 1
else:
Rule30[down,x] = 0
#average run time for 10 runs
av_time = 0
for run in range(10):
start = time.time()
Rule30_code()
end = time.time()
av_time += (end-start)
print(av_time/10.0, 'seconds for 10 runs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment