Created
June 2, 2015 11:24
-
-
Save paraggupta1993/064d3662f308af17ed64 to your computer and use it in GitHub Desktop.
[Javascript] Turing Machine
This file contains hidden or 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
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