'4'
A program is a single number. It starts with 3. and ends with 4, like the digits of pi in a webcomic joke.
Vriskanon, 2015 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Vriskanon made 4 in 2015, named after a joke in Homestuck about the last digit of pi. Every program is written in digits only. It opens with 3., then come operations, and it closes with 4, the exit instruction.
Read the story
There are 100 memory cells, numbered 00 to 99 as on a 10 by 10 grid, all starting at 0. An operation is one digit for what to do, followed by up to three two-digit cell numbers.
The machine
| Code | Does |
|---|---|
0 x y z | x = y + z |
1 x y z | x = y - z |
2 x y z | x = y * z |
3 x y z | x = y / z, rounded down |
4 | Exit |
5 x | Print the character whose code is in x |
6 x nn | Set x to the number nn, 00 to 99 |
7 x | Read one character into x |
8 x | If x is 0, skip past the matching 9 |
9 | Jump back to the matching 8 |
The only literals are two digits long, so a larger number is built with arithmetic. 6 00 16, 6 01 60 and 2 02 00 01 put 960 in cell 02, the code of π. Cells hold integers of any size, as in py-four, the Python interpreter Try It Online runs.
Example
The third program counts down.
The third program counts down. Cell 00 holds 5, cell 01 holds 1 and cell 02 holds 48, the code of 0. Inside the loop 0 03 00 02 makes the digit, 5 03 prints it and 1 00 00 01 takes one away. The spaces are for reading. The last program is a truth machine. It reads a character and prints 1 forever when it was a 1.
Patterns it teaches
- Counter machines: unbounded cells, subtraction and a loop that tests for zero are all a machine needs.
- Turing completeness: esolangs.org compiles Portable Minsky Machine Notation into 4.
Further
- esolangs.org/wiki/4
- py-four, the Python interpreter
See also
Cell-based
Write your own in Run Convert a program from '4'
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 4.
Command line
shib run 4 -e '3.600166016020200015024'shib manual 4Source
- Module
langs/tio/ports.js- Interpreter
langs/tio/4.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org