esolang

Monkeys

Seven monkeys on a grid of ladders. Each one holds a number, and arithmetic happens when they stand next to each other.

david.werecat, 2012 · Turing complete: no · ●●○ moderate · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: A

The idea

david.werecat made Monkeys in 2012, as a break from his larger languages. The only objects are seven monkeys on a 10 by 10 grid, which also holds 14 bananas. Each monkey holds one byte. A program is a list of tasks, one per line, each a monkey's number and what it should do.

Read the story

Climbing changes a monkey's value. A move to a free square adds 1, unless the monkey now stands next to another; climbing off the grid takes 1 away; bumping into another monkey either swaps a banana or adds 1 to both. Arithmetic is social. TEACH adds a monkey's value to every awake monkey around it, and FIGHT, BOND and EGO subtract, multiply and divide the same way.

The machine

The grid starts like this, ! a banana, with one more banana under monkeys 6 and 7.

..!1.!....
.......2!.
.........!
.3.!......
.......!..
.!....!...
..5.!4....
....6...!.
......!...
.7......!.
ActionDoes
UP DOWN LEFT RIGHTMove, with the effects above
LEARN YELLRead a byte into the value; print the value
TEACH FIGHT BOND EGO+ - * / on the values of the awake monkeys on the eight squares around
SLEEP WAKEA sleeping monkey ignores every task but WAKE; one carrying a banana cannot sleep
GRAB DROP EATBananas; when all 14 are eaten the program ends
MARK BACKRemember this line; jump back to the remembered line
PLAYA random value; a fixed sequence in this implementation, so runs repeat

There are no errors; a line that makes no sense is skipped. Values wrap at 256, and with only seven bytes of memory the language is not Turing complete.

Example

Monkey 4 steps right to a lonely square and back, which leaves it at 1.
Expected: hi

Monkey 4 steps right to a lonely square and back, which leaves it at 1. Monkey 6 stands diagonally next to it, so eight lessons make 6 worth 8. 6 BOND makes 4 worth 8, 4 BOND makes 6 worth 64, and a climb down to a free square adds the last 1.

Further

Ideas it shows

Object-oriented paradigm

Two-dimensional languages

Write your own in Run Convert a program from Monkeys

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: monkeys.

Command line

shib run monkeys -e '1 UP
1 YELL'
shib manual monkeys

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/monkeys.js

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

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