RosettaCodeData/Task/Subleq/Phix/subleq.phix
2024-11-04 21:53:44 -08:00

21 lines
601 B
Text

procedure subleq(sequence code)
integer ip := 0
while ip>=0 do
integer {a,b,c} = code[ip+1..ip+3]
ip += 3
if a=-1 then
code[b+1] = iff(platform()=JS?'?':getc(0))
elsif b=-1 then
puts(1,code[a+1])
else
code[b+1] -= code[a+1]
if code[b+1]<=0 then
ip := c
end if
end if
end while
end procedure
subleq({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})