2DFuck
Brainfuck on an endless grid of bits, with one command that runs a step of the Game of Life.
TheWastl · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
TheWastl made 2DFuck as another two-dimensional relative of brainfuck. The memory is a grid of bits that goes on in every direction, and the pointer moves up and down as well as left and right. There is no + or -. All work goes through a one-bit accumulator. r reads the bit under the pointer into it, x XORs it into the bit, and ! flips it. Loops test the accumulator, not the cell.
Read the story
Input and output come one bit at a time, eight to a byte. And l treats the whole grid as Conway's Game of Life and runs one generation.
The machine
| Command | Does |
|---|---|
^ v < > | Move the pointer up, down, left, right |
r | Accumulator = bit |
x | Bit = bit XOR accumulator |
! | Flip the accumulator |
. | Write the accumulator as an output bit |
, | Read an input bit into the accumulator (0 at the end) |
[ | If the accumulator is 0, jump past the matching ] |
] | If the accumulator is 1, jump back to the matching [ |
l | One generation of the Game of Life on the grid |
Bits go most significant first. Every other character is a comment.
Example
The first writes 01001000 01101001 with only the accumulator.
The first writes 01001000 01101001 with only the accumulator. . writes it, ! flips it. The second is a truth machine. It stores the eight bits of the input in a row and prints them back. The last bit of 0 is 0, so the loop never starts; for 1 it would print forever.
Patterns it teaches
- Turing tarpit: the author gave a 2DFuck snippet for every brainfuck command.
- Cellular automata:
lputs a whole Game of Life step into one instruction.
Further
- esolangs.org/wiki/2DFuck
- The interpreter TIO runs: gitlab.com/TheWastl/2DFuck
See also
2DFuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from 2DFuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 2dfuck.
Command line
shib run 2dfuck -e '!x>x>x<l^r.vr.vr.!.....'shib manual 2dfuckSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/2dfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org