NDBall

From Esolang
Jump to navigation Jump to search

NDBall, "N-Dimentinal Ball" or NDB is an esolang made by User:Aspwil (talk)

Language Overview

NDB is a lang where we have a ball that moves. we tell the ball what direction to move in and whenever the ball hits an instruction it executes it.

The ball itself holds a value, a single-byte int (0-255), and starts at 0.

the ball can move in any dimension we want. but it can only move in one of them at a time. and each dimension is only 5 cells in length

the ball starts at position 0 in all dimensions

Position

There are 2 ways we can define the position of something in this lang.

First Method: Point

we can simply define a position in n dimensions as (a,b,c...)

ex:

(0,1,2) 

This is 0 in the zeroth dimension, 1 in the first dimension, and 2 in the second dimension.

this method has a problem, what if we want to represent something that is in the 0th position for dimensions 0 to 15, but at a position of 3 for the 16th dimension.

to do this we would need to use the code

(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3)

now that is a lot of wasted zeros

so we move onto the next way to define the position

Second Method: Vector List

a list of vectors with dimension number and length in that dimension

written as {dim,length|dim,length...}

The code from earlier is 3 in the 16th dimension so we write it as

{16,3}

this is the same position as before but much easier to write and understand.

Instructions

Instruction Effect
>n move the ball forwards in dimension n
<n move the ball backward in dimension n
+ the value of the ball goes up by one
- the value of the ball goes down by one
P prints out the ASCII value associated with the value of the ball
p prints out the value of the ball
$ takes in the input of a single char and sets the value of the ball to ASCII equivalent
% takes in the input of a number and sets the value of the ball to it
E ends program
#mov this a memory cell, it remembers a single byte int. mov is a movement instruction (ex. >3). if the ball`s movement is the same as the mov specified by the memory then the memory cell is written to, becoming the value of the ball. If not the cell is read and the ball becomes the value of the memory cell. Memory cells have a default value of 0.
| this is a mirror, it reverses the direction of the ball
Kmov this is one-way mirror if the movement of the ball matches mov then the ball pass through the mirror otherwise the direction is reversed
a an apioform joins the hive, increasing the have value by 1
f an apioform leaves the hive to polinate flowers, decreasing the value of the hive by 1
q the queen leaves the hive, taking all apioforms with her, hive value is now 0
n nector attract apioforms to or away from the hive untill its value matches the ball
H the hive itself, when run into the ball`s value becomes the hive value
Y[X,movA,movB] this is the Y logic operator. when the ball lands on it, it runs a simple if statement. if the value of the ball is below X then the ball moves according to movA if not then it moves according to movB.
/ this must be the first letter in a new line, this line is a comment
s swap memory cell, starts at 0, when the ball passes over the ball value and cells value are swaped
L reads in a full line of text, each time the ball goes over it, it spits out the next one. terminated with a 0 value, if empty it will read in a new line

Writing Code

Writing code is done in a simple way. Each line of code has 1 position and 1 instruction

it is written simply as:

POS INSTR

for example

(0) >0

is at position "0" and the instruction is "move forward in the 0th dimension"


Code examples

Truth machine

(0) >0
(1) %
(2) -
(4) >1
(4,1) Y[1,<0,>1]
(3,1) +
(2,1) <0
(1,1) P
(0,1) >0
(4,2) #>0
(4,3) P
(4,4) E

Hello World

using only 83 instructions and 20 dimensions

(0) >0
{0,1} >0
{0,2} +
{0,3} Y[72,>1,>0]
{0,3|1,1} <0
{0,1|1,1} <1
{0,4} >2
{0,4|2,1} <0
{0,3|2,1} p
{2,1} >2
{2,2} +
{2,3} Y[101,>3,>2]
{2,3|3,1} <2
{2,1|3,1} <3
{2,4} >4
{2,4|4,1} <2
{2,3|4,1} p
{4,1} >4
{4,2} +
{4,3} Y[108,>5,>4]
{4,3|5,1} <4
{4,1|5,1} <5
{4,4} >6
{4,4|6,1} <4
{4,3|6,1} p
{4,2|6,1} p
{6,1} >6
{6,2} +
{6,3} Y[111,>7,>6]
{6,3|7,1} <6
{6,1|7,1} <7
{6,4} >8
{6,4|8,1} <6
{6,3|8,1} p
{8,1} >8
{8,2} -
{8,3} Y[33,>8,>9]
{8,3|9,1} <8
{8,1|9,1} <9
{8,4} >10
{8,4|10,1} <8
{8,3|10,1} p
{10,1} >10
{10,2} +
{10,3} Y[119,>11,>10]
{10,3|11,1} <10
{10,1|11,1} <11
{10,4} >12
{10,4|12,1} <10
{10,3|12,1} p
{12,1} >12
{12,2} -
{12,3} Y[112,>12,>13]
{12,3|13,1} <12
{12,1|13,1} <13
{12,4} >14
{12,4|14,1} <12
{12,3|14,1} p
{14,1} >14
{14,2} +
{14,3} Y[114,>15,>14]
{14,3|15,1} <14
{14,1|15,1} <15
{14,4} >16
{14,4|16,1} <14
{14,3|16,1} p
{16,1} >16
{16,2} -
{16,3} Y[109,>16,>17]
{16,3|17,1} <16
{16,1|17,1} <17
{16,4} >18
{16,4|18,1} <16
{16,3|18,1} p
{18,1} >18
{18,2} -
{18,3} Y[101,>18,>19]
{18,3|19,1} <18
{18,1|19,1} <19
{18,4} >20
{18,4|20,1} <18
{18,3|20,1} p
{18,2|20,1} E

Add 2 numbers

using a swap cell with 9 dimensions and 36 instructions

(this was... difficult to make)

(0) >0
(1) %
(2) >5
{0,2|5,1} >1
{0,2|1,1|5,1} >2
{0,2|1,1|2,1|5,1} >3
{0,2|1,1|2,1|3,1|5,1} <0
{1,1|2,1|3,1|5,1} <5
{0,1|1,1|2,1|3,1} s
{1,1|2,1|3,1} >0
{0,2|1,1|2,1|3,1} %
{0,3|1,1|2,1|3,1} Y[1,>0,>4]
{0,4|1,1|2,1|3,1} >6
{0,4|1,1|2,1|3,1|6,1} <0
{0,1|1,1|2,1|3,1|6,1} <3
{0,1|1,1|2,1|6,1} <6
{0,3|1,1|2,1|3,1|4,1} -
{0,3|1,1|2,1|3,1|4,2} >7
{0,3|1,1|2,1|3,1|4,2|7,1} <4
{0,3|1,1|2,1|3,1|7,1} <2
{0,3|1,1|3,1|7,1} <0
{0,1|1,1|3,1|7,1} <7
{0,1|2,1|3,1} >1
{0,1|1,2|2,1|3,1} >8
{0,1|1,2|2,1|3,1|8,1} <1 
{0,1|1,1|2,1|3,1|8,1} >0
{0,3|1,1|2,1|3,1|8,1} <8
{0,1|1,1|3,1} >2
{0,1|1,1|2,2|3,1} +
{0,1|1,1|2,3|3,1} >9
{0,1|1,1|2,3|3,1|9,1} <2
{0,1|1,1|2,1|3,1|9,1} <1
{0,1|2,1|3,1|9,1} <9
{0,1|1,1|2,1} >3
{0,1|1,1|2,1|3,2} P
{0,1|1,1|2,1|3,3} E

and just for reference here the drawing I made and based the program off of.

NDBALL.jpg

Interpreters

NDBallSim on GitHub