python中的初等元胞自动机

rule_n的Python项目详细描述


Travis CICoverallsCode ClimatePyPIDownloadsLicenseIssues

这是elementary cellular automata的python实现。

安装

PIP

pip install rule_n

手动

下载^{tt1}$并将其放到python路径中的某个位置。

用法

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 <https://en.wikipedia.org/wiki/Rule_110#Definition>
# 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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java打印元素按ArrayList<String>   java重新启动JSON输出   使用EOL版本Java时存在安全漏洞   java搜索并在vector中列出项目   Java与串口通信   java如何使用keytool运行测试并检查JCE是否缺失或存在?   java如何更改Json格式?   java停止缩放JPanel的背景图像   java递归方法不返回任何内容   facebook sdk中的java UiLifecycleHelper类   java将jfree条形图添加到滚动窗格中   java如何使用ApacheTiles和SpringMVC加载部分页面   javascript如何从安卓 webview读取httpbody?   java@OneToMany映射会自动删除映射的键