esolang

Integer

The program is one number, the input is one number, and running it rewrites one number.

Hakerh400, 2020 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 7 known programs · Test method

Run it

Expected: 42

The idea

Hakerh400 made Integer in 2020. A program is a single non-negative integer and so is the input. The two are woven into one main number, which is rewritten step by step until it says stop, and then the output is read off it.

Read the story

The base comes from the program. It is e, the smallest number above 1 that divides the program, so every even program works in binary. All the work is shuffling base-e digits. Digits in even places belong to the program and digits in odd places to the data, and each half splits the same way again.

The machine

Unfolded, the rules make a machine with two stacks of digits, j and k, and a list of instructions. The program part holds a pointer to the current instruction, and a pointer of 0 halts.

Instruction mod 4Does
0Flip the top digit of j, d becomes e - 1 - d
1Swap j and k
2Push a 0 onto j
3Pop j and jump to one of two next instructions, by whether the digit was 0

The input I starts as I digits of e - 1 on k, a count in unary. The output is read the same way, as the number of digits on top of k before the first 0. The specification writes all of this as six helper functions and five cases on whole numbers, and this implementation follows them exactly.

Example

The program 0 is a cat, since its pointer is 0 from the start and the input is the output.
Expected: 4
Expected: 42
Expected: 3

The program 0 is a cat, since its pointer is 0 from the start and the input is the output. The others are the decrement, increment and halving. The specification also has a doubling program of 578 digits. Its shortest known program for counting the ones in a binary number has about 342 million digits and did not fit in the specification.

Patterns it teaches

Further

Also in Rewriting

Write your own in Run Convert a program from Integer

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: integer.

Command line

shib run integer -e '0' --input '5'
shib manual integer

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/integer.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org