Created
June 9, 2012 06:20
Revisions
-
leif revised this gist
Jun 9, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ print "Usage: %s rule width count" % (sys.argv[0],) sys.exit(1) rule, width, count = map(int, sys.argv[1:] ) world = [0] * (width/2) + [ 1 ] * (width/2) y = 0 while True: print "".join( " *"[cell] for cell in world ) -
leif created this gist
Jun 9, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ """ Wolfram 1-dimensional cellular automata """ __author__ = "Leif Ryge" __license__ = "WTFPL" import sys if len(sys.argv) != 4: print "Usage: %s rule width count" % (sys.argv[0],) sys.exit(1) rule, width, count = map(int, sys.argv[1:] ) world = [0] * (width/2) + [ 1 ] + [0] * (width/2) y = 0 while True: print "".join( " *"[cell] for cell in world ) world = [ rule>>(world[x-1]*4+world[x]*2+world[(x+1)%len(world)])&1 for x in range(len(world)) ] y+=1 if y >= count: break