2 variable trickery
Two numbers, one command per line, and a loop that never ends.
A() · Turing complete: no · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
A() made 2 variable trickery as a test for a small C# interpreter, and the specification includes the whole interpreter. There are two variables, X and Y, both floats that start at 0. Each line of the program is one command. There are no jumps, so a program runs from top to bottom once.
Read the story
The only loop is T. If X equals Y it prints X forever, and otherwise it does nothing. That is enough for a truth machine and for little else.
The machine
| Line | Does |
|---|---|
X Y | Print the variable |
X+ Y+ X- Y- | Add or take 1 |
++ -- * / % | Set X to X plus, minus, times, divided by or modulo Y |
IX IY | Read a line of input as a number |
T | While X equals Y, print X |
E | Print INVAILD, then end |
Any other line prints INVAILD, spelled as the interpreter spells it. So does E, since the C# has no case for it and only tests for E once the line has run. The C# program reads its commands and its input from the same console, so IX takes the next line typed. This implementation takes the program and the input separately. As in the C#, a program without E runs past its last line and prints INVAILD forever. Arithmetic is single precision, and numbers are read and printed the way .NET 8 does on an English system.
Example
The first is a truth machine.
The first is a truth machine. It reads X and prints it, then sets Y to 1. On 0 the T does nothing, and E prints INVAILD and ends the program. On 1 X equals Y, and T prints 1 forever. The second reads 7 and 2 and prints 7 divided by 2.
See also
Unknown year
Write your own in Run Convert a program from 2 variable trickery
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 2-variable-trickery.
Command line
shib run 2-variable-trickery -e 'IX
X
Y+
T
E' --input '0'shib manual 2-variable-trickerySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/2-variable-trickery.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org