fn main [ var l := list_break_whitespace(read_lazy(h[0])); var r := [ ston(l[2]), ston(l[5]), ston(l[8]) ]; var pgm := list_replace_substring(l[10], ",", ""); var ip := 0; var output := empty(byte); while ip + 2 <= len(pgm) do [ var lit : int := pgm[ip + 1] - '0'; var combo : int := select(lit >= 4, lit, r[lit - 4]); var opcode := pgm[ip] - '0'; if opcode = 0 then [ r[0] shr= combo; ] else if opcode = 1 then [ r[1] xor= lit; ] else if opcode = 2 then [ r[1] := combo and 7; ] else if opcode = 3 then [ if r[0] <> 0 then [ ip := lit; continue; ] ] else if opcode = 4 then [ r[1] xor= r[2]; ] else if opcode = 5 then [ if len_greater_than(output, 0) then output +<= ','; output +<= (combo and 7) + '0'; ] else if opcode = 6 then [ r[1] := r[0] shr combo; ] else if opcode = 7 then [ r[2] := r[0] shr combo; ] else [ abort; ] ip += 2; ] write(h[1], output + nl); ]