esolang

NDBall

A ball rolling through as many dimensions as you like, where every dimension is only five cells long.

QTpye, 2020 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 0

The idea

QTpye made NDBall in 2020 to force programs into high dimensions. Space has any number of dimensions, but each one has only five cells, 0 to 4. A program that needs more than five instructions in a row has to turn into a new dimension, so the Hello World uses three and the 99 bottles program four.

Read the story

The ball carries one byte. It starts at the origin, runs the instruction in each cell it enters and rolls on. Rolling off the end of a dimension is an error, so every program ends with E. Beside the ball there is a hive of apioforms, one more byte to keep a number in.

The machine

Each line is a position and an instruction, such as (2,1) P, or {16,3} + for 3 in dimension 16.

CodeDoes
>n <nRoll forward or back in dimension n
\| KmovReverse; a one-way mirror
Y[X,movA,movB]Roll as movA if the value is below X, else as movB
+ -Change the value
p P $ % LPrint as a character or a number; read a character or a number; read a line
a f q n HThe hive; add, subtract, clear, take the ball's value, give it back
s #movA cell that swaps with the ball; a cell that remembers or restores
St[n] ESt PSt[n]Send output to a string memory, stop, print it
R EA random value; end

S[n], which waits in real time, does nothing.

Example

The adder keeps the first number in the hive.
Expected: 5

The adder keeps the first number in the hive. It then circles a loop in dimension 1 that moves the second number into the hive one at a time, until the split at (3,1) sees 0 and sends the ball off to print.

The Hello World counts up in loops of two cells, where each Y lets the ball out once the value reaches the next letter. It prints Hello world!, with a small w.

Further

Ideas it shows

Multi-dimensional languages

Write your own in Run Convert a program from NDBall

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run ndball -e '(0) >0
(1) %
(2) Y[1,>0,>1]
(2,1) P
(2,2) <1
(3) P
(4) E' --input '0'
shib manual ndball

Source

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

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

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