Binary Turing Machine!?
A Turing machine written one binary number per line, with a state for input and a state for output.
Largejamie, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Largejamie made Binary Turing Machine!? in August 2022. A program uses only 0, 1, !, ? and line breaks. Every line is a number in binary, and its last character says what the number is for. Five ! lines make one rule of a Turing machine, and each ? line puts one symbol on the starting tape. When the whole program has been read, the machine runs.
Read the story
A symbol is any whole number, not only a bit, so a cell can hold a character code. States 1 and 2 are taken for input and output, which is how the machine reads and prints.
The machine
| Line ends in | Means |
|---|---|
! | The next part of a rule, in the order state, symbol read, new state, symbol written, move |
? | The next cell of the starting tape, from the left end |
| State | Does |
|---|---|
| 0 | Where the machine starts, on the leftmost cell |
| 1 | Reads a character onto the cell, goes to state 0 and moves right |
| 2 | Prints the cell as a character and moves right; on a blank it goes to state 0 and moves right |
A move goes right when its number is even and left when it is odd. Blanks are 0. The tape has a left end, and a move left from there stays put. The machine halts when no rule fits. A line feed and the end of the input both read as the blank 0, which the binary cat needs to stop.
Example
Hello, world! has one rule.
Hello, world! has one rule. In state 0, reading a 1, the machine writes 0, moves right and goes to state 2, which prints the 14 codes after it.
This machine echoes one character with two rules. It reads the character into the leftmost cell, where a move left stays put, then steps back onto it in state 2 and halts on the 3 at the end of the tape.
The binary cat has 17 rules. It reads 1s and 0s until a line feed, walks back and prints them all, with a line feed of its own after them.
Ideas it shows
See also
Also in Turing tarpits
Write your own in Run Convert a program from Binary Turing Machine!?
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: binary-turing-machine.
Command line
shib run binary-turing-machine -e '0!
1!
10!
0!
0!
1?
1001000?
1100101?
1101100?
1101100?
1101111?
101100?
100000?
1110111?
1101111?
1110010?
1101100?
1100100?
100001?
1010?'shib manual binary-turing-machineSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/binary-turing-machine.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org