Skip to content

Instantly share code, notes, and snippets.

@joemsak

joemsak/turing-ish.js

Last active Aug 19, 2017
Embed
What would you like to do?
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