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

N = 1
observations = []
def solve(x):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                swept = True
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count == 0:
                prep = False
        elif ev == 'reset':
            if disturbed:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif prep:
                out.append('prep')
            elif count > 0:
                out.append('occupied')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 62', {'events': ['in', 'in', 'in', 'reset', 'out', 'in', 'reset', 'query']}, ['prep']), ('control 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('control 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('control 79', {'events': ['reset', 'out', 'out', 'query', 'query', 'reset', 'query']}, ['disturbed', 'disturbed', 'prep']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 57', {'events': ['in', 'query', 'in', 'out', 'reset', 'reset', 'in', 'query', 'out', 'query', 'query', 'in', 'in', 'query', 'query']}, ['occupied', 'prep', 'clear', 'clear', 'occupied', 'occupied']), ('control 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied']), ('sampled regression 54', {'events': ['query', 'query', 'in', 'in', 'out', 'in', 'query', 'out', 'query', 'reset', 'in', 'out', 'query', 'out', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'clear', 'disturbed'])]]
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):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                swept = True
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count == 0:
                prep = False
        elif ev == 'reset':
            if count != 0:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif prep:
                out.append('prep')
            elif count > 0:
                out.append('occupied')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 62', {'events': ['in', 'in', 'in', 'reset', 'out', 'in', 'reset', 'query']}, ['prep']), ('control 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('control 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('control 79', {'events': ['reset', 'out', 'out', 'query', 'query', 'reset', 'query']}, ['disturbed', 'disturbed', 'prep']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('boundary: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 57', {'events': ['in', 'query', 'in', 'out', 'reset', 'reset', 'in', 'query', 'out', 'query', 'query', 'in', 'in', 'query', 'query']}, ['occupied', 'prep', 'clear', 'clear', 'occupied', 'occupied']), ('control 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('regression: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied']), ('sampled regression 54', {'events': ['query', 'query', 'in', 'in', 'out', 'in', 'query', 'out', 'query', 'reset', 'in', 'out', 'query', 'out', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'clear', 'disturbed'])]]
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 operator reset of a miscounted or a disturbed section is ignored.

An axle-counter section counts axles in and out. Counting out below zero latches disturbed (count forced to 0). A reset is accepted only when the section is disturbed or the count is non-zero; it zeroes the count and enters preparatory state, which ends only when a sweep train has counted in and the count returns to zero on an out-count. query reports disturbed, prep, occupied (count>0) or clear, in that precedence.

split: open-access


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

N = 1
observations = []
def solve(x):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                prep = False
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count == 0:
                prep = False
        elif ev == 'reset':
            if disturbed or count != 0:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif prep:
                out.append('prep')
            elif count > 0:
                out.append('occupied')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('sampled regression 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied'])]]
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):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                swept = True
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count <= 1:
                prep = False
        elif ev == 'reset':
            if disturbed or count != 0:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif prep:
                out.append('prep')
            elif count > 0:
                out.append('occupied')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('sampled regression 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied'])]]
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:
The preparatory state ends before the sweep train has left the section.

An axle-counter section counts axles in and out. Counting out below zero latches disturbed (count forced to 0). A reset is accepted only when the section is disturbed or the count is non-zero; it zeroes the count and enters preparatory state, which ends only when a sweep train has counted in and the count returns to zero on an out-count. query reports disturbed, prep, occupied (count>0) or clear, in that precedence.

split: open-access


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

N = 1
observations = []
def solve(x):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                swept = True
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count == 0:
                prep = False
        elif ev == 'reset':
            if disturbed or count != 0:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif count > 0:
                out.append('occupied')
            elif prep:
                out.append('prep')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 14', {'events': ['in', 'in', 'reset', 'in', 'query', 'out', 'out', 'reset', 'in', 'in', 'in', 'out', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('sampled regression 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 14', {'events': ['in', 'in', 'reset', 'in', 'query', 'out', 'out', 'reset', 'in', 'in', 'in', 'out', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied'])]]
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):
    count = 0
    disturbed = False
    prep = False
    swept = False
    out = []
    for ev in x['events']:
        if ev == 'in':
            count += 1
            if prep:
                swept = True
        elif ev == 'out':
            count -= 1
            if count < 0:
                disturbed = True
                count = 0
            if prep and swept and count == 0:
                prep = False
        elif ev == 'reset':
            if disturbed or count != 0:
                count = 0
                disturbed = False
                prep = True
                swept = False
        elif ev == 'query':
            if disturbed:
                out.append('disturbed')
            elif prep and count == 0:
                out.append('prep')
            elif count > 0:
                out.append('occupied')
            else:
                out.append('clear')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('sampled regression 9', {'events': ['in', 'query', 'query', 'reset', 'in', 'in', 'in', 'in', 'query', 'reset', 'in', 'query']}, ['occupied', 'occupied', 'prep', 'prep']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('control 1', {'events': ['out', 'in', 'out', 'query', 'out', 'query', 'in', 'out', 'in', 'out', 'query', 'query', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed', 'disturbed']), ('control 4', {'events': ['in', 'out', 'query', 'query', 'query']}, ['clear', 'clear', 'clear']), ('control 7', {'events': ['query', 'out', 'in', 'query', 'out', 'query', 'reset', 'reset', 'in', 'reset', 'query', 'reset', 'query']}, ['clear', 'disturbed', 'disturbed', 'prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 14', {'events': ['in', 'in', 'reset', 'in', 'query', 'out', 'out', 'reset', 'in', 'in', 'in', 'out', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('control 12', {'events': ['query', 'out', 'reset', 'out', 'query']}, ['clear', 'disturbed']), ('control 15', {'events': ['out', 'out', 'in', 'reset', 'query', 'query', 'query']}, ['prep', 'prep', 'prep']), ('sampled regression 18', {'events': ['out', 'query', 'query', 'reset', 'in', 'query', 'query']}, ['disturbed', 'disturbed', 'prep', 'prep'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('sampled regression 2', {'events': ['in', 'in', 'reset', 'reset', 'query', 'in', 'query']}, ['prep', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('boundary: under-count during preparation', {'events': ['in', 'reset', 'out', 'query']}, ['disturbed']), ('control 23', {'events': ['query', 'out', 'query', 'out', 'in', 'in', 'in', 'query', 'out', 'in', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 26', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 29', {'events': ['out', 'in', 'in', 'out', 'out', 'in', 'reset', 'out', 'reset', 'in', 'query', 'in', 'query']}, ['prep', 'prep'])], [('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 39', {'events': ['query', 'query', 'query', 'query', 'query', 'reset', 'out', 'out', 'out', 'reset', 'in', 'in', 'out', 'query']}, ['clear', 'clear', 'clear', 'clear', 'clear', 'prep']), ('boundary: normal passage', {'events': ['in', 'in', 'query', 'out', 'out', 'query']}, ['occupied', 'clear']), ('boundary: under-count latches disturbance', {'events': ['out', 'query', 'in', 'query']}, ['disturbed', 'disturbed']), ('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('control 34', {'events': ['in', 'out', 'in', 'out', 'in', 'in', 'query']}, ['occupied']), ('control 37', {'events': ['reset', 'query', 'out', 'query', 'query', 'out', 'in', 'out', 'in', 'out', 'in', 'query']}, ['clear', 'disturbed', 'disturbed', 'disturbed']), ('control 40', {'events': ['in', 'in', 'query', 'out', 'query']}, ['occupied', 'occupied'])], [('regression: reset of a miscounted section', {'events': ['in', 'in', 'out', 'reset', 'query', 'in', 'in', 'query', 'out', 'out', 'query']}, ['prep', 'prep', 'clear']), ('regression: sweep train partly through', {'events': ['out', 'reset', 'in', 'in', 'out', 'query', 'out', 'query']}, ['prep', 'clear']), ('sampled regression 14', {'events': ['in', 'in', 'reset', 'in', 'query', 'out', 'out', 'reset', 'in', 'in', 'in', 'out', 'in', 'query']}, ['prep', 'prep']), ('boundary: reset of a disturbed section', {'events': ['out', 'reset', 'query', 'in', 'out', 'query']}, ['prep', 'clear']), ('boundary: reset refused on a clear section', {'events': ['reset', 'query', 'in', 'query']}, ['clear', 'occupied']), ('sampled regression 45', {'events': ['out', 'query', 'out', 'in', 'query', 'in', 'in', 'in', 'reset', 'in', 'query']}, ['disturbed', 'disturbed', 'prep']), ('sampled regression 48', {'events': ['out', 'query', 'in', 'out', 'reset', 'in', 'query', 'query', 'query', 'query']}, ['disturbed', 'prep', 'prep', 'prep', 'prep']), ('control 51', {'events': ['reset', 'query', 'in', 'out', 'query', 'in', 'in', 'query', 'query', 'query', 'query']}, ['clear', 'clear', 'occupied', 'occupied', 'occupied', 'occupied'])]]
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 section under preparatory reset is shown as ordinarily occupied while the sweep train passes.

An axle-counter section counts axles in and out. Counting out below zero latches disturbed (count forced to 0). A reset is accepted only when the section is disturbed or the count is non-zero; it zeroes the count and enters preparatory state, which ends only when a sweep train has counted in and the count returns to zero on an out-count. query reports disturbed, prep, occupied (count>0) or clear, in that precedence.

split: open-access


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

N = 1
observations = []
def solve(x):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s is None or s:
            state = 'occ'
            run = 0
        else:
            run += 1
            if state == 'occ' and run * x['period_ms'] > x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ']), ('sampled regression 6', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, True, False, False, None]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'clr', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 21', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, False, False, False, False, True, False, False]}, ['occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 55', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, None, None, False]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'occ']), ('sampled regression 19', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, True, False, False, False, False, False, False, False, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('regression: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 77', {'period_ms': 250, 'pickup_ms': 500, 'samples': [None, True, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr']), ('control 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('regression: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 43', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [True, False, None, None, False, False, True, False, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('sampled regression 3', {'period_ms': 250, 'pickup_ms': 750, 'samples': [True, False, False, False, False, False, False, False, True, True, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 60', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, True, False, False, False, False, None, False, None, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s is None or s:
            state = 'occ'
            run = 0
        else:
            run += 1
            if state == 'occ' and (run - 1) * x['period_ms'] >= x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ']), ('sampled regression 6', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, True, False, False, None]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'clr', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 21', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, False, False, False, False, True, False, False]}, ['occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 55', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, None, None, False]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'occ']), ('sampled regression 19', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, True, False, False, False, False, False, False, False, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('regression: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 77', {'period_ms': 250, 'pickup_ms': 500, 'samples': [None, True, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr']), ('control 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('regression: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 43', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [True, False, None, None, False, False, True, False, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('sampled regression 3', {'period_ms': 250, 'pickup_ms': 750, 'samples': [True, False, False, False, False, False, False, False, True, True, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 60', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, True, False, False, False, False, None, False, None, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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 section stays occupied one sample longer than its pick-up delay.

Samples arrive every period_ms: True is shunted, False unshunted, None a power or receiver failure. The section starts occupied. A shunt or a failure makes it occupied immediately and restarts the pick-up count; it becomes clear once consecutive unshunted samples span at least pickup_ms (count*period_ms >= pickup_ms). Output the state after every sample.

split: open-access


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

N = 1
observations = []
def solve(x):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s is None or s:
            state = 'occ'
        else:
            run += 1
            if state == 'occ' and run * x['period_ms'] >= x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 3', {'period_ms': 250, 'pickup_ms': 750, 'samples': [True, False, False, False, False, False, False, False, True, True, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 14', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, None, False, False, False, True, False, None, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 9', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, False, True, False, None, None, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('boundary: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 32', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, False, None, False, True, False, True, True, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr'])], [('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 44', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 43', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [True, False, None, None, False, False, True, False, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 59', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, True, None, False, True, False, None, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s is None or s:
            if state == 'clr':
                run = 0
            state = 'occ'
        else:
            run += 1
            if state == 'occ' and run * x['period_ms'] >= x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 3', {'period_ms': 250, 'pickup_ms': 750, 'samples': [True, False, False, False, False, False, False, False, True, True, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 14', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, None, False, False, False, True, False, None, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 9', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, False, True, False, None, None, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('boundary: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 32', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, False, None, False, True, False, True, True, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr'])], [('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 44', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 43', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [True, False, None, None, False, False, True, False, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('regression: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 59', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, True, None, False, True, False, None, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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 section clears after a train has bobbed the shunt without enough consecutive clear samples.

Samples arrive every period_ms: True is shunted, False unshunted, None a power or receiver failure. The section starts occupied. A shunt or a failure makes it occupied immediately and restarts the pick-up count; it becomes clear once consecutive unshunted samples span at least pickup_ms (count*period_ms >= pickup_ms). Output the state after every sample.

split: open-access


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

N = 1
observations = []
def solve(x):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s:
            state = 'occ'
            run = 0
        else:
            run += 1
            if state == 'occ' and run * x['period_ms'] >= x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 6', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, True, False, False, None]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'clr', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('boundary: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 16', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [None, False, False, None, None, True, True, False, None, None, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 10', {'period_ms': 100, 'pickup_ms': 500, 'samples': [None, False, None, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 33', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, None, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('boundary: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 32', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, False, None, False, True, False, True, True, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('boundary: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 62', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, True, None, False, False, False, False, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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):
    state = 'occ'
    run = 0
    out = []
    for s in x['samples']:
        if s is not None and s:
            state = 'occ'
            run = 0
        else:
            run += 1
            if state == 'occ' and run * x['period_ms'] >= x['pickup_ms']:
                state = 'clr'
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 6', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False, True, False, False, None]}, ['occ', 'clr', 'clr', 'occ', 'occ', 'clr', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('boundary: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 1', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, True, False, True, False, None, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 4', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, False, False, True, True, False, False, True, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 7', {'period_ms': 100, 'pickup_ms': 500, 'samples': [False, False, True, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 16', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [None, False, False, None, None, True, True, False, None, None, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 10', {'period_ms': 100, 'pickup_ms': 500, 'samples': [None, False, None, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 12', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, None, None, False, True, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 15', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True, None, True, None, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 33', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False, None, False, False, None, False, None, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 18', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, None, False, False, None, False, False, False, False, False, False, False, None, False]}, ['occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('boundary: train arrives on a clear section', {'period_ms': 100, 'pickup_ms': 100, 'samples': [False, True, False]}, ['clr', 'occ', 'clr']), ('control 23', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, None, False, True, False, True, False, False, None]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 26', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, None, False, False, True, None, None, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('control 29', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, True, False, False, False, True, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 32', {'period_ms': 100, 'pickup_ms': 300, 'samples': [None, False, False, None, False, True, False, True, True, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('boundary: pick-up exactly at the delay', {'period_ms': 250, 'pickup_ms': 500, 'samples': [False, False, False]}, ['occ', 'clr', 'clr']), ('boundary: bobbing shunt while occupied', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('control 34', {'period_ms': 250, 'pickup_ms': 300, 'samples': [True, False, False, False, False, False, False, True]}, ['occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ']), ('control 37', {'period_ms': 250, 'pickup_ms': 300, 'samples': [False, True, False, False, False, False, False, False, False, False, True, False, False]}, ['occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr', 'occ', 'occ', 'clr']), ('control 40', {'period_ms': 100, 'pickup_ms': 1000, 'samples': [False, False, None, False, False, False, False, True, None, False, False, None, True]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])], [('regression: receiver failure mid pick-up', {'period_ms': 100, 'pickup_ms': 300, 'samples': [False, False, None, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr']), ('sampled regression 62', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, True, None, False, False, False, False, False, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'clr', 'clr', 'clr', 'clr', 'clr', 'clr']), ('sampled regression 45', {'period_ms': 250, 'pickup_ms': 500, 'samples': [True, False, False, False, True, False, None, False, False, None, True, False]}, ['occ', 'occ', 'clr', 'clr', 'occ', 'occ', 'occ', 'occ', 'clr', 'occ', 'occ', 'occ']), ('regression: receiver failure on a clear section', {'period_ms': 100, 'pickup_ms': 200, 'samples': [False, False, None, False]}, ['occ', 'clr', 'occ', 'occ']), ('boundary: never clears', {'period_ms': 250, 'pickup_ms': 1000, 'samples': [False, False, False]}, ['occ', 'occ', 'occ']), ('control 48', {'period_ms': 250, 'pickup_ms': 750, 'samples': [False, False, True, True]}, ['occ', 'occ', 'occ', 'occ']), ('control 51', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, None, True, False, False, False, True, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ']), ('sampled regression 54', {'period_ms': 100, 'pickup_ms': 750, 'samples': [False, False, None, False, None, False, False, None, False, False, True, False, False, False]}, ['occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ', 'occ'])]]
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 receiver failure sample counts towards clearing the section.

Samples arrive every period_ms: True is shunted, False unshunted, None a power or receiver failure. The section starts occupied. A shunt or a failure makes it occupied immediately and restarts the pick-up count; it becomes clear once consecutive unshunted samples span at least pickup_ms (count*period_ms >= pickup_ms). Output the state after every sample.

split: open-access