Slot-Machine
Three reels turn one step at a time. Each runs the command in its window, and each can nudge the next.
Zero player rodent · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Zero player rodent drew the program as a slot machine. Every program has three reels, a row of windows and a handle made of o and /, which the specification says is there for purely aesthetic reasons. The interpreter checks for it all the same.
Read the story
The reels take turns. Reel 1 runs the command in its window and turns one step, then reel 2, then reel 3, and round again. Each reel has its own commands, so 7 enqueues a 0 on reel 1, dequeues on reel 2 and prints a number on reel 3. To loop, a reel sends the next reel back to a mark. To branch, it turns the next reel one extra step when the front of the queue equals the accumulator, or when it does not.
The machine
A row is | a b c | with one command for each reel. The window row is ||a|b|c||/, and the row above it ends in o.
| Command | Reel 1 | Reel 2 | Reel 3 |
|---|---|---|---|
7 | Enqueue 0 | Dequeue | Print the front as a number |
$ | Add 1 to the front | Double the front | Subtract 1 from the front |
@ | Enqueue the front | Print the front as a character | End the run |
? | Accumulator = front | Enqueue the accumulator | Enqueue a random number up to it |
* | Reverse the queue | Enqueue a byte of input, 0 at the end | Enqueue front plus back |
On every reel ^ marks its place, > sends the next reel back to its mark, & turns the next reel one more step if the front equals the accumulator, and % if it does not. Reel 3's next reel is reel 1. = does nothing. The queue starts as [0] and the accumulator at 0.
Example
Seven is one, doubled, plus one, doubled, plus one.
Seven is one, doubled, plus one, doubled, plus one. Reel 1 adds and reel 2 doubles in the same round, and reel 3 prints.
The truth machine, with = in window 1 for an input of 0. It prints the 0, and since the front equals the accumulator, reel 2's % does not skip reel 3's @. With $ in window 1 it prints 1 forever.
The cat. Reel 2 reads a byte and prints it, and the loop runs until the byte read equals the accumulator, 0, which the end of the input gives.
And a machine without its handle does not run at all.
Patterns it teaches
- Turing completeness: thespecification translates minimized Brainpocalypse into reel rows, with a bounded tape of any size.
Further
See also
Queue-based
Write your own in Run Convert a program from Slot-Machine
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: slot-machine.
Command line
shib run slot-machine -e '| = |
| = | o
||=|=|7||/
| = % @ |
| ^ ^ = |
| = > ^ |
| > = 7 |
| = = > |'shib manual slot-machineSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/slot-machine.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org