esolang

Fading Rainbow

Every match rewrites at once, and everything that did not match fades away.

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

Tested with 6 known programs · Test method

Run it

Expected: 0110

The idea

Hakerh400 made Fading Rainbow in 2020. It looks like Thue, but it does not replace one match per step. Each iteration finds every match of every pattern, overlapping ones too, and the new string is made of their replacements alone. Whatever no pattern covered is gone. The specification shows it is Turing complete by compiling Consistent 01-2C into it.

The machine

The source is a row of blocks. A block is a run of bits, or . for an empty block, and there must be an even number of them, at least 8. Input and output are bits.

  • The main string is the first block, then for each input bit the second block, the bit and the third block, then the fourth block.
  • The blocks between the first four and the last four pair up as pattern and replacement.
  • In each iteration every match adds its replacement, ordered by place, then shorter pattern first, then earlier pattern first. That sequence is the new main string.
  • After an iteration in which the last pattern matched, the program halts. The fourth block from the end comes off the front, the last block comes off the end, and the two blocks between are removed wherever they stand.

Example

The cat is eight empty blocks.

The cat is eight empty blocks. With no patterns at all it halts at once.

The bit inverter. Input 110 becomes 000 + 011 011 010. The three patterns turn each 011 into 010 and each 010 into 011, and the two places where 000 occurs give nothing. 000 is also the last pattern, so the run halts after this one iteration, and removing every 01 leaves the inverted bits.

Expected: 001

The bit reverser has 124 lines and 122 patterns. In this implementation it reverses all 255 inputs of up to 7 bits.

Patterns it teaches

Further

Also in Rewriting

Write your own in Run Convert a program from Fading Rainbow

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run fading-rainbow -e '........' --input '0110'
shib manual fading-rainbow

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/fading-rainbow.js

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

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