【发布时间】:2016-08-10 10:08:47
【问题描述】:
我是 Python 的新手,所以我不太了解这一点。它是某种图灵机,应该写二进制数,但我不知道在这些规则之后发生了什么
from collections import defaultdict
import operator
# Binary counter
# (Current state, Current symbol) : (New State, New Symbol, Move)
rules = {
(0, 1): (0, 1, 1),
(0, 0): (0, 0, 1),
(0, None): (1, None, -1),
(1, 0): (0, 1, 1),
(1, 1): (1, 0, -1),
(1, None): (0, 1, 1),
}
# from here I don't really understand what's going on
def tick(state=0, tape=defaultdict(lambda: None), position=0):
state, tape[position], move = rules[(state, tape[position])]
return state, tape, position + move
system = ()
for i in range(255):
system = tick(*system)
if(system[2] == 0):
print(map(operator.itemgetter(1), sorted(system[1].items())))
【问题讨论】:
标签: python computer-science turing-machines