URM interpreter in CoffeeScript, 143 bytes (167 with new lines).
This version of URM has consists of an unbounded amount of registers, with zero, successor and jump operators. It is well known that this is turing-complete.
The URM program is written in the array c
(commands), and the inputs are in the array r
(registers). After the calculation the output is at r[0]
and this value is displayed.
The interpreter, with sample program and input that computes 32+13 (and indeed outputs 45):
# Addition program, similar to http://planetmath.org/examplesofunlimitedregistermachines
c = [['j', 1, 2, 4], ['s', 0], ['s', 2], ['j', 1, 1, 0]]
# Input: 32, 13, thus the desired output is: 45
r = [32, 13]
k = 0
while k < c.length
t = c[k]
k += 1
if t[0] == 'z'
r[t[1]] = 0
if t[0] == 's'
if !r[t[1]]?
r[t[1]] = 0
r[t[1]] += 1
if t[0] == 'j' && r[t[1]] == r[t[2]]
k = t[3]
alert r[0]
Minified version:
k=0
while k
What I really like in this code is that is really straightforward and easy to understand.