broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 1 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Backward loops land two bytes early and re-execute the wrong instruction; forward jumps fall short.

Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c != 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c <= 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Loops exit immediately and guard blocks run exactly when they should be skipped.

Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else b - a)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else abs(a - b))
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Decrementing counters increase and swapped operands produce negated differences.

Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1] = stack[-2]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack.append(stack.pop(-2)) if len(stack) > 2 else None
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
After SWAP both top slots hold the same value and the original top is lost.

Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps > fuel:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, fuel):
    def run():
        pc = 0
        stack = []
        out = []
        steps = 0
        while True:
            if pc < 0 or pc >= len(code):
                return {'status': 'badpc', 'pc': pc, 'out': out, 'stack': stack}
            if steps >= fuel - 1:
                return {'status': 'fuel', 'pc': pc, 'out': out, 'stack': stack}
            steps += 1
            op = code[pc]
            if op == 0:
                return {'status': 'halt', 'pc': pc, 'out': out, 'stack': stack}
            need = {1: 0, 2: 2, 3: 2, 4: 0, 5: 1, 6: 1, 7: 2, 8: 1}.get(op)
            if need is None:
                return {'status': 'badop', 'pc': pc, 'out': out, 'stack': stack}
            if len(stack) < need:
                return {'status': 'underflow', 'pc': pc, 'out': out, 'stack': stack}
            if op == 1:
                stack.append(code[pc + 1])
                pc += 2
            elif op == 2 or op == 3:
                b = stack.pop()
                a = stack.pop()
                stack.append(a + b if op == 2 else a - b)
                pc += 1
            elif op == 4:
                pc += 2 + code[pc + 1]
            elif op == 5:
                c = stack.pop()
                pc = pc + 2 + code[pc + 1] if c == 0 else pc + 2
            elif op == 6:
                stack.append(stack[-1])
                pc += 1
            elif op == 7:
                stack[-1], stack[-2] = stack[-2], stack[-1]
                pc += 1
            else:
                out.append(stack.pop())
                pc += 1
    try:
        return run()
    except IndexError:
        return {'status': 'trap'}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: countdown loop prints n..1',
   ([1, 2, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 3, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-1], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -1, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 1, 8, 0], 3), {'out': [1], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 1, 8, 0], 2),
   {'out': [1], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 1, 6, 2, 8, 0], 20),
   {'out': [2], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 6, 0], 10),
   {'out': [], 'pc': 8, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 3, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 6, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-4], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -2, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 2, 8, 0], 3), {'out': [2], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 2, 8, 0], 2),
   {'out': [2], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 2, 6, 2, 8, 0], 20),
   {'out': [4], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 7, 0], 10),
   {'out': [], 'pc': 9, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 4, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 9, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-7], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -3, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 3, 8, 0], 3), {'out': [3], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 3, 8, 0], 2),
   {'out': [3], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 3, 6, 2, 8, 0], 20),
   {'out': [6], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 8, 0], 10),
   {'out': [], 'pc': 10, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 5, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 12, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-10], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -4, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 4, 8, 0], 3), {'out': [4], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 4, 8, 0], 2),
   {'out': [4], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 4, 6, 2, 8, 0], 20),
   {'out': [8], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 9, 0], 10),
   {'out': [], 'pc': 11, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})],
 [('regression: countdown loop prints n..1',
   ([1, 6, 6, 5, 7, 6, 8, 1, 1, 3, 4, -10, 0], 200),
   {'out': [6, 5, 4, 3, 2, 1], 'pc': 12, 'stack': [0], 'status': 'halt'}),
  ('swap then subtract uses swapped order',
   ([1, 15, 1, 2, 7, 3, 8, 0], 50),
   {'out': [-13], 'pc': 7, 'stack': [], 'status': 'halt'}),
  ('jz on negative value falls through',
   ([1, -5, 5, 2, 1, 99, 0], 50),
   {'out': [], 'pc': 6, 'stack': [99], 'status': 'halt'}),
  ('fuel exactly sufficient halts', ([1, 5, 8, 0], 3), {'out': [5], 'pc': 3, 'stack': [], 'status': 'halt'}),
  ('fuel one short reports exhaustion',
   ([1, 5, 8, 0], 2),
   {'out': [5], 'pc': 3, 'stack': [], 'status': 'fuel'}),
  ('dup on empty stack underflows', ([6, 0], 10), {'out': [], 'pc': 0, 'stack': [], 'status': 'underflow'}),
  ('dup with one item doubles',
   ([1, 5, 6, 2, 8, 0], 20),
   {'out': [10], 'pc': 5, 'stack': [], 'status': 'halt'}),
  ('forward jump beyond code is badpc',
   ([4, 10, 0], 10),
   {'out': [], 'pc': 12, 'stack': [], 'status': 'badpc'}),
  ('control: unknown opcode', ([1, 1, 42, 0], 10), {'out': [], 'pc': 2, 'stack': [1], 'status': 'badop'})]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A program given exactly one unit too little fuel still halts normally.

Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(ops):
    def wrap(v):
        v &= 0xFFFFFFFF
        return v - 0x100000000 if v > 0x80000000 else v
    out = []
    for op, a, b in ops:
        if op == 'iadd':
            out.append(wrap(a + b))
        elif op == 'imul':
            out.append(wrap(a * b))
        elif op == 'idiv':
            if b == 0:
                out.append('ArithmeticException')
            else:
                q = abs(a) // abs(b)
                out.append(wrap(q if (a < 0) == (b < 0) else -q))
        elif op == 'irem':
            if b == 0:
                out.append('ArithmeticException')
            else:
                r = abs(a) % abs(b)
                out.append(r if a >= 0 else -r)
        elif op == 'ishl':
            out.append(wrap(a << (b & 31)))
        elif op == 'ishr':
            out.append(a >> (b & 31))
        elif op == 'iushr':
            out.append(wrap((a & 0xFFFFFFFF) >> (b & 31)))
        elif op == 'ineg':
            out.append(wrap(-a))
        else:
            out.append('VerifyError')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483646, 1], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -8, 2], ['idiv', 9, -2]],), [-4, -4]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483647, -1]],),
   [-2147483648, 2147483647]),
  ('irem takes the sign of the dividend', ([['irem', -10, 3], ['irem', 11, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 2, 32], ['ishl', 3, 34]],), [2, 12]),
  ('iushr is a logical shift with masking', ([['iushr', -16, 28], ['iushr', -16, 37]],), [15, 134217727]),
  ('division by zero', ([['idiv', 1, 0], ['irem', 1, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65537], ['ishr', -8, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [65536, -2, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483645, 2], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -9, 2], ['idiv', 11, -2]],), [-4, -5]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483646, -1]],),
   [-2147483648, 2147483646]),
  ('irem takes the sign of the dividend', ([['irem', -13, 3], ['irem', 14, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 3, 32], ['ishl', 3, 35]],), [3, 24]),
  ('iushr is a logical shift with masking', ([['iushr', -32, 28], ['iushr', -16, 38]],), [15, 67108863]),
  ('division by zero', ([['idiv', 2, 0], ['irem', 2, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65538], ['ishr', -16, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [131072, -4, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483644, 3], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -10, 2], ['idiv', 13, -2]],), [-5, -6]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483645, -1]],),
   [-2147483648, 2147483645]),
  ('irem takes the sign of the dividend', ([['irem', -16, 3], ['irem', 17, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 4, 32], ['ishl', 3, 36]],), [4, 48]),
  ('iushr is a logical shift with masking', ([['iushr', -48, 28], ['iushr', -16, 39]],), [15, 33554431]),
  ('division by zero', ([['idiv', 3, 0], ['irem', 3, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65539], ['ishr', -24, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [196608, -6, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483643, 4], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -11, 2], ['idiv', 15, -2]],), [-5, -7]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483644, -1]],),
   [-2147483648, 2147483644]),
  ('irem takes the sign of the dividend', ([['irem', -19, 3], ['irem', 20, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 5, 32], ['ishl', 3, 37]],), [5, 96]),
  ('iushr is a logical shift with masking', ([['iushr', -64, 28], ['iushr', -16, 40]],), [15, 16777215]),
  ('division by zero', ([['idiv', 4, 0], ['irem', 4, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65540], ['ishr', -32, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [262144, -8, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483642, 5], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -12, 2], ['idiv', 17, -2]],), [-6, -8]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483643, -1]],),
   [-2147483648, 2147483643]),
  ('irem takes the sign of the dividend', ([['irem', -22, 3], ['irem', 23, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 6, 32], ['ishl', 3, 38]],), [6, 192]),
  ('iushr is a logical shift with masking', ([['iushr', -80, 28], ['iushr', -16, 41]],), [15, 8388607]),
  ('division by zero', ([['idiv', 5, 0], ['irem', 5, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65541], ['ishr', -40, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [327680, -10, -2147483648, 'VerifyError'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(ops):
    def wrap(v):
        v &= 0xFFFFFFFF
        return v - 0x100000000 if v >= 0x7FFFFFFF else v
    out = []
    for op, a, b in ops:
        if op == 'iadd':
            out.append(wrap(a + b))
        elif op == 'imul':
            out.append(wrap(a * b))
        elif op == 'idiv':
            if b == 0:
                out.append('ArithmeticException')
            else:
                q = abs(a) // abs(b)
                out.append(wrap(q if (a < 0) == (b < 0) else -q))
        elif op == 'irem':
            if b == 0:
                out.append('ArithmeticException')
            else:
                r = abs(a) % abs(b)
                out.append(r if a >= 0 else -r)
        elif op == 'ishl':
            out.append(wrap(a << (b & 31)))
        elif op == 'ishr':
            out.append(a >> (b & 31))
        elif op == 'iushr':
            out.append(wrap((a & 0xFFFFFFFF) >> (b & 31)))
        elif op == 'ineg':
            out.append(wrap(-a))
        else:
            out.append('VerifyError')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483646, 1], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -8, 2], ['idiv', 9, -2]],), [-4, -4]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483647, -1]],),
   [-2147483648, 2147483647]),
  ('irem takes the sign of the dividend', ([['irem', -10, 3], ['irem', 11, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 2, 32], ['ishl', 3, 34]],), [2, 12]),
  ('iushr is a logical shift with masking', ([['iushr', -16, 28], ['iushr', -16, 37]],), [15, 134217727]),
  ('division by zero', ([['idiv', 1, 0], ['irem', 1, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65537], ['ishr', -8, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [65536, -2, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483645, 2], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -9, 2], ['idiv', 11, -2]],), [-4, -5]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483646, -1]],),
   [-2147483648, 2147483646]),
  ('irem takes the sign of the dividend', ([['irem', -13, 3], ['irem', 14, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 3, 32], ['ishl', 3, 35]],), [3, 24]),
  ('iushr is a logical shift with masking', ([['iushr', -32, 28], ['iushr', -16, 38]],), [15, 67108863]),
  ('division by zero', ([['idiv', 2, 0], ['irem', 2, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65538], ['ishr', -16, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [131072, -4, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483644, 3], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -10, 2], ['idiv', 13, -2]],), [-5, -6]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483645, -1]],),
   [-2147483648, 2147483645]),
  ('irem takes the sign of the dividend', ([['irem', -16, 3], ['irem', 17, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 4, 32], ['ishl', 3, 36]],), [4, 48]),
  ('iushr is a logical shift with masking', ([['iushr', -48, 28], ['iushr', -16, 39]],), [15, 33554431]),
  ('division by zero', ([['idiv', 3, 0], ['irem', 3, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65539], ['ishr', -24, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [196608, -6, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483643, 4], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -11, 2], ['idiv', 15, -2]],), [-5, -7]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483644, -1]],),
   [-2147483648, 2147483644]),
  ('irem takes the sign of the dividend', ([['irem', -19, 3], ['irem', 20, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 5, 32], ['ishl', 3, 37]],), [5, 96]),
  ('iushr is a logical shift with masking', ([['iushr', -64, 28], ['iushr', -16, 40]],), [15, 16777215]),
  ('division by zero', ([['idiv', 4, 0], ['irem', 4, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65540], ['ishr', -32, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [262144, -8, -2147483648, 'VerifyError'])],
 [('regression: iadd reaching MAX_VALUE',
   ([['iadd', 2147483642, 5], ['iadd', 2147483647, 1]],),
   [2147483647, -2147483648]),
  ('idiv truncates toward zero', ([['idiv', -12, 2], ['idiv', 17, -2]],), [-6, -8]),
  ('idiv MIN_VALUE by -1 overflows to MIN_VALUE',
   ([['idiv', -2147483648, -1], ['idiv', -2147483643, -1]],),
   [-2147483648, 2147483643]),
  ('irem takes the sign of the dividend', ([['irem', -22, 3], ['irem', 23, -3]],), [-1, 2]),
  ('ishl masks the shift count to five bits', ([['ishl', 6, 32], ['ishl', 3, 38]],), [6, 192]),
  ('iushr is a logical shift with masking', ([['iushr', -80, 28], ['iushr', -16, 41]],), [15, 8388607]),
  ('division by zero', ([['idiv', 5, 0], ['irem', 5, 0]],), ['ArithmeticException', 'ArithmeticException']),
  ('controls: imul wrap, ishr, ineg MIN',
   ([['imul', 65536, 65541], ['ishr', -40, 2], ['ineg', -2147483648, 0], ['bogus', 1, 1]],),
   [327680, -10, -2147483648, 'VerifyError'])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Overflowing MAX_VALUE + 1 reports 2147483648 instead of MIN_VALUE.

Each op is [name, a, b] over 32-bit two's complement ints: iadd/imul wrap; idiv truncates toward zero and MIN_VALUE / -1 wraps to MIN_VALUE; irem has the sign of the dividend; ishl/ishr/iushr use only the low five bits of the shift count, iushr shifts in zeros; ineg wraps. Division by zero yields "ArithmeticException", an unknown op "VerifyError".

split: open-access