Created
December 8, 2011 23:03
-
-
Save Swizec/1449124 to your computer and use it in GitHub Desktop.
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
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