Primes
Brainfuck written in numbers, where only the count of prime factors matters.
Meloons, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Meloons made Primes in 2021, after brainfuck. A program is a list of numbers. Each number is factored, and the count of its prime factors, repeats included, picks the instruction. 143 is 11 times 13, so it has 2 factors and moves the pointer right. 32 is 2 to the fifth, so it adds 1.
Read the story
So any one program can be written in countless ways. The specification gives its Hello World twice, once in powers of two and once in numbers like 3675 and 11858 that factor to the same counts.
The memory is a grid, and the pointer moves up and down as well as left and right.
The machine
| Factors | Does | Smallest number |
|---|---|---|
| 0 | Halt | 0 or 1 |
| 1 2 | Pointer left, right | 2, 4 |
| 3 4 | Pointer up, down | 8, 16 |
| 5 6 | Add 1, subtract 1 | 32, 64 |
| 7 8 | Start loop, end loop | 128, 256 |
| 9 10 | Print a byte, read a byte | 512, 1024 |
| 11 | Set the cell to 0 | 2048 |
Loops work as brainfuck's [ and ]. The specification leaves the cell size open. Its 99 bottles program only ends when cells are bytes that wrap, so they are bytes.
Example
The Hello World in powers of two.
The Hello World in powers of two. The pointer only goes up (8) and down (16), so it uses one column of the grid.
Read two bytes into neighbouring cells and print them. 1024 reads, 143 moves right, 2 moves left and 512 prints.
Patterns it teaches
- Turing tarpit: brainfuck's eight commands, on a grid.
- Encoding tricks: an instruction hides in a number's factors.
Further
See also
Primes builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Primes
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: primes.
Command line
shib run primes program.txtThe program is long; save it as program.txt first.
shib manual primesSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/primes.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org