Useful brainfuck
Brainfuck with an accumulator that every cell can reach, decimal numbers in and out, and a switch for wrapping.
EvyLah, 2024 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
EvyLah made Useful brainfuck in 2024, a brainfuck that aims to be useful. Brainfuck's eight commands stay as they are. Beside the tape sits one more cell, the accumulator, which every part of the tape can reach. It can be counted up and down by 1 or 10, doubled, halved, added to a cell, and used to jump the pointer that many cells at once. ; and : read and print numbers in decimal, so adding two numbers no longer needs a converter.
Read the story
Cells and the accumulator wrap at 256 at the start. ' switches wrapping off, and then they hold any integer.
The machine
| Char | Does |
|---|---|
> < + - [ ] , . | Brainfuck's eight |
( ) | Copy the cell to the accumulator, or the accumulator to the cell |
0 ? | Set the accumulator to 0, or to a random number from 0 to 255 |
i d I D | Add 1, take 1, add 10, take 10 |
* / | Double or halve the accumulator, a half going to the even number |
a A | Add the cell to the accumulator, or the accumulator to the cell |
{ } | Move the pointer left or right as many cells as the accumulator says |
; : | Read a decimal number into the cell, print the cell as a number |
' | Switch wrapping off or on |
Any brainfuck program runs unchanged, so the language is Turing complete.
Example
The A + B, once with the accumulator and once in plain brainfuck.
The A + B, once with the accumulator and once in plain brainfuck.
The looping counter reads a number of lines and a character, and prints a triangle of that character. The accumulator counts 1, 2, 3 and ) copies it into the cell the inner loop counts down.
Patterns it teaches
- Turing completeness: it holds brainfuck whole.
See also
Useful brainfuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Useful brainfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: useful-brainfuck.
Command line
shib run useful-brainfuck -e ';(;A:' --input '3 4'shib manual useful-brainfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/useful-brainfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org