Cerberus
Three lines of dots and dashes. The size of each patch is the instruction.
2020 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Every Cerberus program has three lines, like the dog has three heads. The lines hold only . and -, and the first column with anything else ends the program. Cells of one character that touch up, down, left or right form a group, and the size of the group picks the command. Two dots read a number and two dashes print one.
Read the story
The pointer walks the middle line from left to right. It runs a group's command once, when it steps into the group. The top and bottom lines only shape the groups.
The machine
| Size | . | - |
|---|---|---|
| 1 | Push 1 | Push -1 |
| 2 | Read an integer | Pop and print it |
| 3 | Pop A, then B, push A-B | Pop A, push A! or, when A is not above 0, -((-A)!) |
| 4 | Swap | Duplicate |
| 5 | Nothing | Nothing |
| 6 | Pop A, mark this place as A | Pop A, jump to mark A |
A command with too few items on the stack does nothing. A jump to a mark that was never set goes on to the right. After a jump the pointer stands on the marked cell and does not run it again.
Example
The truth machine.
The truth machine. Along the middle line its groups read a number, duplicate it, push 1, set mark 1, duplicate, print, duplicate and jump to the mark the number names. Only 1 has a mark, so 1 prints forever and any other number prints once.
The cat is 79 columns wide and runs push 1, mark 1, read, duplicate, print, push 1 and jump 1 forever. This implementation stops when the input runs out.
Patterns it teaches
- Stack machines: ten commands on one stack of whole numbers.
- Encoding tricks: an instruction is the size of a patch, not a symbol.
Further
See also
Pattern-based
Stack-based
Write your own in Run Convert a program from Cerberus
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: cerberus.
Command line
shib run cerberus -e '.-...-..--.--....-..-.-..--
.-.---..-.--.----..-..-..--
--.-..-.--.-.....-.-..--.--' --input '0'shib manual cerberusSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/cerberus.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org