esolang

Duck Duck Goose

Ducks sit in a circle with one goose. Every result takes the goose's seat, and the goose moves on.

Vriskanon, 2015 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: H

The idea

Vriskanon made Duck Duck Goose in 2015, after a joke by Connor Lawman, with Chicken and brainfuck in mind. A program has two words, duck and goose. Numbers are how many ducks stand on a line.

Read the story

The data sits in a circle. The first line says how many ducks there are, each holding 0, and puts the goose after them. Every address counts ducks to the left of the goose. A command that makes a value puts it in the goose's seat, which becomes a duck, and the duck it names first becomes the new goose. So the goose walks round the circle, and the same address points somewhere else after each one.

The machine

A command is a line of N ducks, maybe a line of Y ducks, and then a line of ducks ending with goose. The ducks on that last line choose the command. A blank line counts as 0.

DucksDoes
0End
1Print the Nth duck as a character
2 3 4 5N + Y, N - Y, N * Y, N // Y into the goose's seat
6A character read into the goose's seat
7The Nth duck into the goose's seat, and a copy to the teacher
8The teacher into the goose's seat; the teacher becomes 0
9Start loop Y; skip past its end if the Nth duck is 0
10End loop N; go back to its start
11The number Y into the goose's seat

After 2 to 8 and 11 the Nth duck becomes the goose. The teacher is one more number outside the circle. Case does not matter, every word but duck and goose is ignored, and # starts a comment.

Example

This one makes 8, then 9, multiplies them and prints the 72.

This one makes 8, then 9, multiplies them and prints the 72. Two ducks and a goose start the circle.

A cat program. It reads a character, then loops while the duck holding it is not 0, printing it and reading the next. The end of the input reads as 0.

Expected: quack

The truth machine sets 7, squares it to 49, takes 1 minus 49 and adds the result to the character read. On 0 that leaves 0, the loop is skipped and it prints the character once. On 1 it prints 1 forever.

Expected: 0

The Hello World is 114 lines long and prints Hello, World! and a line break.

Patterns it teaches

Further

Queue-based

Write your own in Run Convert a program from Duck Duck Goose

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: duck-duck-goose.

Command line

shib run duck-duck-goose -e 'duck goose
duck
duck duck duck duck duck duck goose
duck

duck duck duck duck duck duck duck duck duck goose
duck
duck goose
duck
duck duck duck duck duck duck goose

duck duck duck duck duck duck duck duck duck duck goose
goose' --input 'Duck duck goose!'
shib manual duck-duck-goose

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/duck-duck-goose.js

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

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