Skip to content

Instantly share code, notes, and snippets.

@mgritter
Created November 21, 2018 22:14
Show Gist options
  • Select an option

  • Save mgritter/35c8b8b7de8c119c6c253e1ee4ccf2fd to your computer and use it in GitHub Desktop.

Select an option

Save mgritter/35c8b8b7de8c119c6c253e1ee4ccf2fd to your computer and use it in GitHub Desktop.
rule 110 CA implementation
rule110_dict = {
"111" : "0",
"110" : "1",
"101" : "1",
"100" : "0",
"011" : "1",
"010" : "1",
"001" : "1",
"000" : "0",
}
def rule110Circular( start, iterations ):
curr = start
print curr
for i in xrange( iterations ):
nextIter = [ rule110_dict[ a + b + c ]
for ( a, b, c ) in zip( curr[-1:] + curr[:-1],
curr,
curr[1:] + curr[:1] ) ]
print "".join( nextIter )
curr = nextIter
return "".join( curr )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment