Skip to content

Instantly share code, notes, and snippets.

@Swizec Swizec/gist:1449124
Created Dec 8, 2011

Embed
What would you like to do?
var _ = require('underscore'), states = {};
var tm = function(S, step, end){
if (_.keys(s).indexOf(end)>=0) return true;
var _step = {};
for(var k in step){
var i = step[k][0],
tape = step[k][1],
front = S[k][tape[i]] || S[k].B;
for(var j=0; front, j<_.size(front); ){
var _cur = front[j++],
_tape = _.clone(tape);
_tape.splice(i, 1, _cur.w);
_step[_cur.n] = [i+_step.m, _tape];
}
}
return _.size(Θ) ? tm(S, _step, end) : true;
};
states = JSON.parse(require('fs').readFileSync(process.argv[2], 'utf-8'));
console.log(tm(states,
{"q0": [0, process.argv[3].split("")]},
process.argv[4]));
/* example machine
{"q0":{"0":[{"n":"q4","w":0,"m":1},
{"n":"q1","w":1,"m":1}]},
"q4":{"0":[{"n":"q0","w":0,"m":-1}]},
"q1":{"0":[{"n":"q2","w":1,"m":-1}]},
"q2":{"1":[{"n":"q3","w":1,"m":1}]}}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.