Kolmogorov
Memory is a graph of nodes that hold bytes, and the value of an edge is the address of the node it leads to.
2009 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Kolmogorov is based on the Kolmogorov machine, which works on a graph where a Turing machine has a tape. Every node holds one byte and every edge carries one byte. Seen from the active node, the value of an edge is the address of its neighbour, so \1 means the node at the end of edge 1. A program builds its own memory as it runs, one node at a time.
Read the story
The specification shows a reduction from brainfuck. Lay the nodes out in a row, each joined to the next by an edge 0 and to the one before by an edge 1. Then > is s\0, < is s\1 and + is +*\1. The original interpreter is lost, which the designer wrote about in 2017.
The machine
| Code | Does |
|---|---|
\n | The byte n, 0 to 255 |
p x | The value of the node at address x |
i | One byte of input |
* | The address of the active node |
a v e | Make a node holding v at the end of a new edge e |
j x y e | Join the node at x to the node at y by an edge e |
s x | Make the node at x active |
o x | Print the node at x as a character |
+ x n, - x n | Add or subtract n, wrapping at 256 |
R e, r e | Remove the node at e, or the edge e |
[x ...] | Repeat while the node at x holds more than 0 |
{e ...} | Repeat while the active node has an edge e |
Text in double quotes is a comment. The run starts on one node that holds 0. A new edge replaces an old one with the same value, which is how the array program leaves its inner loop. Reading past the end of the input ends the run.
Example
The countdown from the specification adds 9 to the active node.
The countdown from the specification adds 9 to the active node. Then it adds 48, prints the digit and takes 49 off, until the node holds 0.
The truth machine keeps a 1 in the neighbour at edge 1 and prints it forever when the input is 1. The cat loops on a neighbour that always holds 1.
The array program builds a row of nodes that each hold < and are each joined to one counter node. Every round prints the node it stands on, walks along edge 0 to the end of the row, adds a node there and counts down from 5.
Patterns it teaches
- Turing tarpit: eight statements and two loops, and each brainfuck command has a short translation.
- Turing completeness: the specification shows it by translating brainfuck.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Kolmogorov
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: kolmogorov.
Command line
shib run kolmogorov -e '"This program prints out the numbers 9 - 1"
+*\9 "Add 9 to the active node"
[*
+*\48 "Add 48 to the active node"
o*
-*\49 "Subtract 49 from the active node"
]'shib manual kolmogorovSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/kolmogorov.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org