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
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
| Mode | A mirror |
|---|---|
| 0 BOUNCE | Reflects the pointer like a wall, and lets it pass when it runs parallel |
| 1 GHOST | Does nothing |
| 2 ZAP | Sends the pointer along itself, the side nearest its heading |
| 3 FLOW | Sends 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.
| Command | Does |
|---|---|
0 to 9, T | Set PR to the digit, or to ten |
S L | Store PR in the active array at MP, or load it |
( ) | Move MP down or up by PR |
" | Swap PR and the second register SR |
+ - * % m | Combine 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 I | Print 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.
The factorial program keeps the running product in the ZAP array and leaves its loop by switching to FLOW.
Patterns it teaches
- Two-dimensional control flow: the mode decides what each mirror does, so a number steers the pointer.
Further
See also
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 bouncySource
- 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