Left-Right March
One line of cells, a pointer that marches both ways, and every command reads the two digits in front of it.
DigitalDetective47, 2021 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
DigitalDetective47 made Left-Right March in 2021. The first line of the program is a row of cells, and everything after it is a comment. A pointer starts on the leftmost cell facing right. It runs the cell it stands on and moves one cell on, until it walks off either end.
Read the story
A digit does nothing. Any other character is a command, and its argument is the two digits ahead of it in the way the pointer faces. So 34c12 sets the accumulator to 12 when the pointer passes from the left and to 34 when it passes from the right. The digits are read left to right either way. Programs reuse the same cells in both directions, and w writes the accumulator back into the digits, so a program can change its own arguments.
The machine
| Command | Does |
|---|---|
a s m d | Add, subtract, multiply or divide A by F |
c | Set A to F |
w | Write A into the two digits of F |
j | Jump F cells ahead |
b | Jump F cells ahead if A is not 0 |
l r | Face left or right |
i | Read a character into A, 99 at the end of the input |
p | Print the character of A |
A holds 0 to 99, and every result is taken modulo 100. Characters go through LSCEF, a table the specification links to but does not include. Its programs show 1 for space, 9 for H, eight lower case letters from c at 30 to w at 50, 54 to 63 for the digits, 64 for ! and 88 for the comma. This implementation fills in the rest of A to Z as 2 to 27 and of a to z as 28 to 53, the runs those letters sit in. Any other character stops the run with an error, so this is a subset.
Example
The truth machine reads a character and takes away 54, the value of 0.
The truth machine reads a character and takes away 54, the value of 0. On 0 it prints 0 and jumps off the end. On 1 it prints 1 and marches between r00 and l00 for ever, printing 1 at p00 each way.
The cat adds 1 to each character it reads. The 99 at the end of the input wraps to 0, the branch is not taken and j14 jumps off the field. Otherwise it takes the 1 back, prints and turns at l00. Marching left, the j reads the 18 of p18 as its own argument and jumps back to the r that turns it right again.
The specification's text dump program generator writes a program that prints its input. Given Hello, world! it writes the Hello World above, character for character, and leaves out the c before the second l.
Patterns it teaches
- Self-modifying code:
wwrites A into the digits other commands read as arguments, and the text dump generator keeps every number it works with there.
See also
Self-modifying
Cell-based
Write your own in Run Convert a program from Left-Right March
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: left-right-march.
Command line
shib run left-right-march -e 'j03ri00a01b05j14s01p18j02l00' --input 'Hello, world!'shib manual left-right-marchSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/left-right-march.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org