BFFB
Brainfuck that has to be its own mirror image.
Feuermonster, 2012 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Feuermonster made BFFB in 2012 as a joke. The name stands for Brainfuck fucks brains, and it reads the same both ways. So must every program. Read a BFFB program backwards, swap [ with ] and > with <, and you get the same program again. +, -, . and , are their own mirror images. So [><] is a valid program and [>] is not.
Read the story
The cat is ,[.,][,.],. The first half copies the input. The mirrored half never runs, because the loop before it only ends on a cell that holds 0. In the reference implementation that loop never ends, since it waits for more input. In this implementation , reads 0 at the end of the input, so the cat stops there.
The machine
| Command | Its mirror | Does |
|---|---|---|
+ - | itself | Add or subtract 1 |
> < | each other | Move right or left |
[ ] | each other | Loop while the cell is not 0 |
. , | itself | Print or read a byte |
Everything else is a comment and does not count for the mirror. A program that is not its own mirror stops with an error before it starts. As in the Python implementation, cells are bytes that wrap and the tape starts with one cell and grows to the right; moving left of the first cell is an error. At the end of the input , reads 0.
Example
The second program makes 65 and prints it.
The second program makes 65 and prints it. Its mirrored half prints it again and then skips its own loop, because the cell it lands on holds 0.
The third shows how any brainfuck program fits. The work sits in a loop that runs once, +[> and <[-]], and its mirror image sits in a loop that never runs, [[-]> and <]+. The specification suggests ending a program with [-]+[] and mirroring it, which works too but never halts.
Patterns it teaches
- Turing tarpit: still brainfuck, so still Turing complete.
- Hostile design: one rule about symmetry makes every program twice as long.
Further
See also
BFFB builds on Brainfuck.
Brainfuck equivalents
Brainfuck derivatives
Write your own in Run Convert a program from BFFB
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bffb.
Command line
shib run bffb -e '[-]'shib manual bffbSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/bffb.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org