esolang

Hanabi

Every instruction is a dot, and what it does is the empty space around it.

Ellie, 2018 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello, world!

The idea

Ellie made Hanabi in 2018 and named it after the Japanese word for firework. A program is a field of dots and other characters. For each dot, count the spaces above it, below it, to its left and to its right, up to the next character that is not a space. Those four numbers, U D L R, are the instruction. So pushing 9 means a dot with nine empty cells under it.

Read the story

The dots run in reading order, left to right and top to bottom. A dot can be the wall of another dot, so programs come out as scattered sparks.

The machine

U D L RDoes
0 n 0 0Push n
0 n 0 1Push the character codes of n's digits
0 0 0 2 0 0 0 3 0 0 0 4Read a byte, a number or a line
0 0 1 0 0 0 1 1 0 0 2 1Swap, reverse the stack, rotate it
1 0 0 0 1 0 0 1 1 0 0 2Print a character, a number, a line feed
1 1 0 0Print the whole stack as characters
2 0 0 0Duplicate
2 1 L RCompare, 1 for true and 0 for false
2 2 L RAdd, subtract, multiply, divide, power, modulo and more
3 n 0 0Label n
3 n 0 1 3 n 1 0 3 n 1 1Jump to label n if not 0, if 0, always

Whole numbers have no bounds, as in Ruby, the language of the reference. Division gives a fraction, since the specification lists integer division as an instruction of its own, and integer division and modulo round down as Ruby's do.

Example

Hello, world! It pushes 8 and 9, multiplies them into 72 and prints an H.

Hello, world! It pushes 8 and 9, multiplies them into 72 and prints an H. The ..... in the fourth line are five instructions in a row, each the wall of the next.

The prime test. It builds 32 and 62, a space and a >, prints the stack as its prompt, reads a number n and multiplies n mod d for every d from n minus 1 down to 2. It prints 1 if that product is not 0, so 1 for a prime.

Expected: > 1

The Fibonacci program prints 0, 1, 1, 2, 3, 5 and on, one to a line, and never stops. Its two rotations only work one way round, which is how this implementation knows that rotating upward moves the top item to the bottom.

Patterns it teaches

Further

Pattern-based

Two-dimensional languages

Write your own in Run Convert a program from Hanabi

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: hanabi.

Command line

shib run hanabi program.txt --input '7'

The program is long; save it as program.txt first.

shib manual hanabi

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/hanabi.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org