Skip to content

Instantly share code, notes, and snippets.

@paraggupta1993
Created June 2, 2015 11:24
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 paraggupta1993/064d3662f308af17ed64 to your computer and use it in GitHub Desktop.
Save paraggupta1993/064d3662f308af17ed64 to your computer and use it in GitHub Desktop.
[Javascript] Turing Machine
function tm(tape, transform, startState, endStates, i){
currState = startState;
while(currState is not in endStates){
sym = (tape[i])? tape[i]: 'Blank';
state = transform[currState][sym];
if(!state) return 'Not Halting';
tape[i] = state.w; // write sym
i += state.m; // move tape
currState = state.n; // move to next state
}
return tape;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment