Mini-Flak
Brain-Flak with the second stack taken away, and still Turing complete.
2016 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Mini-Flak is a cut down Brain-Flak from 2016; the specification says Wheatwizard most likely made it. It keeps one stack, five bracket commands and the rule that every command gives a number. The stack holds integers of any size and starts as zeros all the way down. There is no second stack, no stack height and no input, and yet the language is Turing complete, by way of a counter machine.
The machine
| Code | Gives | Does |
|---|---|---|
() | 1 | |
{} | the popped value | pops |
(x) | the sum of x | pushes that sum |
[x] | minus the sum of x | |
{x} | the sum of every run of x | runs x while the top is not 0 |
The specification leaves the output open. This implementation prints the final stack the way Brain-Flak does, top first, one number per line.
Example
(()()) is a (...) around two (), so it pushes 2.
(()()) is a (...) around two (), so it pushes 2. {{}} pops while the top is not 0; on three 2s it pops all three and gives 6, which the outer brackets push.
The swap. After pushing 2 and then 3 it leaves 2 on top of 3.
The first part pushes the sum of both values and keeps the lower one. The second pushes the upper value and gives its negative, so the outer brackets push sum minus upper, which is the lower value.
Patterns it teaches
- Stack machines: one stack of integers, where every command is also a number.
- Turing tarpit: five commands.
- Counter machines: the usual proof that it is Turing complete.
Further
See also
Esoteric subset
Stack-based
Write your own in Run Convert a program from Mini-Flak
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: mini-flak.
Command line
shib run mini-flak -e '(()())'shib manual mini-flakSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/mini-flak.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org