esolang

Bouncy

Four mirrors, four modes. The same wall bounces, vanishes, steers along or steers across.

Mercerenies, 2024 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello World!

The idea

Mercerenies made Bouncy in 2024. The pointer starts at the $ facing east and moves in eight directions on a grid that wraps at every edge, so the program lives on a torus. There is no conditional jump. A program turns by hitting one of four mirrors, |, _, / and \, and what a mirror does depends on the mode.

Read the story

# adds the primary register to the mode, so a computed number decides how the next mirror acts. Each mode also has its own array of memory, so changing the mode changes the memory you see.

The machine

ModeA mirror
0 BOUNCEReflects the pointer like a wall, and lets it pass when it runs parallel
1 GHOSTDoes nothing
2 ZAPSends the pointer along itself, the side nearest its heading
3 FLOWSends the pointer across itself, the side nearest its heading

In ZAP and FLOW a tie turns right, so a pointer heading east into | in ZAP goes south.

CommandDoes
0 to 9, TSet PR to the digit, or to ten
S LStore PR in the active array at MP, or load it
( )Move MP down or up by PR
"Swap PR and the second register SR
+ - * % mCombine PR with the cell at MP
& ; ^ n ~And, or, xor with the cell; negate; logical not
< = >Compare PR with the cell, giving 1 or 0
p P i IPrint a number or a character; read a number or a character
#Add PR to the mode, modulo 4
@Halt

Example

The Hello World program sets FLOW mode with 3# and then runs once round an octagon.

The Hello World program sets FLOW mode with 3# and then runs once round an octagon. Every corner is a mirror that sends it across, and the arithmetic along the edges builds each letter.

The truth machine. With 0 the # keeps BOUNCE mode, the / turns the pointer west to 0p@, and it prints 0. With 1 it enters GHOST, passes the /, enters ZAP and runs round the border printing 1 for ever.

Expected: 0

The factorial program keeps the running product in the ZAP array and leaves its loop by switching to FLOW.

Expected: 3628800

Patterns it teaches

Further

Two-dimensional languages

Write your own in Run Convert a program from Bouncy

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run bouncy -e '_......|
.      .
.  $i\ .
.    # 1
. @p0/ p
.    # .
|...._._' --input '0'
shib manual bouncy

Source

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

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

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