esolang

Gummy Bear

A string of bits with one dot in it, and rules that rewrite what touches the dot on either side.

Hakerh400, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 1010001

The idea

Hakerh400 made Gummy Bear in 2020. The input bits get a dot in front, and the dot splits the string in a left part and a right part. A rule names bits that end the left part and bits that start the right part, and what to put in their place. Each step uses the first rule in the source that fits. When none fits, the string without its dot is the output.

Read the story

The dot is the only place where anything happens, so a program walks it through the string by rewriting the bits on one side and handing them to the other.

The machine

RuleDoes
a.b.c.dIf the left part ends with a and the right part starts with b, a becomes c and b becomes d
#a.b.c.da must be the whole left part
a.b#.c.db must be the whole right part
a.b~Remove a, the dot and b, and stop

Rules are split by whitespace, and // starts a comment.

Example

Invert the bits.

Invert the bits. Each step flips the bit right of the dot and moves it to the left. After seven steps the dot is at the end and no rule fits.

A program with no rules is a cat.

Expected: 110101

Reverse the bits. The program takes 65 steps on 11001, the same 65 its table lists. It first writes each bit as a pair, 00 for a 0 and 01 for a 1, and it ends with 11.#~, which removes two marker bits and the dot.

Expected: 10011

Patterns it teaches

  • String rewriting: rules tried from the top, with the dot as a cursor that only rules can move.

Further

String-rewriting paradigm

Write your own in Run Convert a program from Gummy Bear

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run gummy-bear -e '// noop' --input '110101'
shib manual gummy-bear

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/gummy-bear.js

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

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