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

N = 1
observations = []
def solve(x):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse'] // 1000
        else:
            pos = table[v] * 1000
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('sampled regression 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 6', {'floor_mm': [0, 3000, 6000, 9000, 12500, 16000, 19000, 22500, 26700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 2], ['pulses', 3000], ['pulses', 4200], ['magnet', 2], ['pulses', 5000], ['pulses', 2999], ['pulses', 3500]]}, [2, 3, None, 2, None, None, None]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('sampled regression 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('sampled regression 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('sampled regression 13', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400, 20900, 25100], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 5000], ['pulses', 3499], ['pulses', 4200], ['pulses', 5000]]}, [None, None, None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('sampled regression 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('sampled regression 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 20', {'floor_mm': [0, 3500, 7000, 11200, 14700, 17700], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3499], ['pulses', 2999], ['pulses', 1000], ['pulses', 3500]]}, [1, None, None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('regression: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('sampled regression 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('sampled regression 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('sampled regression 28', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17200, 20700, 24900, 28400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 4200], ['pulses', 3000], ['pulses', 3500]]}, [0, 1, 2, 3]), ('sampled regression 17', {'floor_mm': [0, 3500, 7700, 11200, 14700, 17700], 'start_mm': 20, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000], ['pulses', 3499], ['pulses', 2999], ['magnet', 2], ['pulses', 4200]]}, [1, None, None, None, 2, None]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('sampled regression 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('sampled regression 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v // 1000 * x['um_per_pulse']
        else:
            pos = table[v] * 1000
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('sampled regression 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 6', {'floor_mm': [0, 3000, 6000, 9000, 12500, 16000, 19000, 22500, 26700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 2], ['pulses', 3000], ['pulses', 4200], ['magnet', 2], ['pulses', 5000], ['pulses', 2999], ['pulses', 3500]]}, [2, 3, None, 2, None, None, None]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('sampled regression 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('sampled regression 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('sampled regression 13', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400, 20900, 25100], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 5000], ['pulses', 3499], ['pulses', 4200], ['pulses', 5000]]}, [None, None, None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('sampled regression 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('sampled regression 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 20', {'floor_mm': [0, 3500, 7000, 11200, 14700, 17700], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3499], ['pulses', 2999], ['pulses', 1000], ['pulses', 3500]]}, [1, None, None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('regression: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('sampled regression 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('sampled regression 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('sampled regression 28', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17200, 20700, 24900, 28400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 4200], ['pulses', 3000], ['pulses', 3500]]}, [0, 1, 2, 3]), ('sampled regression 17', {'floor_mm': [0, 3500, 7700, 11200, 14700, 17700], 'start_mm': 20, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000], ['pulses', 3499], ['pulses', 2999], ['magnet', 2], ['pulses', 4200]]}, [1, None, None, None, 2, None]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('sampled regression 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('sampled regression 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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 car position drifts or barely moves with encoder pulses.

Car position is tracked in micrometres: start_mm*1000, pulses add count*um_per_pulse, a door-zone magnet at floor k resets the position to floor_mm[k]*1000. After every event the position in mm is floor(um/1000); the car is at the nearest floor (ties to the lower index) if within zone_mm inclusive, otherwise None (between floors).

split: open-access


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

N = 1
observations = []
def solve(x):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos += table[v] * 1000
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 5', {'floor_mm': [0, 4200, 7700, 10700, 14200, 18400, 21400], 'start_mm': 0, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['pulses', 1000], ['magnet', 3], ['pulses', 4200], ['pulses', 1000], ['pulses', 2999], ['magnet', 2], ['pulses', 100]]}, [None, 3, None, None, None, 2, None]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3]), ('sampled regression 10', {'floor_mm': [0, 3000, 6000, 9500, 13700], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['magnet', 2], ['pulses', 4200], ['pulses', 3500], ['pulses', 100], ['pulses', 5000], ['pulses', 3000], ['pulses', 4200]]}, [2, None, 4, None, None, None, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 14', {'floor_mm': [0, 3000, 6500, 9500, 12500, 16000, 19500, 23700], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 2999], ['magnet', 1], ['pulses', 3000]]}, [1, 1, None]), ('sampled regression 8', {'floor_mm': [0, 4200, 8400, 12600, 16100, 19600, 23800], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 2], ['pulses', 3500], ['magnet', 5], ['magnet', 0], ['pulses', 3500]]}, [2, None, 5, 0, None]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 31', {'floor_mm': [0, 4200, 8400, 11400, 14400, 17900, 22100, 26300], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3499], ['magnet', 1], ['magnet', 2], ['magnet', 1], ['pulses', 3000], ['pulses', 4200]]}, [None, 1, 2, 1, None, 3]), ('sampled regression 14', {'floor_mm': [0, 3000, 6500, 9500, 12500, 16000, 19500, 23700], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 2999], ['magnet', 1], ['pulses', 3000]]}, [1, 1, None]), ('boundary: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('sampled regression 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('sampled regression 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 43', {'floor_mm': [0, 3500, 7000, 11200, 14200], 'start_mm': 0, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 1], ['pulses', 2999]]}, [1, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 50', {'floor_mm': [0, 3000, 7200, 11400, 14900, 18400, 22600], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 100], ['pulses', 100], ['magnet', 3], ['pulses', 3499], ['pulses', 1000]]}, [None, None, 3, 4, None]), ('sampled regression 36', {'floor_mm': [0, 3500, 7000, 10500, 14700, 18200], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 4], ['magnet', 3], ['pulses', 2999], ['magnet', 2], ['pulses', 3499], ['pulses', 5000]]}, [4, 3, None, 2, None, None]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('sampled regression 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('sampled regression 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos = table[v]
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 5', {'floor_mm': [0, 4200, 7700, 10700, 14200, 18400, 21400], 'start_mm': 0, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['pulses', 1000], ['magnet', 3], ['pulses', 4200], ['pulses', 1000], ['pulses', 2999], ['magnet', 2], ['pulses', 100]]}, [None, 3, None, None, None, 2, None]), ('sampled regression 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('sampled regression 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3]), ('sampled regression 10', {'floor_mm': [0, 3000, 6000, 9500, 13700], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['magnet', 2], ['pulses', 4200], ['pulses', 3500], ['pulses', 100], ['pulses', 5000], ['pulses', 3000], ['pulses', 4200]]}, [2, None, 4, None, None, None, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 14', {'floor_mm': [0, 3000, 6500, 9500, 12500, 16000, 19500, 23700], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 2999], ['magnet', 1], ['pulses', 3000]]}, [1, 1, None]), ('sampled regression 8', {'floor_mm': [0, 4200, 8400, 12600, 16100, 19600, 23800], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 2], ['pulses', 3500], ['magnet', 5], ['magnet', 0], ['pulses', 3500]]}, [2, None, 5, 0, None]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 31', {'floor_mm': [0, 4200, 8400, 11400, 14400, 17900, 22100, 26300], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3499], ['magnet', 1], ['magnet', 2], ['magnet', 1], ['pulses', 3000], ['pulses', 4200]]}, [None, 1, 2, 1, None, 3]), ('sampled regression 14', {'floor_mm': [0, 3000, 6500, 9500, 12500, 16000, 19500, 23700], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 2999], ['magnet', 1], ['pulses', 3000]]}, [1, 1, None]), ('boundary: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4]), ('sampled regression 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('sampled regression 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('sampled regression 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 43', {'floor_mm': [0, 3500, 7000, 11200, 14200], 'start_mm': 0, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 1], ['pulses', 2999]]}, [1, None])], [('regression: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('sampled regression 50', {'floor_mm': [0, 3000, 7200, 11400, 14900, 18400, 22600], 'start_mm': 20, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 100], ['pulses', 100], ['magnet', 3], ['pulses', 3499], ['pulses', 1000]]}, [None, None, 3, 4, None]), ('sampled regression 36', {'floor_mm': [0, 3500, 7000, 10500, 14700, 18200], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 4], ['magnet', 3], ['pulses', 2999], ['magnet', 2], ['pulses', 3499], ['pulses', 5000]]}, [4, 3, None, 2, None, None]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('sampled regression 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('sampled regression 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('sampled regression 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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:
Passing a door-zone magnet throws the position far off.

Car position is tracked in micrometres: start_mm*1000, pulses add count*um_per_pulse, a door-zone magnet at floor k resets the position to floor_mm[k]*1000. After every event the position in mm is floor(um/1000); the car is at the nearest floor (ties to the lower index) if within zone_mm inclusive, otherwise None (between floors).

split: open-access


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

N = 1
observations = []
def solve(x):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos = table[v] * 1000
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) < x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('control 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('control 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('control 10', {'floor_mm': [0, 3000, 6000, 9500, 13700], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['magnet', 2], ['pulses', 4200], ['pulses', 3500], ['pulses', 100], ['pulses', 5000], ['pulses', 3000], ['pulses', 4200]]}, [2, None, 4, None, None, None, None]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None]), ('control 32', {'floor_mm': [0, 4200, 7700, 11200, 14700, 17700, 21200, 25400], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 5000], ['pulses', 3000], ['magnet', 6], ['magnet', 0], ['magnet', 4]]}, [None, None, None, 6, 0, 4])], [('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('control 54', {'floor_mm': [0, 4200, 8400, 11900, 16100, 19600, 23100, 26100, 30300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 3500], ['pulses', 3500], ['magnet', 6], ['pulses', 2999]]}, [None, 1, 6, None]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('control 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('control 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('control 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('control 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos = table[v] * 1000
        mm = pos // 1000
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] * 1000 - pos) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('control 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('control 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('control 10', {'floor_mm': [0, 3000, 6000, 9500, 13700], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['magnet', 2], ['pulses', 4200], ['pulses', 3500], ['pulses', 100], ['pulses', 5000], ['pulses', 3000], ['pulses', 4200]]}, [2, None, 4, None, None, None, None]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None]), ('control 32', {'floor_mm': [0, 4200, 7700, 11200, 14700, 17700, 21200, 25400], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 5000], ['pulses', 3000], ['magnet', 6], ['magnet', 0], ['magnet', 4]]}, [None, None, None, 6, 0, 4])], [('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('control 54', {'floor_mm': [0, 4200, 8400, 11900, 16100, 19600, 23100, 26100, 30300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 3500], ['pulses', 3500], ['magnet', 6], ['pulses', 2999]]}, [None, 1, 6, None]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('control 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('control 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('regression: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('regression: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('control 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('control 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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 car exactly at the zone edge is reported between floors.

Car position is tracked in micrometres: start_mm*1000, pulses add count*um_per_pulse, a door-zone magnet at floor k resets the position to floor_mm[k]*1000. After every event the position in mm is floor(um/1000); the car is at the nearest floor (ties to the lower index) if within zone_mm inclusive, otherwise None (between floors).

split: open-access


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

N = 1
observations = []
def solve(x):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos = table[v] * 1000
        mm = round(pos / 1000)
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('control 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('control 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('control 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('control 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('control 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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):
    table = x['floor_mm']
    pos = x['start_mm'] * 1000
    out = []
    for kind, v in x['events']:
        if kind == 'pulses':
            pos += v * x['um_per_pulse']
        else:
            pos = table[v] * 1000
        mm = -(-pos // 1000)
        best = min(range(len(table)), key=lambda k: (abs(table[k] - mm), k))
        out.append(best if abs(table[best] - mm) <= x['zone_mm'] else None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 1', {'floor_mm': [0, 4200, 8400, 11400, 14900], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 5000], ['magnet', 4], ['pulses', 2999], ['pulses', 4200], ['pulses', 2999], ['magnet', 4]]}, [3, None, 4, None, None, None, 4]), ('control 4', {'floor_mm': [0, 3000, 6500, 10000, 13500, 16500, 20000], 'start_mm': 2990, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 1000], ['pulses', 100]]}, [None, None]), ('control 7', {'floor_mm': [0, 3500, 7700, 10700, 14200, 17200, 21400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 1000], ['pulses', 100], ['magnet', 2], ['pulses', 3000]]}, [0, None, None, None, 2, 3])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 12', {'floor_mm': [0, 3000, 6000, 10200, 13200, 17400], 'start_mm': 2990, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['magnet', 0], ['pulses', 3499], ['pulses', 1000], ['pulses', 3500], ['pulses', 100], ['magnet', 2], ['pulses', 3500]]}, [0, None, None, None, None, 2, None]), ('control 15', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 3499]]}, [1, None]), ('control 18', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19100], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 3499], ['pulses', 3000], ['pulses', 3000]]}, [None, None, None])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('control 23', {'floor_mm': [0, 4200, 7700, 11200, 15400, 18400, 22600, 25600, 28600], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3500], ['pulses', 3000]]}, [None, None]), ('control 26', {'floor_mm': [0, 4200, 7200, 11400, 14900, 17900, 21400, 25600], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 75, 'events': [['pulses', 4200], ['pulses', 4200], ['pulses', 3500], ['pulses', 2999], ['pulses', 3499], ['pulses', 2999], ['pulses', 4200]]}, [1, None, None, 4, None, 6, None]), ('control 29', {'floor_mm': [0, 4200, 8400, 12600, 16100, 20300, 23800, 27300], 'start_mm': 20, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 3], ['pulses', 2999], ['pulses', 3499], ['pulses', 5000], ['magnet', 1], ['pulses', 100]]}, [3, None, None, None, 1, None])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('boundary: magnet correction', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 1], ['pulses', 3000]]}, [1, 1, 2]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('control 34', {'floor_mm': [0, 4200, 7700, 10700, 14200, 17700, 20700, 23700], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 50, 'events': [['magnet', 5], ['pulses', 5000]]}, [5, 6]), ('control 37', {'floor_mm': [0, 4200, 7200, 10700, 14200, 17700, 20700], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 2999], ['pulses', 1000], ['pulses', 100], ['magnet', 2]]}, [None, None, None, 2]), ('control 40', {'floor_mm': [0, 4200, 7700, 11900, 15400, 19600, 22600, 26800, 29800], 'start_mm': 20, 'um_per_pulse': 1000, 'zone_mm': 50, 'events': [['pulses', 3000], ['magnet', 0], ['magnet', 8], ['pulses', 5000], ['pulses', 3000], ['pulses', 5000], ['magnet', 4]]}, [None, 0, 8, None, None, None, 4])], [('regression: six-tenths of a millimetre short of the zone', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['pulses', 1], ['pulses', 1]]}, [None, 1]), ('boundary: zone edge', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 1000, 'zone_mm': 75, 'events': [['pulses', 2925], ['pulses', 1]]}, [1, 1]), ('boundary: sub-millimetre pulses', {'floor_mm': [0, 3000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 999], ['pulses', 2]]}, [None, None]), ('boundary: fractional millimetre below a floor', {'floor_mm': [0, 3000], 'start_mm': 2924, 'um_per_pulse': 1003, 'zone_mm': 75, 'events': [['pulses', 1]]}, [1]), ('boundary: encoder slip accumulates', {'floor_mm': [0, 3000, 6000], 'start_mm': 0, 'um_per_pulse': 997, 'zone_mm': 50, 'events': [['pulses', 3000], ['pulses', 3000]]}, [1, 2]), ('control 45', {'floor_mm': [0, 3000, 7200, 11400, 15600, 19800, 22800, 26300], 'start_mm': 2990, 'um_per_pulse': 600, 'zone_mm': 75, 'events': [['magnet', 3], ['pulses', 3500], ['pulses', 3500]]}, [3, None, 4]), ('control 48', {'floor_mm': [0, 3000, 6000, 9000, 13200, 16200, 20400, 23400, 26400], 'start_mm': 0, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 1000], ['magnet', 2]]}, [0, None, 2]), ('control 51', {'floor_mm': [0, 4200, 7200, 10700, 14900, 19100], 'start_mm': 2990, 'um_per_pulse': 1003, 'zone_mm': 50, 'events': [['magnet', 0], ['pulses', 100], ['pulses', 100]]}, [0, None, None])]]
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:
Positions just short of the zone edge are rounded into it.

Car position is tracked in micrometres: start_mm*1000, pulses add count*um_per_pulse, a door-zone magnet at floor k resets the position to floor_mm[k]*1000. After every event the position in mm is floor(um/1000); the car is at the nearest floor (ties to the lower index) if within zone_mm inclusive, otherwise None (between floors).

split: open-access


prompt:
Webster cycle length returns a wrong result when critical ratio sums every lane group of a phase.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Webster cycle length returns a wrong result when lost time is counted once per cycle instead of once per phase.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Webster cycle length returns a wrong result when the constant 5 s is scaled together with lost time.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Webster cycle length returns a wrong result when the computed cycle is rounded down to a 5 s multiple.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Webster cycle length returns a wrong result when the oversaturation guard only trips above Y = 1.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Webster cycle length returns a wrong result when the cycle is not capped at the controller maximum.

Input {phases: per-phase lists of lane-group flows veh/h, sat: saturation flow per lane group, lost: lost seconds per phase, allred: extra all-red seconds per cycle, cmin, cmax}. Y is the sum over phases of the critical (largest) flow ratio; L = lost*phases + allred. If Y >= 0.9 return 'oversaturated'. Otherwise C0 = (1.5L + 5)/(1 - Y), rounded UP to a multiple of 5 s and clamped to [cmin, cmax]. Return {cycle, lost: L, y_milli: floor(1000Y)}.

split: open-access


prompt:
Green split allocation returns a wrong result when the whole cycle is distributed as green.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access


prompt:
Green split allocation returns a wrong result when leftover seconds go to the smallest remainders.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access


prompt:
Green split allocation returns a wrong result when base shares are rounded to nearest before remainder distribution.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access


prompt:
Green split allocation returns a wrong result when critical flow ratios are read as den over num.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access


prompt:
Green split allocation returns a wrong result when feasibility compares the single largest minimum with G.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access


prompt:
Green split allocation returns a wrong result when minimum green seconds are taken from the longest green regardless of its own minimum.

Input {cycle, lost, ratios: per-phase critical flow ratios [num, den], min_green: per-phase minima}. Effective green G = cycle - lost is shared in proportion to the ratios; each phase gets the floor of its ideal share and remaining seconds go one each by largest fractional remainder (ties to the lower phase index). Then each phase below its minimum (in index order) takes seconds one at a time from the phase with the largest surplus over its own minimum (ties to the lower index). If the minima exceed G return 'infeasible'. Return the list of integer greens.

split: open-access