esolang

'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

Expected: Hello, World!

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

CodeDoes
0 x y zx = y + z
1 x y zx = y - z
2 x y zx = y * z
3 x y zx = y / z, rounded down
4Exit
5 xPrint the character whose code is in x
6 x nnSet x to the number nn, 00 to 99
7 xRead one character into x
8 xIf x is 0, skip past the matching 9
9Jump 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.
Expected: π
Expected: 54321
Expected: 0

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

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 4

Source

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