2fuck is a simple 2D variation on brainfuck. Like traditional brainfuck, there is an 1D memory tape that extends 30000 bytes to the right from its beginning, consisting of values between 0 and 255.
Arithmetic should wrap around, adding 1 to 255 sets the cell to 0, and moving right from memory cell 29999 should move the pointer back to 0. The converse should happen when decrementing or moving left.
The input is an 1D unidirectional string/stream.
It has the following commands:
<
change the direction of the instruction pointer to left.>
change the direction of the instruction pointer to right.^
change the direction of the instruction pointer to up.v
change the direction of the instruction pointer to down.[
decrement the data pointer.]
increment the data pointer.-
decrement the value of the tape under the data pointer.+
increment the value of the tape under the data pointer.?
if the value under the data pointer is not 0, rotate the instruction pointer counterclockwise 90 degrees..
Output the value of the tape under the data pointer as a character.,
Read a character from standard input and copy it to the position in the tape under the data pointer. If EOF is reaches this should NOOP.- Any other character should be ignored.
The instruction pointer starts in the top left corner, moving right, execution terminates if it ever goes out of bounds in any direction, aka when it would be impossible to reach any more instructions.
The program can be passed to the interpreter as a two dimensional array or a simple string featuring line breaks. The input might be passed as an additional parameter or concatenated to the program with a separator like a null byte. However, do not assume that all lines in the program are the same length.
Test cases
"Hello World"
v >]++]+++]+++]+[[[[-v
v >[v
v >]++++>?]+]+]-]]+>?[ -v
>++++++++>?]].]- --.+++++++ .. + ++. ]].[-.[.+++.------.--------.]]+.]++.
^ <
^ <
^ <
Cat
Copies the input to the output
v >-v
v >.>?, v
>,>?
^ <
^ <
Print the ASCII code page
Thanks Matteo_C
v >-[v
v >->?]] +[v
v >-[++++]v
v >-[[. +]]v
v >-v
v >-]]++++>?[>?++++ +++ +++.>?[ v
>]->?] -]+ ++ +++>?
^ <
^ <
^ <
^ <
^ <
^ <
>
norv
? \$\endgroup\$