esolang

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

Expected: Hello, world!

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.

CommandDoes
p sAdd 2; take 1
r lMove two cells right; move one cell left
dGo back to cell 0
k z hSquare the cell; clear it; halve it
w qCopy the cell to the right, or to the left, into this one
i jRead a number; read a character
o uPrint the cell as a number; as a character
a bLoop, as brainfuck's [ and ]
cRun the next command 7 times
tRun the command before it 3 times
v yRun the next command only if the cell is 0; only half the time
eEnd 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.

Expected: pain

The specification writes ptptsso as pcwyydd. It adds 2, then 6, then 2 and 6 again, takes 2 and prints 14.

Expected: 14

Patterns it teaches

Further

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 painfuck

Source

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