Hello today I am a unicorn
Two variables, three bit operations and one jump. That is enough for a Turing machine.
Hakerh400, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Hakerh400 made Hello today I am a unicorn in 2020. It has exactly two variables, x and y, both whole numbers with no upper bound. Each one is a stack of bits. A left shift pushes a 0, a flip of the lowest bit turns it into a 1, a right shift pops, and the jump looks at the bit on top. Two stacks and free jumps make a Turing machine.
Read the story
The input is a number, written to x before the start. When the program ends, y is the output.
The machine
| Instruction | Does |
|---|---|
x~ | Flip the lowest bit; 123 becomes 122 |
x+ | Shift left; 5 becomes 10 |
x- | Shift right; 15 becomes 7 |
x? a b | Jump to label a if the lowest bit is 1, else to label b |
name: | A label in front of an instruction |
Every instruction works the same way on y. All but ? go on to the next instruction, and the program ends after the last one.
Example
The cat moves the bits of x to y two at a time while the first of each pair is 1.
The cat moves the bits of x to y two at a time while the first of each pair is 1. On 7, which is 111, it builds 1110, which is 14.
The cat is meant for text, turned into a number the way its Semper dissolubilis page does. Each bit of each byte, lowest first, gets a 1 in front of it. The letter a becomes 16 bits, and read from the lowest bit they are 32087. The cat gives back the same 16 bits in y, read from the highest bit, which is 60094.
Patterns it teaches
- Counter machines: two numbers used as two stacks of bits.
See also
Also in Turing tarpits
Write your own in Run Convert a program from Hello today I am a unicorn
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: hello-today-i-am-a-unicorn.
Command line
shib run hello-today-i-am-a-unicorn -e 'x~' --input '123'shib manual hello-today-i-am-a-unicornSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/hello-today-i-am-a-unicorn.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org