Painfuck
Brainfuck in 21 letters, and after every command the rest of the program is encrypted again.
Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Painfuck is a brainfuck derivative with one cruel rule. Each time a command runs, the whole rest of the program goes through a fixed table that swaps 21 letters. The second character is read through the table once, the third twice, the hundredth 99 times. So you cannot write the program you mean. To run pso you have to write ptt.
Read the story
The table moves every letter one step along a cycle. One cycle holds 8 letters and the other 13, so a letter at place 104 is back to itself.
The machine
The letters below are what the program says after decryption.
| Command | Does |
|---|---|
p s | Add 2; take 1 |
r l | Move two cells right; move one cell left |
d | Go back to cell 0 |
k z h | Square the cell; clear it; halve it |
w q | Copy the cell to the right, or to the left, into this one |
i j | Read a number; read a character |
o u | Print the cell as a number; as a character |
a b | Loop, as brainfuck's [ and ] |
c | Run the next command 7 times |
t | Run the command before it 3 times |
v y | Run the next command only if the cell is 0; only half the time |
e | End the program |
The specification has no interpreter text, so some things are this implementation's choice. Cells are whole numbers on a tape that runs both ways, the end of the input reads as 0, o prints the digits alone and y flips a coin from a fixed seed, so a run always replays.
Example
The Hello World, its two lines joined, since every character counts as a place.
The Hello World, its two lines joined, since every character counts as a place.
Decrypted it starts cpptt. cp adds 14 and p adds 2. The first t runs p three times, and the second t runs the first t three times, which is nine more p. So the cell holds 40, and a loop that adds 25 and seven more after it make 72, the H.
The cat decrypts to jaujb, brainfuck's ,[.,] in Painfuck letters.
The specification writes ptptsso as pcwyydd. It adds 2, then 6, then 2 and 6 again, takes 2 and prints 14.
Patterns it teaches
- Hostile design: the program text changes under you as it runs.
- Encoding tricks: a substitution cipher that turns once per place.
- Turing tarpit: brainfuck underneath, with a few extra commands.
Further
See also
Painfuck builds on Brainfuck.
Brainfuck derivatives
Write your own in Run Convert a program from Painfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: painfuck.
Command line
shib run painfuck -e 'ptt'shib manual painfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/painfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org