2DFuck

From Esolang
(Redirected from 2DF)
Jump to navigation Jump to search

2DFuck is another multidimensional brainfuck derivative esolang invented by TheWastl (wastl in PPCG). The language, as presumed by the title, runs on an infinite 2-dimensional memory tape, extending the 1-dimensional memory tape of brainfuck (There are also numerous other 2D brainfuck derivatives). There is a memory pointer which has an X value and a Y one, which indexes the 2D memory tape.

Although the 2DFuck is lightly related to brainfuck, the memory tape of the language only contains bits (boolean values), rather than the bytes (or full integers) of brainfuck. 2DFuck also works with an accumulator, a special boolean value which may be important in programs.

Commands and syntax

At the start of excecution, every bit in the memory tape and the accumulator is set to 0.

2DFuck uses a dozen single letter commands (and an extra debugging command). Any other sign will be ignored, like in brainfuck.

2DFuck retains most of the commands of brainfuck, excluding the operation signs + and - since 2DFuck only operates on bits. The only way to change a value in the memory tape is by using x. 2DFuck introduces a handful of other commands.

Command Function
^ Move the MP up.
v Move the MP down.
> Move the MP right.
< Move the MP left.
l Perform one iteration of Conway's game of life. (All cells consisting of true values are alive cells. False values are dead ones)
r Set the accumulator's value to the pointed cell in the tape.
x Set the pointed cell's value to its XOR with the accumulator. (If the pointed cell is zero, set it to the accumulator value, otherwise set it to the opposite of the accumulator value.)
! Set the accumulator to its logical NOT.
. Output the accumulator bit to STDOUT.
, Input a bit from STDIN and store it in the accumulator.
[ If the accumulator bit is 0, jump to the corresponding ].
] If the accumulator bit is 1, jump to the corresponding [.
? (Debug command) Output the accumulator and the current state of the active memory tape to STDERR (Error console).

I/O

Input is converted to binary ASCII values during runtime. When a , command is called, the first bit is removed and stored in the accumulator (If the input was Hi!, it will get converted to 01001000 01101001 00100001). Taking input from an empty STDIN sets the accumulator to 0.

Output is given in bits, and are converted to ASCII bytes at the end of execution.

Turing-completeness

The author of the language proved that 2DFuck is Turing-Complete by correlating each brainfuck command with a 2DFuck snippet. Since brainfuck is Turing-Complete, 2DFuck is too.

Examples

Hello, World!

.!.!..!.!....!..!..!.!.!.!.!..!.!..!...!..!.!..!...!..!.!....!..!.!.!..!....!.!......!.!.!.!.!...!.!..!.!....!.!...!..!.!..!..!.!..!...!..!..!.!....!.!....!.

This code basically prints:

01001000 01100101 01101100 01101100 01101111 00101100 00100000 01010111 01101111 01110010 01101100 01100100 00100001

...using only the accumulator.

Truth-machine

,x>,x>,x>,x>,x>,x>,x>,x<<<<<<<r.>r.>r.>r.>r.>r.>r.>r.[<<<<<<<r.>r.>r.>r.>r.>r.>r.>r.]

The program stores the input and prints it once, and the goes in a loop if the last bit of the input is one (i.e if the ASCII value of the input character is odd).

Cat program

!xv>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x^r![<r!]!vx>>>>>>>>r![<r!]^r![[<r!]!vx^v>r.>r.>r.>r.>r.>r.>r.>r.^r![<r!]!v>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x>rx,x^r![<r!]!vx>>>>>>>>r![<r!]^r!]v!x^

The program is translated directly from brainfuck to 2DFuck using the TheWastl's translation cheat sheet (Which can be found here).

External links