Factor
A program is one number, and its prime factors are the brainfuck commands.
Bangyen Pham, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Bangyen Pham made Factor, also called Factors, in 2020. A program is a single number. Factor it into primes and sort them; each prime, taken mod 11, is one brainfuck command, and a prime that divides twice is the same command twice. The cat ,[.,] is 310861643, which is 17 × 29 × 71 × 83 × 107. Those are 6, 7, 5, 6 and 8 mod 11.
Read the story
Why 11? It is the smallest modulus with at least eight residues coprime to it, and by Dirichlet's theorem each of those residues has infinitely many primes. So any brainfuck program has a number, and Factor is Turing complete.
The machine
Brainfuck with cells of 0 to 255 that wrap and a tape that is unbounded to the right.
| p mod 11 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Command | > | < | + | - | . | , | [ | ] |
To write a program, take for each command the next prime above the last one with the right residue, and multiply them. The Hello World on the specification is a number of 300 digits. Its brainfuck ends by printing an empty cell, so Hello World! comes out followed by a NUL byte.
Example
The cat from the specification, and its polyglot truth machine, a number of 111 digits that starts with…
The cat from the specification, and its polyglot truth machine, a number of 111 digits that starts with eighteen <.
Ideas it shows
See also
Factor builds on Brainfuck.
Zero-dimensional languages
Brainfuck equivalents
Write your own in Run Convert a program from Factor
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: factor.
Command line
shib run factor -e '310861643' --input 'cat'shib manual factorSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/factor.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org