Skip to content

Instantly share code, notes, and snippets.

@joemsak
Last active August 19, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemsak/11fcf5551bd0f66856c05339ef8c3b22 to your computer and use it in GitHub Desktop.
Save joemsak/11fcf5551bd0f66856c05339ef8c3b22 to your computer and use it in GitHub Desktop.
turing-ish machine in js
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