Skip to main content

Elementary cellular automata in Python

Project description

Travis CI Coveralls Code Climate PyPI Downloads License Issues

This is a Python implementation of elementary cellular automata.



pip install rule_n


Download and put it somewhere in your Python path.


import rule_n

rule_110 = rule_n.RuleN(110)
rule_30 = rule_n.RuleN(30)
rule_184 = rule_n.RuleN(184)  # Works with anything from 1 to 255
rule_110 = rule_n.RuleN()  # Default rule is 110, as that is the most common
from rule_n import rule_90   # Shorthand for rule_90 = rule_n.RuleN(90)
                             # Works with 110, 30, 90, 184
# You can also specify a list of rules
rule_110 = rule_n.RuleN([False, True, True, False, True, True, True, False])
# Or a string that summarizes the rule
rule_110 = rule_n.RuleN("01101110")
# See <>
# You can also have a finite canvas
rule_110_finite_canvas = rule_n.RuleN(110, canvas_size=5)
# A canvas is finite if its size is over 0

data = rule_110.process([True, False, True])
len(data) == 5  # because a False is added to both sides
data == [True, True, True, True, False]

data_2 = rule_110.process([1, 0, 1])  # You can use any data type, as long
data == data_2                        # as the boolean values of these are
                                      # correct
                                      # Return values are always in boolean

# With a finite canvas, the output is always as big as the canvas
data = rule_110_finite_canvas.process([0, 0, 0, 0, 1])
data == [False, False, False, True, True]

data_3 = rule_110([True, False, True])  # Shorthand for
                                        # rule_110.process(state)
data == data_3

i = 0
for x in rule_110.iterate([1, 0, 1]):  # Repeatedly process a state
    print x
    i += 1
    if i == 10:
        break  # Please do this
# Note: Iteration on an infinte canvas seems to have some problems
# I recommend using a finite canvas
for x in rule_110_finite_canvas.iterate([0, 0, 0, 0, 1]):
    print x
    # This breaks automatically if the current state is equal to the
    # previous, which will probably happen at some point on a finite canvas

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rule_n, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size rule_n-0.2.1-py2.py3-none-any.whl (7.4 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size rule_n-0.2.1.tar.gz (17.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page