Piece of cake
FRACTRAN without the primes. The registers get names, and the rules read from left to right.
Hakerh400, 2026 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Hakerh400 made Piece of cake in 2026 while playing a game about FRACTRAN. In FRACTRAN a number is a bag of primes, and each prime's exponent is a register. Piece of cake keeps the bag and drops the primes. The FRACTRAN fraction (2^3·5^7)/3^2 is written a:2 -> b:3 c:7, with the part that is taken first.
Read the story
It also allows what FRACTRAN cannot, a rule like x y -> x z that tests for x and leaves it in place.
The machine
The state is a term, a bag of names with counts. x:3 is three of x, and x alone is one.
| Step | What happens |
|---|---|
| Start | The input term, with one INP added |
| Repeat | The first line whose left side the term holds takes it away and adds its right side |
| Stop | No line fits. OUT is removed and the term is printed |
Every rewrite starts the search again from the first line, as in FRACTRAN. This implementation prints the result with its names in code point order, the way the specification writes B x y z:3.
Example
The specification's own rule turns A x:2 y:8 into B x y z:3.
The specification's own rule turns A x:2 y:8 into B x y z:3. The INP is still there, as no line takes it.
The multiplication. The states A to D are a loop that adds a to c once for every b, with d keeping a copy of a.
The division leaves the quotient in q and the remainder in r. 17 divided by 5 is 3, with 2 left.
Patterns it teaches
- Counter machines: every name is a counter, and a line is a guarded decrement and increment.
- Turing completeness: it runs every FRACTRAN program, and its interpreter converts back.
Further
See also
Also in Rewriting
Write your own in Run Convert a program from Piece of cake
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: piece-of-cake.
Command line
shib run piece-of-cake -e 'A x:2 y:7 -> B x:1 z:3' --input 'A x:2 y:8'shib manual piece-of-cakeSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/piece-of-cake.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org