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

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return [v for v, s in live if s == top][-1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[-1] if '1' in vals else (vals[0] if len(vals) == 1 else 'x')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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:
Two strong drivers fighting yield the value of whichever is listed last instead of x.

Input [drivers, keeper]: drivers are [value, strength] with value in 0/1/x/z and strength weak < pull < strong. 'z' drivers are ignored. With no active driver the net is the keeper value, or 'z' when keeper is None. Otherwise only drivers at the highest present strength matter: a single agreed value wins, any disagreement (including x) gives 'x'.

split: open-access


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

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = list(drivers)
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z' or len(drivers) == 1]
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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 strong driver in high impedance beats an active weak driver and the net reads 'z' or 'x'.

Input [drivers, keeper]: drivers are [value, strength] with value in 0/1/x/z and strength weak < pull < strong. 'z' drivers are ignored. With no active driver the net is the keeper value, or 'z' when keeper is None. Otherwise only drivers at the highest present strength matter: a single agreed value wins, any disagreement (including x) gives 'x'.

split: open-access


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

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None and not drivers else 'z'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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 kept bus reads 'z' after its drivers tri-state.

Input [drivers, keeper]: drivers are [value, strength] with value in 0/1/x/z and strength weak < pull < strong. 'z' drivers are ignored. With no active driver the net is the keeper value, or 'z' when keeper is None. Otherwise only drivers at the highest present strength matter: a single agreed value wins, any disagreement (including x) gives 'x'.

split: open-access


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

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    if any(v == 'x' for v, s in live):
        return 'x'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    if any(v == 'x' and s != 'weak' for v, s in live):
        return 'x'
    top = max(live, key=lambda d: rank[d[1]])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[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:
An unknown value from a weaker driver turns a strongly driven net into x.

Input [drivers, keeper]: drivers are [value, strength] with value in 0/1/x/z and strength weak < pull < strong. 'z' drivers are ignored. With no active driver the net is the keeper value, or 'z' when keeper is None. Otherwise only drivers at the highest present strength matter: a single agreed value wins, any disagreement (including x) gives 'x'.

split: open-access


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

N = 1
observations = []
def solve(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, cur)
            if kind == 'b':
                cur[lhs] = v
            else:
                cur[lhs] = v
        for lhs, v in nba:
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, cur)
            if kind == 'b':
                cur[lhs] = v
            else:
                regs[lhs] = v
        for lhs, v in nba:
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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 register swap written with non-blocking assignments copies one value into both registers.

Input [regs, stmts, cycles]. Each clock step executes stmts [kind, lhs, op, a, b] in order (ops copy/inv/and/xor on 0/1). Blocking ('b') statements update the working state immediately; non-blocking ('nb') statements evaluate their right side at the statement against the working state and queue the update. After all statements, queued updates apply in statement order (last write wins). Every variable, blocking or not, keeps its value into the next step. Return per-step values sorted by variable name.

split: open-access


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

N = 1
observations = []
def solve(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, cur)
            if kind == 'b':
                cur[lhs] = v
            else:
                nba.append((lhs, v))
        for lhs, v in reversed(nba):
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, cur)
            if kind == 'b':
                cur[lhs] = v
            else:
                nba.append((lhs, v))
        for lhs, v in sorted(nba):
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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:
With two non-blocking writes to one register, the earlier write sticks.

Input [regs, stmts, cycles]. Each clock step executes stmts [kind, lhs, op, a, b] in order (ops copy/inv/and/xor on 0/1). Blocking ('b') statements update the working state immediately; non-blocking ('nb') statements evaluate their right side at the statement against the working state and queue the update. After all statements, queued updates apply in statement order (last write wins). Every variable, blocking or not, keeps its value into the next step. Return per-step values sorted by variable name.

split: open-access


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

N = 1
observations = []
def solve(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, regs)
            if kind == 'b':
                cur[lhs] = v
            else:
                nba.append((lhs, v))
        for lhs, v in nba:
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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(*args):
    regs, stmts, cycles = args
    regs = dict(regs)
    hist = []
    def ev(op, a, b, env):
        if op == 'copy': return env[a]
        if op == 'inv': return 1 - env[a]
        if op == 'and': return env[a] & env[b]
        return env[a] ^ env[b]
    for _ in range(cycles):
        cur = dict(regs)
        nba = []
        for kind, lhs, op, a, b in stmts:
            v = ev(op, a, b, cur if kind == 'nb' else regs)
            if kind == 'b':
                cur[lhs] = v
            else:
                nba.append((lhs, v))
        for lhs, v in nba:
            cur[lhs] = v
        regs = cur
        hist.append([regs[k] for k in sorted(regs)])
    return hist
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 1], [[0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 2], [[0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 2], [[0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 3], [[0, 1, 0], [1, 0, 1], [1, 1, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 1], [[0, 1, 1, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 2], [[0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 3], [[0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 4], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 2], [[0, 1, 1, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 3], [[0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 4], [[0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 5], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 3], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 4], [[0, 1], [1, 0], [0, 1], [1, 0]]), ('blocking chain inside one step', [{'a': 0, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[1, 1, 1], [0, 0, 0]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 5], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 6], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 4], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])], [('non-blocking swap', [{'a': 1, 'b': 0}, [['nb', 'a', 'copy', 'b', None], ['nb', 'b', 'copy', 'a', None]], 5], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1]]), ('blocking chain inside one step', [{'a': 1, 't': 0, 'u': 0}, [['b', 't', 'inv', 'a', None], ['b', 'u', 'copy', 't', None], ['nb', 'a', 'copy', 'u', None]], 2], [[0, 0, 0], [1, 1, 1]]), ('later non-blocking write wins', [{'a': 1, 'c': 0}, [['nb', 'c', 'copy', 'a', None], ['nb', 'c', 'inv', 'a', None], ['nb', 'a', 'inv', 'a', None]], 6], [[0, 0], [1, 1], [0, 0], [1, 1], [0, 0], [1, 1]]), ('blocking temp persists across cycles', [{'t': 0, 'c': 0}, [['nb', 'c', 'copy', 't', None], ['b', 't', 'inv', 't', None]], 6], [[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]), ('shift register with non-blocking', [{'s0': 1, 's1': 0, 's2': 0}, [['nb', 's1', 'copy', 's0', None], ['nb', 's2', 'copy', 's1', None], ['nb', 's0', 'xor', 's2', 's1']], 7], [[0, 1, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], [0, 1, 1], [0, 0, 1], [1, 0, 0]]), ('non-blocking reads blocking result', [{'a': 1, 'b': 1, 'y': 0, 'm': 0}, [['b', 'm', 'and', 'a', 'b'], ['nb', 'y', 'xor', 'm', 'y'], ['nb', 'a', 'inv', 'b', None]], 5], [[0, 1, 1, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 0, 1]])]]
for label, args, expected in fixtures[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 value computed by a blocking statement is not visible to the next statement in the same step.

Input [regs, stmts, cycles]. Each clock step executes stmts [kind, lhs, op, a, b] in order (ops copy/inv/and/xor on 0/1). Blocking ('b') statements update the working state immediately; non-blocking ('nb') statements evaluate their right side at the statement against the working state and queue the update. After all statements, queued updates apply in statement order (last write wins). Every variable, blocking or not, keeps its value into the next step. Return per-step values sorted by variable name.

split: open-access