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

N = 1
observations = []
def solve(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] > k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 6', {'isolate_after': 2, 'cycles': [[None, False, True], [False, True, False], [True, False, False], [False, True, False], [False, False, False], [False, False, False], [None, False, True]]}, {'votes': [True, False, True, False, False, False, True], 'isolated': [1]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 39', {'isolate_after': 2, 'cycles': [[True, False, True], [False, True, None], [True, False, False], [True, True, False], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [True, True, False, True, False, True, True], 'isolated': [0]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k and not any(iso):
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 6', {'isolate_after': 2, 'cycles': [[None, False, True], [False, True, False], [True, False, False], [False, True, False], [False, False, False], [False, False, False], [None, False, True]]}, {'votes': [True, False, True, False, False, False, True], 'isolated': [1]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 39', {'isolate_after': 2, 'cycles': [[True, False, True], [False, True, None], [True, False, False], [True, True, False], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [True, True, False, True, False, True, True], 'isolated': [0]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('regression: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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 persistently dissenting channel keeps voting one cycle too long or is never isolated.

Three channels report occupancy (True/False) or None when failed. A channel isolated earlier counts as None. With fewer than two healthy channels the vote is occupied. Otherwise the vote is occupied when occupied reports are at least as many as clear ones (ties are occupied). A healthy channel that disagrees with the vote increments its discrepancy count, otherwise (agreeing or None) the count resets; a channel is isolated for good when its count reaches isolate_after. Return all votes and isolated channel indices.

split: open-access


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

N = 1
observations = []
def solve(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = list(cyc)
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 6', {'isolate_after': 2, 'cycles': [[None, False, True], [False, True, False], [True, False, False], [False, True, False], [False, False, False], [False, False, False], [None, False, True]]}, {'votes': [True, False, True, False, False, False, True], 'isolated': [1]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 56', {'isolate_after': 2, 'cycles': [[False, True, None], [False, True, None], [False, False, False], [True, False, False], [False, False, True]]}, {'votes': [True, True, False, False, True], 'isolated': [0]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] and cyc[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 6', {'isolate_after': 2, 'cycles': [[None, False, True], [False, True, False], [True, False, False], [False, True, False], [False, False, False], [False, False, False], [None, False, True]]}, {'votes': [True, False, True, False, False, False, True], 'isolated': [1]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 56', {'isolate_after': 2, 'cycles': [[False, True, None], [False, True, None], [False, False, False], [True, False, False], [False, False, True]]}, {'votes': [True, True, False, False, True], 'isolated': [0]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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 isolated channel continues to influence the vote.

Three channels report occupancy (True/False) or None when failed. A channel isolated earlier counts as None. With fewer than two healthy channels the vote is occupied. Otherwise the vote is occupied when occupied reports are at least as many as clear ones (ties are occupied). A healthy channel that disagrees with the vote increments its discrepancy count, otherwise (agreeing or None) the count resets; a channel is isolated for good when its count reaches isolate_after. Return all votes and isolated channel indices.

split: open-access


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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i]
            b[i] = None
            if i == n - 1:
                exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 3', {'berths': 3, 'events': [['cancel', 0], ['step', 1], ['step', 2], ['interpose', 0, '9Z10'], ['cancel', 1], ['interpose', 2, '9Z10']]}, {'berths': ['9Z10', None, '9Z10'], 'clashes': [], 'exited': ['????']}), ('sampled regression 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('sampled regression 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']}), ('sampled regression 11', {'berths': 5, 'events': [['step', 1], ['step', 3], ['interpose', 0, '5X99'], ['step', 3], ['interpose', 1, '5X99'], ['step', 1], ['step', 2], ['cancel', 2], ['step', 4]]}, {'berths': ['5X99', None, None, '5X99', None], 'clashes': [4, 2], 'exited': ['????']}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []})], [('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 17', {'berths': 4, 'events': [['step', 3], ['step', 2], ['step', 0], ['interpose', 1, '5X99'], ['step', 1], ['interpose', 2, '9Z10'], ['cancel', 2], ['interpose', 2, '5X99'], ['step', 0]]}, {'berths': [None, '????', '5X99', '????'], 'clashes': [], 'exited': ['????']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('boundary: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []})], [('regression: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 24', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 3]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']})], [('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']}), ('sampled regression 27', {'berths': 5, 'events': [['step', 2], ['step', 4], ['step', 2], ['step', 2], ['step', 2], ['step', 1], ['cancel', 2], ['step', 4]]}, {'berths': [None, None, None, '????', None], 'clashes': [3, 3, 3], 'exited': ['????', '????']}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('sampled regression 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
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(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else b[i + 1] if i + 1 < n else '????'
            b[i] = None
            if i == n - 1:
                exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 3', {'berths': 3, 'events': [['cancel', 0], ['step', 1], ['step', 2], ['interpose', 0, '9Z10'], ['cancel', 1], ['interpose', 2, '9Z10']]}, {'berths': ['9Z10', None, '9Z10'], 'clashes': [], 'exited': ['????']}), ('sampled regression 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('sampled regression 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']}), ('sampled regression 11', {'berths': 5, 'events': [['step', 1], ['step', 3], ['interpose', 0, '5X99'], ['step', 3], ['interpose', 1, '5X99'], ['step', 1], ['step', 2], ['cancel', 2], ['step', 4]]}, {'berths': ['5X99', None, None, '5X99', None], 'clashes': [4, 2], 'exited': ['????']}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []})], [('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 17', {'berths': 4, 'events': [['step', 3], ['step', 2], ['step', 0], ['interpose', 1, '5X99'], ['step', 1], ['interpose', 2, '9Z10'], ['cancel', 2], ['interpose', 2, '5X99'], ['step', 0]]}, {'berths': [None, '????', '5X99', '????'], 'clashes': [], 'exited': ['????']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('boundary: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []})], [('regression: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 24', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 3]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']})], [('regression: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']}), ('sampled regression 27', {'berths': 5, 'events': [['step', 2], ['step', 4], ['step', 2], ['step', 2], ['step', 2], ['step', 1], ['cancel', 2], ['step', 4]]}, {'berths': [None, None, None, '????', None], 'clashes': [3, 3, 3], 'exited': ['????', '????']}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('sampled regression 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
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 train stepping from an unlabelled berth loses its description entirely.

A train describer has berths 0..n-1. interpose writes a headcode, cancel blanks a berth. step i moves the description from berth i to i+1 (or out of the area from the last berth, recorded in exited); stepping an empty berth carries the unknown description ????. Stepping onto a filled berth records a clash at the destination and the stepped description overwrites it. The source berth is always blanked.

split: open-access


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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            if i == n - 1:
                exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('control 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 38', {'berths': 4, 'events': [['step', 2], ['step', 1], ['step', 2], ['cancel', 1]]}, {'berths': [None, None, None, '????'], 'clashes': [3], 'exited': []}), ('sampled regression 54', {'berths': 3, 'events': [['step', 2], ['step', 2], ['step', 2], ['step', 1], ['interpose', 2, '5X99'], ['step', 0], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [2], 'exited': ['????', '????', '????', '????']}), ('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']})], [('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 50', {'berths': 4, 'events': [['step', 2], ['interpose', 0, '9Z10'], ['step', 0], ['interpose', 1, '2B17'], ['cancel', 1], ['step', 0], ['step', 3]]}, {'berths': [None, '????', None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 76', {'berths': 5, 'events': [['interpose', 0, '9Z10'], ['step', 4], ['step', 3], ['step', 4], ['interpose', 0, '2B17'], ['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 1]]}, {'berths': ['1A01', None, '1A01', None, None], 'clashes': [], 'exited': ['????', '????']}), ('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('control 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('control 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
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(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            if i == n - 1:
                exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
                b[i] = None
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('control 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 38', {'berths': 4, 'events': [['step', 2], ['step', 1], ['step', 2], ['cancel', 1]]}, {'berths': [None, None, None, '????'], 'clashes': [3], 'exited': []}), ('sampled regression 54', {'berths': 3, 'events': [['step', 2], ['step', 2], ['step', 2], ['step', 1], ['interpose', 2, '5X99'], ['step', 0], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [2], 'exited': ['????', '????', '????', '????']}), ('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']})], [('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('sampled regression 50', {'berths': 4, 'events': [['step', 2], ['interpose', 0, '9Z10'], ['step', 0], ['interpose', 1, '2B17'], ['cancel', 1], ['step', 0], ['step', 3]]}, {'berths': [None, '????', None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 76', {'berths': 5, 'events': [['interpose', 0, '9Z10'], ['step', 4], ['step', 3], ['step', 4], ['interpose', 0, '2B17'], ['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 1]]}, {'berths': ['1A01', None, '1A01', None, None], 'clashes': [], 'exited': ['????', '????']}), ('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('control 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('control 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
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 description stays behind in the berth the train has left.

A train describer has berths 0..n-1. interpose writes a headcode, cancel blanks a berth. step i moves the description from berth i to i+1 (or out of the area from the last berth, recorded in exited); stepping an empty berth carries the unknown description ????. Stepping onto a filled berth records a clash at the destination and the stepped description overwrites it. The source berth is always blanked.

split: open-access