Cubix
The code is folded onto a cube, and the pointer walks over its edges onto the next face.
2016 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Cubix dates from 2016 and follows Labyrinth and Hexagony. The interpreter strips all whitespace, finds the smallest cube the code fits on, and pads the rest with the no-op .. A program of 29 characters gets a cube with sides of 3, so 54 cells.
Read the story
Then it is an ordinary 2D stack language, except for the edges. A pointer that walks off the top face comes out on a side face, turned to match the fold, and walking straight on long enough always brings it back where it started.
The machine
The faces are laid out as a net: the top face, then the band of left, front, right and back faces, then the bottom face. The pointer starts at the top left of the left face moving east. One stack with endless zeros under it; most operators leave their operands on it.
| Char | Does |
|---|---|
0-9 ' " N S Q | Push a digit, the next character, a string, 10, 32, 34 |
i I A | Read a byte, a number, or all the input |
o O | Print the top as a character or a number, without popping |
+ - * , & a b c | Arithmetic and bitwise operators |
( ) n ~ | Decrement, increment, negate, not, in place |
: ; # s r q t | Dup, drop, length, swap, rotate, to the bottom, pick |
/ \ \| _ < > ^ v | Mirrors and arrows |
L R U u W w D | Turn, U-turn into the next lane, sidestep, random |
$ ! ? | Skip, skip if not 0, turn by the sign of the top |
@ | Stop |
Example
The Hello World from the specification and Try It Online.
The Hello World from the specification and Try It Online. On the cube the band row reads "!dlroW"S',u, so the pointer collects the end of the message, turns with u into the row below and reads "Hello" backwards. The loop on the top face prints and drops each character.
A cat on a cube of side 2. The four dots are the top face, the rest is the first row of the band, which goes round all four side faces and back to i. ) makes the end of input 0, and only then does ! let the pointer reach @.
Patterns it teaches
- Two-dimensional control flow: the grid has no edges, only folds.
- Stack machines: one stack, read without popping.
Further
- esolangs.org/wiki/Cubix
- The interpreter, in JavaScript
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Cubix
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: cubix.
Command line
shib run cubix -e '....67*O@'shib manual cubixSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/cubix.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org