Alice & Bob
Brain-Flak, except the second stack is a queue, and Bob thinks 0 is true.
bforte · Turing complete: yes · ●●● hard
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
bforte made Alice & Bob from Brain-Flak. Brain-Flak has a left stack and a right stack, and <> switches between them. The left one belongs to Alice and is still a stack. The right one belongs to Bob and is a queue: what goes in first comes out first. Bob also reads truth the other way round. A loop {...} on Alice's side runs while her top is not 0; on Bob's side it runs while the front of his queue is 0.
The machine
Everything is brackets. Each one has a value, and a group's value is the sum of its contents.
| Code | Does |
|---|---|
() | 1 |
(x) | Push the value of x onto the active store; its value too |
[] | The size of the active store |
[x] | Minus the value of x |
{} | Pop, 0 when empty |
{x} | Repeat x while the active store says true |
<> | Switch between Alice and Bob |
<x> | Run x, value 0 |
Other characters are ignored. Numbers have no limit. Input numbers start on Alice's stack with the first on top; TIO passes them as arguments; this implementation takes them from the input. At the end the active store is printed, top or front first, as characters modulo 128, the way the reference prints with -a. This implementation follows the Haskell interpreter at github.com/bforte/alice-bob.
Example
The first is the Brain-Flak triangle: count 12 down to 0, adding up 11 + 10 + … + 0, which is 66, a B.
The first is the Brain-Flak triangle: count 12 down to 0, adding up 11 + 10 + … + 0, which is 66, a B. The second pops 30 and 35 and pushes the sum, 65.
Pushing 65 and then 66 shows the difference between the two. On Alice's stack the 66 is on top, so it prints first, BA. After a <> the same pushes go to Bob's queue, and the 65 comes out first, AB.
Patterns it teaches
- Stack machines: a stack and a queue, both unbounded.
- Turing tarpit: eight characters, like Brain-Flak.
Further
- The Haskell interpreter
- Carol & Dave, by the same author, where the two switch after every step
See also
Also in Turing tarpits
Write your own in Run Convert a program from Alice & Bob
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: alice-bob.
Command line
shib run alice-bob -e '({}{})' --input '30 35'shib manual alice-bobSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/alice-bob.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language