LNUSP
Five commands on a two-dimensional grid of code, steering through a two-dimensional grid of memory.
Zzo38, 2004 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Zzo38 made LNUSP in 2004 as a leaner PATH; the name means Low SNUSP. The code is a grid that the instruction pointer crosses in any of eight directions, diagonals included. The memory is a grid too, and its pointer moves the way the instruction pointer is going at that moment.
Read the story
There are no commands for input and output. Instead, leaving the code off the top edge calls a subroutine chosen by the column. Column 8 reads, 24 prints and 41 stops. Programs draw long dotted lines up to those columns, with their names written above them as comments.
Source lines start with a three-digit count that repeats the rest of the line. 065 + is 65 rows of +, which is how a program builds a letter going down a column. A count of 000 makes the line a comment.
The machine
| Command | Does |
|---|---|
+ | Add 1 to the memory cell, mod 256 |
* | Move the memory pointer one step in the IP's direction |
? | Turn 45 degrees left if the cell is not 0 |
! | Turn 45 degrees left if the cell is 0 |
@ | Going north, turn 45 degrees right; else go back to the saved place, or save this place and go north |
The IP starts at the top left going southeast. Every other character, such as ., does nothing. After a subroutine the IP turns round. Leaving by any other edge ends the run. The specification leaves open whether @ also restores the direction; this implementation does, as TIO's hello world needs.
Example
The first four rows turn the IP from southeast to south in the first column.
The first four rows turn the IP from southeast to south in the first column. Then 65 + set the cell to 65, and a ? turns it southeast. Three ? turn it east, northeast and north into column 24, and it runs off the top, which prints A. Coming back down, the next ? sends it southeast again, and three more steer it north up column 41, which stops the program.
Patterns it teaches
- Two-dimensional control flow: turns only to the left, and only on a test, so every path is a carefully drawn curve.
- Turing tarpit: Reversible Bitfuck compiles into it.
Further
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from LNUSP
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: lnusp.
Command line
shib run lnusp -e '001 . !.!
001 . !
001 ! . !
001 . !!
065 +
001 ?
019
001 ?
001 ??
012
001 ?
001 ??'shib manual lnuspSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/lnusp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org