RosettaCodeData/Task/Subleq/Pluto/subleq.pluto
2026-04-30 12:34:36 -04:00

26 lines
759 B
Text

require "io2"
local function subleq(program)
local words = program:split(" "):map(|w| -> tonumber(w))
local sb = ""
local ip = 0
while true do
local a = words[ip + 1]
local b = words[ip + 2]
local c = words[ip + 3]
ip += 3
if a < 0 then
words[b + 1] = tonumber(io.readStr("Enter a character : ", 1, 1))
elseif b < 0 then
sb ..= string.char(words[a + 1])
else
words[b + 1] -= words[a + 1]
if words[b + 1] <= 0 then ip = c end
if ip < 0 then break end
end
end
io.write(sb)
end
local program = "15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0"
subleq(program)