UglyBF
Brainfuck with half its commands taken away. A backslash turns each one into its opposite.
2011 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
UglyBF keeps four of brainfuck's eight commands, + > . [, and gets the other four back with \, which inverts the command after it. \+ is -, \> is <, \. is , and \[ is ].
Read the story
The sixth command is *, which doubles the command after it. Stars chain, so **+ adds 4 and ******+ adds 64. A \ passes over the stars, so \**+ subtracts 4. Any byte can be reached in at most eight groups, one for each bit.
The machine
| Command | Does | After \ |
|---|---|---|
+ | Add 1 to the cell | Subtract 1 |
> | Move right | Move left |
. | Print the cell | Read a byte into it |
[ | Jump past the matching \[ if the cell is 0 | Jump back past the matching [ if it is not |
* | Double the next command | Cannot be inverted |
Every other character is a comment. The specification leaves the machine under it open. This implementation uses byte cells that wrap, a tape with no end either way and \. reading 0 at the end of the input. A doubled bracket is two brackets, which must pair up as in brainfuck.
Example
The BF.
The BF. ******+*+ adds 64 and 2, which is B.
The Hello World, in capitals. Each letter is reached from the one before.
The specification writes the brainfuck program ,++[->++<]>[<+>-]<. in UglyBF. It reads a byte, adds 2 and doubles it, so 0, which is 48, comes out as d, which is 100.
Patterns it teaches
- Turing tarpit: six commands, one of them only a modifier.
- Encoding tricks: constants written in powers of two.
Further
See also
UglyBF builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from UglyBF
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: uglybf.
Command line
shib run uglybf -e '\..[\..\[' --input 'cat '