Triangular
The code is folded into a triangle, and the pointer walks it in eight directions.
aaronryank, 2017 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Triangular is a two-dimensional stack language from 2017, inspired by Surface and Hexagony. The program is not laid out by its lines. Whitespace is dropped and the characters are folded into the smallest triangle they fit, one cell in the top row, two in the next, and so on, with . as padding. 123456 becomes three rows, 1, 2 3 and 4 5 6.
Read the story
The pointer starts at the top going south-east. On a triangle with offset rows a cell has eight neighbours, two in its own row, two above, two below, and one straight up and one straight down, two rows away. The program ends when the pointer leaves the triangle.
The machine
One stack of up to 30,000 numbers and one memory value.
| Command | Does |
|---|---|
` ^ / > \ v , < | Go NW, N, NE, E, SE, S, SW, W | |
o e | Turn clockwise, counter-clockwise; c and z turn and then become each other |
0–9 A–F | Push 0 to 15 |
+ - * _ m | Add, subtract, multiply, divide, remainder |
: p " | Duplicate, pop, swap |
d i \| u | Decrement, increment, negate, absolute value |
= l g | Equal (keeps both), less than, greater than |
$ ~ | Read a number, read a character |
% @ # | Print the top as a number, as a character, as a character and pop |
? ! | Skip the next cell if the top is 0 or less, or above 0 |
( ) ] x | Mark a point, go back to it, go back while the top is above 0, drop it |
P S U | Pop into memory, copy into memory, push memory |
& ; | End; end if the top is 0 or less |
Example
The first two programs run straight down the diagonal, cells 0, 2, 5 and 9 of the code, and the dots…
The first two programs run straight down the diagonal, cells 0, 2, 5 and 9 of the code, and the dots between are padding the pointer never meets. The Hello World is 56 characters, so it is folded into 11 rows and winds back and forth across them.
Further
- esolangs.org/wiki/Triangular
- The C interpreter, which TIO runs
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Triangular
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: triangular.
Command line
shib run triangular -e '9.i..%'shib manual triangularSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/triangular.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org