Last active
August 19, 2017 13:45
-
-
Save joemsak/11fcf5551bd0f66856c05339ef8c3b22 to your computer and use it in GitHub Desktop.
turing-ish machine in js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const X_B = { | |
"B,s1": ["X", "R", "s2"], | |
"B,s2": ["B", "L", "s3"], | |
"X,s3": ["B", "R", "s4"], | |
"B,s4": ["B", "L", "s1"], | |
} | |
var tape = ["B", "B"], | |
head = 0, | |
state = "s1"; | |
for(i = 0; i < 8; i++) { | |
console.log(" " + state + ": " + tape.join("")); | |
console.log(" " + Array(head).fill(" ").join("") + "^"); | |
var value = tape[head], | |
key = [value, state].join(","), | |
[next_value, next_action, next_state] = X_B[key]; | |
tape[head] = next_value; | |
head += next_action == "R" ? 1 : -1; | |
state = next_state; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment