Moving donut
A donut rolls through a maze and runs whatever it rolls over.
2023 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Moving donut grew out of Mice in a maze and HQ9+. The program is a maze drawn with #. The donut O rolls right until it meets a wall, then turns clockwise and tries again. Every cell it rolls into is a command. A lowercase letter prints itself, so a message is written along a corridor, and brainfuck's eight commands work a tape as they always do.
The machine
| Char | Does |
|---|---|
O | The donut, which starts facing right |
# | A wall |
a to z | Print the letter |
+ - < > [ ] , . | Brainfuck, on a tape of bytes |
A | Switch , and . between characters and decimal numbers |
The donut never turns straight back. At a wall it tries its right hand side first, then its left, and when both are walls too the run ends. A loop's ] puts the donut back on its [, and a [ over 0 sends it on along its path to the matching ].
Example
The donut prints hello along the bottom corridor.
The donut prints hello along the bottom corridor. At the wall its right hand side is a wall too, so it turns left and goes up through w and o, then left again through r, l and d. There it is stuck and stops.
The truth machine switches to numbers with A and climbs to ,, which reads one. On 0 the [ sends the donut on to ], and it turns onto the . in the corner, prints 0 and is stuck. On 1 it runs the loop from [ through . to ] and prints 1 forever.
In a straight corridor a brainfuck loop works as usual. The cell goes to 3, and each pass prints x and takes 1 away.
The longest program winds through a whole maze and prints movingdonutisaveryinterestinglanguage.
Patterns it teaches
- Two-dimensional control flow: the walls decide the order in which the commands run.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Moving donut
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: moving-donut.
Command line
shib run moving-donut -e '########
#O+[,.]#
########' --input 'hi '