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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 9', {'cars': [{'id': 'P2', 'floor': 9, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 23}), ('sampled regression 13', {'cars': [{'id': 'P2', 'floor': 1, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 18, 'load': 0, 'oos': True}, {'id': 'P4', 'floor': 14, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P2'], 'starts': {'P4': 0, 'P2': 36}, 'selected': 'P4', 'done_s': 46}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('control 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 24', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 10, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P4', 'P3', 'P1'], 'starts': {'P4': 0, 'P3': 15, 'P1': 40}, 'selected': 'P4', 'done_s': 73}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('control 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('control 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 46', {'cars': [{'id': 'P1', 'floor': 7, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 5, 'load': 75, 'oos': True}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P4', 'P2'], 'starts': {'P1': 0, 'P4': 26, 'P2': 73}, 'selected': 'P1', 'done_s': 93}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86}), ('control 43', {'cars': [{'id': 'P2', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 16, 'load': 75, 'oos': True}, {'id': 'P3', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 13, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P2'], 'starts': {'P3': 0, 'P2': 16}, 'selected': 'P2', 'done_s': 44})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 47', {'cars': [{'id': 'P1', 'floor': 11, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 4, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P3', 'P1'], 'starts': {'P3': 0, 'P1': 17}, 'selected': 'P3', 'done_s': 55}), ('sampled regression 62', {'cars': [{'id': 'P3', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 11, 'P4': 25}, 'selected': 'P1', 'done_s': 51}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('control 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
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):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[-1]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 9', {'cars': [{'id': 'P2', 'floor': 9, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 23}), ('sampled regression 13', {'cars': [{'id': 'P2', 'floor': 1, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 18, 'load': 0, 'oos': True}, {'id': 'P4', 'floor': 14, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P2'], 'starts': {'P4': 0, 'P2': 36}, 'selected': 'P4', 'done_s': 46}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('control 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 24', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 10, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P4', 'P3', 'P1'], 'starts': {'P4': 0, 'P3': 15, 'P1': 40}, 'selected': 'P4', 'done_s': 73}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('control 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('control 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 46', {'cars': [{'id': 'P1', 'floor': 7, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 5, 'load': 75, 'oos': True}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P4', 'P2'], 'starts': {'P1': 0, 'P4': 26, 'P2': 73}, 'selected': 'P1', 'done_s': 93}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86}), ('control 43', {'cars': [{'id': 'P2', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 16, 'load': 75, 'oos': True}, {'id': 'P3', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 13, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P2'], 'starts': {'P3': 0, 'P2': 16}, 'selected': 'P2', 'done_s': 44})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 47', {'cars': [{'id': 'P1', 'floor': 11, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 4, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P3', 'P1'], 'starts': {'P3': 0, 'P1': 17}, 'selected': 'P3', 'done_s': 55}), ('sampled regression 62', {'cars': [{'id': 'P3', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 11, 'P4': 25}, 'selected': 'P1', 'done_s': 51}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('control 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
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 selected car is unavailable or not the first returned car.

On emergency power in-service cars (not oos) return to the lobby one at a time: occupied cars (load > 0) first, then by lower floor, then id. Each return takes floor*per_floor_s + door_s; starts are cumulative. Afterwards the preselected car runs if it is in service, otherwise the first car of the return order (None if no car).

split: open-access


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

N = 1
observations = []
def solve(x):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = (lo <= hour < hi) if lo <= hi else (hour >= lo or hour < hi)
        if v not in restricted or not in_window:
            out.append('accepted')
        elif card is not None and t - card_t >= 0 and v in cards.get(card, []):
            out.append('accepted')
            card = None
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('control 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 62', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [65, 'call', 7], [3665, 'call', 12], [3675, 'card', 'K1'], [7275, 'card', 'K1']]}, ['read', 'denied', 'accepted', 'read', 'read']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 14', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85809, 'call', 2], [85819, 'card', 'K2'], [85829, 'card', 'K1'], [85838, 'call', 12], [85849, 'call', 7], [85858, 'call', 9]]}, ['accepted', 'read', 'read', 'accepted', 'denied', 'denied']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 68', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[25205, 'card', 'K1'], [28805, 'call', 5], [32405, 'call', 12], [32414, 'card', 'K2'], [32419, 'call', 2]]}, ['read', 'denied', 'accepted', 'read', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('control 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 21', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[25209, 'card', 'K1'], [28809, 'call', 12], [28818, 'card', 'K1'], [28878, 'call', 7], [28879, 'call', 12]]}, ['read', 'accepted', 'read', 'denied', 'accepted']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = (lo <= hour < hi) if lo <= hi else (hour >= lo or hour < hi)
        if v not in restricted or not in_window:
            out.append('accepted')
        elif card is not None and t - card_t < 10 and v in cards.get(card, []):
            out.append('accepted')
            card = None
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('control 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 62', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [65, 'call', 7], [3665, 'call', 12], [3675, 'card', 'K1'], [7275, 'card', 'K1']]}, ['read', 'denied', 'accepted', 'read', 'read']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 14', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85809, 'call', 2], [85819, 'card', 'K2'], [85829, 'card', 'K1'], [85838, 'call', 12], [85849, 'call', 7], [85858, 'call', 9]]}, ['accepted', 'read', 'read', 'accepted', 'denied', 'denied']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 68', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[25205, 'card', 'K1'], [28805, 'call', 5], [32405, 'call', 12], [32414, 'card', 'K2'], [32419, 'call', 2]]}, ['read', 'denied', 'accepted', 'read', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('control 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('sampled regression 21', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[25209, 'card', 'K1'], [28809, 'call', 12], [28818, 'card', 'K1'], [28878, 'call', 7], [28879, 'call', 12]]}, ['read', 'accepted', 'read', 'denied', 'accepted']), ('control 35', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 12], [20, 'call', 5], [25, 'card', 'K2'], [26, 'call', 5], [35, 'call', 9], [45, 'call', 7]]}, ['accepted', 'denied', 'read', 'denied', 'accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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 card read long ago still authorises secured calls, or a call at exactly 10 s is refused.

Restricted floors are secured during [lo, hi) hours of day (hour = t//3600 mod 24; when lo > hi the window wraps midnight). A car call to a secured floor is accepted only within 10 s of a card read whose card allows that floor; the credential is consumed by the call it authorises. Unsecured calls are accepted without affecting the credential. Log read, accepted or denied.

split: open-access


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

N = 1
observations = []
def solve(x):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = lo <= hour < hi
        if v not in restricted or not in_window:
            out.append('accepted')
        elif card is not None and t - card_t <= 10 and v in cards.get(card, []):
            out.append('accepted')
            card = None
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 8', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 5], [3610, 'call', 12], [3670, 'call', 5], [7270, 'card', 'K9'], [7279, 'call', 12], [7339, 'card', 'K2'], [7340, 'card', 'K2']]}, ['denied', 'accepted', 'denied', 'read', 'accepted', 'read', 'read']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('sampled regression 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 62', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [65, 'call', 7], [3665, 'call', 12], [3675, 'card', 'K1'], [7275, 'card', 'K1']]}, ['read', 'denied', 'accepted', 'read', 'read']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('control 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 24', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[9, 'call', 9], [14, 'card', 'K1'], [15, 'card', 'K9'], [25, 'card', 'K9']]}, ['denied', 'read', 'read', 'read']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('sampled regression 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 53', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72001, 'call', 2], [72061, 'call', 7]]}, ['accepted', 'denied']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = (lo <= hour <= hi) if lo <= hi else (hour >= lo or hour <= hi)
        if v not in restricted or not in_window:
            out.append('accepted')
        elif card is not None and t - card_t <= 10 and v in cards.get(card, []):
            out.append('accepted')
            card = None
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 8', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 5], [3610, 'call', 12], [3670, 'call', 5], [7270, 'card', 'K9'], [7279, 'call', 12], [7339, 'card', 'K2'], [7340, 'card', 'K2']]}, ['denied', 'accepted', 'denied', 'read', 'accepted', 'read', 'read']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('sampled regression 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('sampled regression 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 62', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [65, 'call', 7], [3665, 'call', 12], [3675, 'card', 'K1'], [7275, 'card', 'K1']]}, ['read', 'denied', 'accepted', 'read', 'read']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('control 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 24', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[9, 'call', 9], [14, 'card', 'K1'], [15, 'card', 'K9'], [25, 'card', 'K9']]}, ['denied', 'read', 'read', 'read']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('sampled regression 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('sampled regression 53', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72001, 'call', 2], [72061, 'call', 7]]}, ['accepted', 'denied']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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:
Overnight security windows never apply, or the closing hour is still secured.

Restricted floors are secured during [lo, hi) hours of day (hour = t//3600 mod 24; when lo > hi the window wraps midnight). A car call to a secured floor is accepted only within 10 s of a card read whose card allows that floor; the credential is consumed by the call it authorises. Unsecured calls are accepted without affecting the credential. Log read, accepted or denied.

split: open-access


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

N = 1
observations = []
def solve(x):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = (lo <= hour < hi) if lo <= hi else (hour >= lo or hour < hi)
        if v not in restricted or not in_window:
            out.append('accepted')
        elif card is not None and t - card_t <= 10 and v in cards.get(card, []):
            out.append('accepted')
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('control 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('control 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('control 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('control 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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):
    cards = x['cards']
    restricted = set(x['restricted'])
    lo, hi = x['secure_hours']
    card = None
    card_t = None
    out = []
    for t, kind, v in x['events']:
        if kind == 'card':
            card = v
            card_t = t
            out.append('read')
            continue
        hour = (t // 3600) % 24
        in_window = (lo <= hour < hi) if lo <= hi else (hour >= lo or hour < hi)
        if v not in restricted or not in_window:
            out.append('accepted')
            card = None
        elif card is not None and t - card_t <= 10 and v in cards.get(card, []):
            out.append('accepted')
        else:
            out.append('denied')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('control 1', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[9, 'card', 'K1'], [14, 'card', 'K1'], [23, 'call', 2]]}, ['read', 'read', 'accepted']), ('control 4', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[10, 'call', 7], [3610, 'call', 2], [3615, 'card', 'K9'], [3625, 'call', 2]]}, ['denied', 'accepted', 'read', 'accepted']), ('control 7', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85811, 'call', 7], [85812, 'card', 'K1'], [85821, 'call', 5], [85831, 'card', 'K2']]}, ['read', 'accepted', 'read', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('control 12', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[5, 'card', 'K1'], [3605, 'call', 12], [3615, 'call', 9], [3616, 'call', 7]]}, ['read', 'accepted', 'denied', 'denied']), ('control 15', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[89400, 'call', 9], [93000, 'call', 7]]}, ['denied', 'denied']), ('control 18', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85810, 'card', 'K1'], [85870, 'call', 2], [85880, 'call', 5], [85889, 'call', 12], [85900, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('control 23', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[72010, 'call', 9], [75610, 'card', 'K1'], [75615, 'call', 12], [75675, 'call', 5], [75686, 'call', 9], [75696, 'call', 5], [75705, 'call', 9]]}, ['denied', 'read', 'accepted', 'denied', 'denied', 'denied', 'denied']), ('control 26', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[85810, 'call', 2], [85819, 'card', 'K1'], [85820, 'card', 'K9'], [85825, 'call', 2]]}, ['accepted', 'read', 'read', 'accepted']), ('control 29', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[85801, 'card', 'K2'], [85812, 'call', 12], [85823, 'call', 9], [85832, 'call', 12], [85892, 'card', 'K2']]}, ['read', 'accepted', 'accepted', 'accepted', 'read'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: card without the floor', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K2'], [101, 'call', 5]]}, ['read', 'denied']), ('boundary: call ten seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [110, 'call', 5]]}, ['read', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('control 34', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'call', 2], [3611, 'card', 'K2']]}, ['accepted', 'read']), ('control 37', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[3600, 'card', 'K9'], [3609, 'card', 'K1'], [3619, 'card', 'K1'], [7219, 'card', 'K1'], [7224, 'card', 'K1']]}, ['read', 'read', 'read', 'read', 'read']), ('control 40', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[72011, 'call', 12], [72022, 'call', 9]]}, ['accepted', 'denied'])], [('regression: credential used twice', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [102, 'call', 5], [104, 'call', 7]]}, ['read', 'accepted', 'denied']), ('boundary: unsecured call between read and secured call', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [101, 'call', 2], [103, 'call', 7]]}, ['read', 'accepted', 'accepted']), ('boundary: call eleven seconds after the read', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [0, 24], 'events': [[100, 'card', 'K1'], [111, 'call', 5]]}, ['read', 'denied']), ('boundary: end of the secured window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[64800, 'call', 5], [64799, 'call', 5]]}, ['accepted', 'denied']), ('boundary: overnight window', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[82800, 'call', 9], [10800, 'call', 9], [43200, 'call', 9]]}, ['denied', 'denied', 'accepted']), ('control 45', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'call', 2], [72020, 'card', 'K9'], [72021, 'call', 2]]}, ['accepted', 'read', 'accepted']), ('control 48', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [20, 6], 'events': [[25260, 'call', 5], [25265, 'card', 'K2']]}, ['accepted', 'read']), ('control 51', {'restricted': [5, 7, 9], 'cards': {'K1': [5, 7], 'K2': [9]}, 'secure_hours': [8, 18], 'events': [[72011, 'card', 'K9'], [75611, 'call', 5], [75620, 'call', 12], [75629, 'card', 'K1']]}, ['read', 'accepted', 'accepted', 'read'])]]
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:
One card read authorises several secured floors, or an unsecured call wastes the credential.

Restricted floors are secured during [lo, hi) hours of day (hour = t//3600 mod 24; when lo > hi the window wraps midnight). A car call to a secured floor is accepted only within 10 s of a card read whose card allows that floor; the credential is consumed by the call it authorises. Unsecured calls are accepted without affecting the credential. Log read, accepted or denied.

split: open-access