esolang

Hive

Every ant carries one number. To add two numbers, two ants have to meet.

Bsoelch, 2023 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: Hello World!

The idea

Bsoelch made Hive in 2023, after the idea of hive intelligence. Every # in the grid starts an ant, and an ant can remember a single 32-bit number. Alone it can only turn, build its number from digits and print it. Everything else takes two ants that meet in one cell. That goes for arithmetic and comparisons, and for memory itself, as queues and stacks are ants trapped between brackets.

Read the story

So a Hive program is a matter of timing. Two paths have to deliver their ants to the same cell, and the one that arrives first gets the result.

The machine

CharDoes
#Start an ant here, facing east
< ^ > v / \Point it; mirrors
@Kill it
& 0 to 9 ~Set its number to 0; append a digit; negate
+ - * % =Wait for a second ant; the first gets A+B, A-B, A*B, A/B or A==B
w l e gWait for a second ant and kill it unless it is anything, less, equal or greater
{ }Split an ant into one going north and one going south
[ ] ( )Queues and stacks of waiting ants
, ? . !Read a byte or a number; write a byte or a number

On every tick each ant that is not waiting moves one cell. The specification leaves the order open; ants move in the order they were made, the grid wraps at its edges, and the program ends when no ant is left or every ant left is waiting.

Example

The Hello World has twelve ants.

The Hello World has twelve ants. Each reads its character code as digits and prints it on the fourth tick, all on the same tick, so the order they move in spells the text.

The Fibonacci numbers below 1000. Two ants holding 1 meet at +. The first takes the sum and goes round the loop below; the second goes on east, prints its number with ! and splits at {. One half carries the number back up to +, the other prints a space. A third ant builds 1000 from 0001, read right to left, and circles with it, and at l it kills any sum that is not below it.

Expected: 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

The prime checker reads a number with ? and prints 1 for a prime and 0 otherwise. The specification says its empty line matters for timing, and it does; without it every even number prints nothing. It gets every number from 2 to 120 right, and runs for ever on -1, 0 and 1.

Expected: 1

Patterns it teaches

Further

Concurrent programming

Two-dimensional languages

Write your own in Run Convert a program from Hive

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run hive -e ' #1 v <
#1> +!{
 /l w<0001#<
  ^ < \&32.@
 \   /'
shib manual hive

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/hive.js

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

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