'99'
Programs are written in nines and spaces. Even the variable names are runs of nines.
Turing complete: yes · ●●○ moderate
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
99 comes from a challenge on Code Golf Stack Exchange: write an interpreter for a language made of the digit 9. Every other character is ignored. A run of nines is a variable, and a variable named with n nines starts out holding n ones, so 999 holds 111. Arithmetic is only adding and subtracting, and the only control flow is a conditional jump.
Read the story
TIO runs a golfed Perl answer to that challenge, which translates each line into Perl and evals it. This implementation follows it.
The machine
Each line is one statement. Its shape decides what it does.
| Line | Does |
|---|---|
A B C D | A becomes B minus C plus D, the signs alternating |
A | Print A: as a number if A has an odd count of nines, as a character (modulo 128) if even |
A (space first) | Read into A: a number if odd, the code of the first character of a line if even |
A B C | Jump to line A times 9 if B and C are all 0 |
Lines count from 0, and a jump goes to the value times 9, so loops can only start on lines 0, 9, 18 and so on. Empty lines pad the gap. A jump before the start or past the end ends the program.
Example
The first sets 999 to 1 minus 1, then 9 to 1111 minus 11, and prints it.
The first sets 999 to 1 minus 1, then 9 to 1111 minus 11, and prints it. The second reads a number into 9 and a character into 99, then prints both; the even name prints its value as a character.
Patterns it teaches
- Encoding tricks: constants come from the starting values, 1, 11, 111 and so on, added and subtracted.
- Counter machines: unbounded integers, subtraction and a jump on zero are enough for any computation.
Further
- The Perl interpreter that TIO runs
See also
Also in Turing tarpits
Write your own in Run Convert a program from '99'
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 99.
Command line
shib run 99 -e ' 9
99
9
99' --input '42
A
'shib manual 99Source
- Module
langs/tio/ports.js- Interpreter
langs/tio/99.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language