MSR
Match, switch, reverse. Rules flip bits in an endless grid until none of them can.
GDavid, 2018 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
GDavid made MSR, short for Match Switch Reverse, in 2018. Memory is an endless grid of bits in as many dimensions as the program asks for, and each bit is called a field. A program is nothing but numbers. It lists operations and the fields that are set at the start.
Read the story
An operation names the fields that must be set, the fields that must not be set and the fields to switch. The operations run in order, cycle after cycle, and each one that matches switches its fields. When a whole cycle matches nothing, the run ends and prints the fields that are set. There is no input, so the data is part of the program.
Given a number of steps instead of 0, MSR runs backwards. In each cycle it switches an operation's fields once more and keeps that when the operation matches again, which undoes it. A program only ever touches the fields it names, and the specification counts MSR as most likely a finite state machine.
The machine
A program is whole numbers in this order, separated by any whitespace.
| Part | Holds |
|---|---|
| Dimensions | How many numbers name one field |
| Operations | How many, then each one as three lists |
| A list | A count, then that many fields |
| Set fields | One list, the fields set at the start |
| Steps | 0 to run forward, or how many cycles to step back |
| Log | 0, or print the grid every that many cycles |
The three lists of an operation are the fields that must be set, those that must not be set and those to switch. The output is the number of set fields, then each set field on a line of its own and, after a forward run, the number of cycles that switched something.
Example
A one bit increment, with the data bit at 10 and the overflow bit at 20.
A one bit increment, with the data bit at 10 and the overflow bit at 20. The data bit starts at 1. In the first cycle the first operation carries it into the overflow bit, and the second cycle finds nothing to do.
When the data bit starts at 0, the second operation sets it in the first cycle and the first operation carries it in the second. The run goes on until nothing matches, so a 0 is incremented twice.
The interpreter in the specification tests the fields that must not be set against the wrong list, so this example cannot run on it. This implementation tests them as the specification describes. Stepping back follows the interpreter, which tries every operation but the first.
Further
Ideas it shows
See also
Also in Rewriting
Write your own in Run Convert a program from MSR
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: msr.
Command line
shib run msr -e '1 2 1 10 1 20 2 10 20 0 2 10 20 1 10 0 0 0'shib manual msrSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/msr.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org