Pain-Flak
Brain-Flak written in a mirror, and every program runs twice.
Cis112233 · Turing complete: yes · ●●● hard
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Brain-Flak is a stack language made only of brackets. Pain-Flak turns each bracket round, so ) opens and ( closes, and then appends the program to itself back to front with the brackets turned round again. Whatever the first half does, the mirrored second half does too, in reverse order. A program that pushes a value then pops one gets a second half that pushes and pops in the other order.
The machine
Two stacks of unbounded integers, an empty stack popping 0. This implementation follows the Ruby interpreter in the repository Cis112233/Pain-Flak, which is what TIO runs.
| Pain-Flak | Brain-Flak | Does |
|---|---|---|
)( | () | 1 |
][ | [] | The height of the stack |
}{ | {} | Pop |
>< | <> | Switch stacks |
)x( | (x) | Push x |
]x[ | [x] | Minus x |
}x{ | {x} | Loop while the top is not 0 |
>x< | <x> | Run x, worth 0 |
The input is decimal numbers, the first on top. At the end the stack is printed top first as characters, which is how TIO runs it with -A.
Example
The first program is ({}()), pop and add 1.
The first program is ({}()), pop and add 1. The mirrored half is ((){}), which adds 1 again, so 64 becomes 66. In the second, ({}{}) adds 32 and 33 and the mirror adds 65 and an empty pop.
Patterns it teaches
- Stack machines: Brain-Flak's two stacks, unchanged underneath.
- Turing tarpit: the mirrored half can be cancelled out, so it is as strong as Brain-Flak.
Further
- The interpreter, in Ruby
See also
Also in Turing tarpits
Write your own in Run Convert a program from Pain-Flak
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pain-flak.
Command line
shib run pain-flak -e ')}{)((' --input '64'shib manual pain-flakSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/pain-flak.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language