esolang

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

Expected: 10

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.

CommandDoes
` ^ / > \ v , < | Go NW, N, NE, E, SE, S, SW, W
o eTurn clockwise, counter-clockwise; c and z turn and then become each other
0–9 A–FPush 0 to 15
+ - * _ mAdd, subtract, multiply, divide, remainder
: p "Duplicate, pop, swap
d i \| uDecrement, increment, negate, absolute value
= l gEqual (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
( ) ] xMark a point, go back to it, go back while the top is above 0, drop it
P S UPop 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…
Expected: 42
Expected: Hello, World!

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

Ideas it shows

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 triangular

Source

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