local fiveStateBB = {
initState = "A",
endState = "H",
blank = "0",
rules = {
{"A", "0", "1", "right", "B"},
{"A", "1", "1", "left", "C"},
{"B", "0", "1", "right", "C"},
{"B", "1", "1", "right", "B"},
{"C", "0", "1", "right", "D"},
{"C", "1", "0", "left", "E"},
{"D", "0", "1", "left", "A"},
{"D", "1", "1", "left", "D"},
{"E", "0", "1", "stay", "H"},
{"E", "1", "0", "left", "A"}
}
}
local function turing(machine)
local state, tapeNum, step = machine.initState, 1, 0
repeat
for _, rule in ipairs(machine.rules) do
if rule[1] == state and rule[2] == tapeNum then
tapeNum = rule[3]
state = rule[5]
print(tapeNum..state)
break
end
end
step = step + 1
print("Step: "..step.." | "..tapeNum.." | State: "..state)
if state == machine.endState then
print("Halted.")
end
wait(1)
until state == machine.endState
end
turing(fiveStateBB)
This script keeps outputting the same thing over and over,
when it really shouldn’t.
After a couple prints I realized the line if rule[1] == state and rule[2] == tapeNum then
always returns false for some reason. I just wanna know why that is. Been scratching my head at it for a good 20 minutes so any answer would be awesome.
Sorry for the vague title, just didn’t know what to call this lol