BrainGuck
Brainfuck with a loop that runs while the cell is 0, and one byte to carry a value across the tape.
Periapsis, 2017 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Periapsis made BrainGuck in 2017 from brainfuck and five more commands. Brainfuck's loop runs while the cell is not 0. BrainGuck adds its mirror, { }, which runs while the cell is 0. That makes it easy to walk over a stretch of empty cells. A one-byte store beside the tape lets a value be picked up in one place and put down in another, where brainfuck would need a loop to move it.
The machine
A tape of bytes that wrap at 256, and a store of one byte that starts at 0.
| Code | Does |
|---|---|
+ - < > [ ] . , | Brainfuck's eight |
{ | Skip past the matching } if the cell is not 0 |
} | Jump back to the matching { if the cell is 0 |
^ | Copy the cell into the store |
v | Copy the store into the cell |
0 | Set the cell to 0 |
At the end of input , gives 0.
Example
The reverse cat reads three characters and puts a 1 after them as a marker.
The reverse cat reads three characters and puts a 1 after them as a marker. Each round it walks left with {<} to the last character still there, picks it up with ^, clears it with 0, walks right over the empty cells with {>} and past the marker and the copies with [>], and puts it down with v.
A character in the input that is 0 would stop the walks early, which is why the specification asks for three characters that are not 0.
This one reads A, copies it one cell to the right with ^ and v, adds one to the copy and prints B, then goes back and prints the A it read.
Patterns it teaches
- Turing tarpit: brainfuck's eight commands, with five more for comfort.
Further
See also
BrainGuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from BrainGuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainguck.
Command line
shib run brainguck -e ',>,>,>+<
{<}^0{>}[>]v.
[<]{<}^0{>}[>]v.
[<]{<}^0{>}[>]v.' --input 'abc'shib manual brainguckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainguck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org