# shlomi-fish-homepage / t2 / puzzles / cs / lotg / index.html.wml

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112``` ```#include '../template.wml'

“Lotg” (originally standing for “Language of the Gods”) is a pseudocode I developed during my first year at the Technion. I wanted to develop such a code with a minimal set of instructions. Initially it had eight instructions, but I was able to reduce it to five. I believe it is Turing-complete. Here is an explanation of it.

Lotg is defined on a memory in which there is a cell associated with every integral number (positive, negative and zero), and every cell can contain one integral value. The cells will be marked as m[i] where i is the index of the cell. There are two registers - “pointer” and “register” which will be marked as r and p.

The following instructions are defined:

1. p ← i, where i is any integral parameter. This is the only instruction that accepts an arbitrary parameter.
2. r ← r+p
3. p ← m[p]
4. m[p] ← r ; r ← 0 - a composite instruction doing two instructions one after the other.
5. if r>0 jump to p (If r is greater than 0 jump to the instruction whose index is p).

Sample Constructs

Using these instructions one can define the following macros:

m[m[i]] = m[m[j]]

p = -10**100   # Essentially a number that should not concern us. m[p] = r ; r = 0 p = j p = m[p] p = m[p] r += p p = i p = m[p] m[p] = r ; r = 0

m[m[i]] += m[m[j]]

p = -10**100 m[p] = r; r = 0 p = j p = m[p] p = m[p] r += p p = i p = m[p] p = m[p] r += p p = i p = m[p] m[p] = r ; r = 0

if (m[i] = j) { [BLOCK] }

p = -10**100 m[p] = r ; r = 0 p = -j r += p p = i p = m[p] r += p p = i(end) if r > 0 jump p p = 1 r += p p = i(after) if r > 0 jump p p = -10**100 m[p] = r ; r = 0 p = 1 r += p p = i(end) if r > 0 jump p after:     [BLOCK] end:
```