Twocoman
Brainfuck written with two commands. One turns a dial of eleven modes, the other does what the dial says.
2023 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Twocoman is brainfuck behind a dial. There are two commands. 0 turns the dial to the next mode and 1 carries out the mode it points at. Every other character is a comment, so a program is a string of bits.
Read the story
The dial holds the eight commands of brainfuck, ? and ! for numbers, and x, a mode that does nothing. A program starts on x, and the specification says it has to use it first. To run the same command twice costs only another 1, but to go back one mode costs ten turns, so the Hello, World! is 274 bits long.
The machine
The modes, in the order the dial turns, from > back to x.
| Mode | Does |
|---|---|
x | Nothing |
+ - | Add or take 1 from the cell |
. , | Print the cell as a character; read a character into it |
? ! | Print the cell as a number; read a number into it |
[ ] | Loop while the cell is not 0 |
< > | Move to the previous or next cell |
Cells are bytes that wrap, which the Hello, World! program needs. The end of input reads as 0. The specification also writes programs in hexadecimal and as the sequence of modes they carry out, x![?]? for the truth machine; this implementation runs the bits.
Example
The Hello, World! program.
The Hello, World! program. Its modes are x+[-->-[>>+>-----<<]<--<---]>-.>>>+.>>..+++[.>]<<<<.+++.------.<<-.>>>>+., a short brainfuck program that counts on cells wrapping.
The truth machine reads a number with !, loops on [?] while it is not 0 and prints it once more with ?. On 0 that is a single 0. The specification notes that its cat, x+[,.], is longer than this.
Patterns it teaches
- Turing tarpit: brainfuck, still all there.
- Encoding tricks: two symbols and a dial in place of eight.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Twocoman
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: twocoman.
Command line
shib run twocoman -e '100000010100000000010001000000001' --input '0'shib manual twocomanSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/twocoman.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org