Coeus
Four registers of fractions, and a loop that runs a second program just to learn where to stop.
2020 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Coeus is loosely after 3-cell brainfuck. It has four registers, A to D. A starts at 1 and the others at 0, and every command is a letter followed by a register.
Read the story
There is no plain loop. [XY][m][n] first runs the program m on a fresh set of registers of its own and takes the value of its register Y. Then it runs n until the caller's register X equals that value. To loop until a register is 0, leave m empty and ask for one of its zeros.
cX turns X into 1/X, so registers hold exact fractions. bX multiplies A by a register and gX counts how often a number divides A, so one register can keep several counts at once as powers of different numbers.
The machine
| Command | Does |
|---|---|
aX | Print X |
bX | A becomes A times X |
cX | X becomes 1/X |
dX eX | Add 1 to X; take 1 from X |
fX | Swap A and X |
gX | X becomes n, where A = k X^n and X does not divide k |
hX | Read a number into X |
[XY][m][n] | Run m on its own registers, then repeat n while X is not m's Y |
The specification does not say how a value prints. This implementation puts each value on a line of its own and prints a fraction as 1/2. At the end of the input h reads 0.
Example
The factorial from the specification.
The factorial from the specification. hB reads n into B. The loop's first program is empty, so its B is 0, and the body bBeB multiplies A by B and counts B down until B is 0. Then aA prints A.
The truth machine prints A while A is not 0 and once more after, so a 0 prints once and a 1 forever. The cat reads and prints numbers until it has printed a 0.
The counter [BB][eB][aBdB] never stops. Its first program takes B down to -1, and B counts up from 0, so it never gets there.
Patterns it teaches
- Counter machines: four registers that only go up and down by one, plus a multiply.
- Turing tarpit: eight commands and a single kind of loop.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Coeus
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: coeus.
Command line
shib run coeus -e '[AB][][hAaA]' --input '3 4 0'shib manual coeusSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/coeus.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org