Skip to content

Instantly share code, notes, and snippets.

@leif
Created June 9, 2012 06:20

Revisions

  1. leif revised this gist Jun 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wolfram.py
    Original 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 ] + [0] * (width/2)
    world = [0] * (width/2) + [ 1 ] * (width/2)
    y = 0
    while True:
    print "".join( " *"[cell] for cell in world )
  2. leif created this gist Jun 9, 2012.
    21 changes: 21 additions & 0 deletions wolfram.py
    Original 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