Created
January 13, 2016 16:11
-
-
Save ryohey/2fc4037616056196bedb to your computer and use it in GitHub Desktop.
The Wolfram 2, 3 Turing Machine in CoffeeScript
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
| logTm = (tm) -> | |
| text = tm.colors | |
| .map (s, i) -> if i is tm.pos then "%c" + ["▲", "▼"][tm.state] else "%c " | |
| .join "" | |
| style = tm.colors.map (c) -> "background-color:" + ["white", "yellow", "orange"][c] + ";" | |
| console.log.apply console, [text].concat style | |
| # [state, color] = [state, color, offset] | |
| rule = {} | |
| rule[[0, 2]] = [0, 1, -1] | |
| rule[[0, 1]] = [0, 2, -1] | |
| rule[[0, 0]] = [1, 1, 1] | |
| rule[[1, 2]] = [0, 0, 1] | |
| rule[[1, 1]] = [1, 2, 1] | |
| rule[[1, 0]] = [0, 2, -1] | |
| stepTm = (tm) -> | |
| r = rule[[tm.state, tm.colors[tm.pos]]] | |
| tm.state = r[0] | |
| tm.colors[tm.pos] = r[1] | |
| tm.pos += r[2] | |
| tm = | |
| colors: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
| pos: 3 | |
| state: 0 | |
| for _ in [0..50] | |
| logTm tm | |
| stepTm tm |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result