2L
Brainfuck on a grid with two symbols. A * means one of four commands, and which one depends on the way the pointer is moving.
Gregor Richards, 2005 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Gregor Richards made 2L, the Two Language, in 2005, loosely after PATH and brainfuck. It keeps brainfuck's tape and drops every command but two. * stands for >, <, + or -, picked by the direction the instruction pointer travels. + is the only branch: a wall that turns the pointer left or right by the cell under the data pointer.
Read the story
Every other character is a nop, but it still takes up room on the grid, so it is not ignored. Input and output have no command at all; they are mapped onto the first two cells of the tape.
The machine
A grid, an IP that starts at the top left moving down, and a tape of byte cells with the data pointer on cell 2. The run ends when the IP leaves the grid.
| Symbol | Does |
|---|---|
* moving up | Move the data pointer right |
* moving down | Move the data pointer left |
* moving right | Add one to the cell |
* moving left | Take one from the cell |
+ | A wall: just before it, turn right if the cell is not 0, else left |
Cell 0 holds the byte for I/O and cell 1 is the trigger. Changing cell 1 writes cell 0 when it is not 0, and reads a byte into it when it is 0.
Example
Print !.
Print !. The two stars on the left move the data pointer from cell 2 to cell 0, and the + below turns the IP right along 33 stars, so cell 0 is 33. Three turns bring it back up through a star onto cell 1, and the star at the top right of *+* changes cell 1 while moving left, which writes the byte.
The Hello World from Try It Online prints Hi the same way twice. The second row of stars adds 33 to the 72 of the first.
Patterns it teaches
- Turing tarpit: two symbols and a nop are enough. 2L is Turing complete.
- Two-dimensional control flow: the same
*does four things, so a program is laid out by the direction it must be crossed in. - Encoding tricks: I/O hides in the tape, as in BitChanger.
Further
See also
2L builds on Brainfuck.
Two-dimensional languages
Brainfuck derivatives
Write your own in Run Convert a program from 2L
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 2l.
Command line
shib run 2l -e '* +
*+*
*******************************************************************************+
+ +
+ +
+ +*
****************************+
+ +
+ +'shib manual 2lSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/2l.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org