Golden sunrise
Groups of bits are replaced until no group is left, and the bits left over are the answer.
Hakerh400, 2020 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 12 known programs · Test method
Run it
The idea
Hakerh400 made Golden sunrise in 2020. It has only two things, bits and groups. A group is written in parentheses and holds bits and more groups. The program starts with one group, the bit 0 followed by the input, and stops when no group is left. The bits that remain are the output.
Read the story
A rule says what a group starts with and what to put in its place. 101 - 11. turns any group that starts with 101 into the bits 11 followed by the rest of the group, so 10(101001)00 becomes 101100100. A right side can build new groups, and a group that rebuilds itself is a loop.
Rules may never overlap, and every group of bits must match one of them. The specification says the interpreter checks this before it runs.
The machine
| Left side | Matches a group that |
|---|---|
101 | starts with 101 |
101# | is exactly 101 |
/ | is anything; then it is the only rule |
| Right side | Puts in the group's place |
|---|---|
0 1 | A bit |
(...) | A new group |
. | The rest of the group after the matched bits |
/ | Nothing |
A letter on the left matches either bit and stands for it on the right, and ~a is the other bit. So ab - ba is four rules in one. Each step replaces the outermost group a rule matches, the first from the left, and tries a group before the groups inside it.
Example
Every program runs on the input 1011.
Every program runs on the input 1011. The cat matches the whole group, drops the leading 0 and keeps the rest.
Reverse moves one bit at a time out of the group, to its right. (01011) becomes (0011)1, then (011)01, and so on until the empty (0) goes.
Increment builds three nested groups and walks the carry through them. The specification shows 14 steps from (01011) to 1100.
Hello World is one rule that replaces the first group with 104 bits. They are Hello, World! in ASCII, with the lowest bit of each character first.
Patterns it teaches
- String rewriting: prefix rules on nested groups of bits.
- Tag systems: the specification turns any cyclic tag system into a program, which makes it Turing complete.
Further
See also
Also in Rewriting
Write your own in Run Convert a program from Golden sunrise
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: golden-sunrise.
Command line
shib run golden-sunrise -e 'a - .
# - /' --input '1011'shib manual golden-sunriseSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/golden-sunrise.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org