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

N = 1
observations = []
def solve(x):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N + 1 - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] == 'up':
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            if best is None or fs > best[0]:
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 55', {'floors': 11, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'C', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'up'}], 'calls': [[6, 'down'], [4, 'up']]}, ['C', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 77', {'floors': 13, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'C', 'floor': 0, 'dir': 'up'}, {'id': 'A', 'floor': 4, 'dir': 'down'}], 'calls': [[2, 'up'], [11, 'up'], [9, 'up'], [12, 'down']]}, ['C', 'C', 'C', 'A']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('control 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 79', {'floors': 14, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'up'}, {'id': 'B', 'floor': 4, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('control 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 32', {'floors': 16, 'cars': [{'id': 'A', 'floor': 15, 'dir': 'up'}, {'id': 'D', 'floor': 14, 'dir': 'down'}, {'id': 'C', 'floor': 0, 'dir': 'up'}], 'calls': [[15, 'down'], [14, 'up'], [2, 'down']]}, ['A', 'C', 'C']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N + 1 - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] != cd:
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            if best is None or fs > best[0]:
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 55', {'floors': 11, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'C', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'up'}], 'calls': [[6, 'down'], [4, 'up']]}, ['C', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 77', {'floors': 13, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'C', 'floor': 0, 'dir': 'up'}, {'id': 'A', 'floor': 4, 'dir': 'down'}], 'calls': [[2, 'up'], [11, 'up'], [9, 'up'], [12, 'down']]}, ['C', 'C', 'C', 'A']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('control 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 79', {'floors': 14, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'up'}, {'id': 'B', 'floor': 4, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('control 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('regression: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 32', {'floors': 16, 'cars': [{'id': 'A', 'floor': 15, 'dir': 'up'}, {'id': 'D', 'floor': 14, 'dir': 'down'}, {'id': 'C', 'floor': 0, 'dir': 'up'}], 'calls': [[15, 'down'], [14, 'up'], [2, 'down']]}, ['A', 'C', 'C']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
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 approaching in the call direction gains no advantage.

With N = floors-1 and d = distance to the call: an idle car scores N+1-d; a car moving strictly towards the call scores N+2-d if travelling in the call direction, N+1-d otherwise; a car moving away (or level with the call while moving) scores 1. Each call independently goes to the highest score, ties to the lowest car id.

split: open-access


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

N = 1
observations = []
def solve(x):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N + 1 - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] == cd:
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            if best is None or fs >= best[0]:
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 11', {'floors': 14, 'cars': [{'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 3, 'dir': 'up'}], 'calls': [[9, 'down'], [9, 'up'], [10, 'down'], [11, 'down']]}, ['A', 'A', 'A', 'A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 5', {'floors': 10, 'cars': [{'id': 'C', 'floor': 4, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}], 'calls': [[6, 'up'], [4, 'up'], [7, 'up'], [1, 'down']]}, ['D', 'A', 'B', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('sampled regression 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('sampled regression 13', {'floors': 16, 'cars': [{'id': 'D', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'up'}], 'calls': [[7, 'down'], [1, 'down']]}, ['C', 'D']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 65', {'floors': 11, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'down'}, {'id': 'A', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'up'], [6, 'up']]}, ['C', 'A']), ('control 20', {'floors': 11, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'B', 'floor': 0, 'dir': 'idle'}, {'id': 'D', 'floor': 3, 'dir': 'idle'}], 'calls': [[4, 'up'], [10, 'down'], [10, 'down'], [9, 'up']]}, ['D', 'A', 'A', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('sampled regression 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 3', {'floors': 11, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'A', 'floor': 0, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'idle'}], 'calls': [[9, 'down'], [8, 'up'], [4, 'up'], [1, 'down']]}, ['D', 'D', 'D', 'A']), ('control 25', {'floors': 13, 'cars': [{'id': 'C', 'floor': 2, 'dir': 'idle'}, {'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 0, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[7, 'down'], [0, 'up']]}, ['A', 'D']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
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):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N + 1 - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] == cd:
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            for car in sorted(x['cars'], key=lambda c: c['floor']):
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 11', {'floors': 14, 'cars': [{'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 3, 'dir': 'up'}], 'calls': [[9, 'down'], [9, 'up'], [10, 'down'], [11, 'down']]}, ['A', 'A', 'A', 'A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 5', {'floors': 10, 'cars': [{'id': 'C', 'floor': 4, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}], 'calls': [[6, 'up'], [4, 'up'], [7, 'up'], [1, 'down']]}, ['D', 'A', 'B', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('sampled regression 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('sampled regression 13', {'floors': 16, 'cars': [{'id': 'D', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'up'}], 'calls': [[7, 'down'], [1, 'down']]}, ['C', 'D']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: idle versus same-direction car', {'floors': 12, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 65', {'floors': 11, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'down'}, {'id': 'A', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'up'], [6, 'up']]}, ['C', 'A']), ('control 20', {'floors': 11, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'B', 'floor': 0, 'dir': 'idle'}, {'id': 'D', 'floor': 3, 'dir': 'idle'}], 'calls': [[4, 'up'], [10, 'down'], [10, 'down'], [9, 'up']]}, ['D', 'A', 'A', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('sampled regression 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('regression: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: same-direction bonus', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'down'}], 'calls': [[5, 'up']]}, ['A']), ('sampled regression 3', {'floors': 11, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'A', 'floor': 0, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'idle'}], 'calls': [[9, 'down'], [8, 'up'], [4, 'up'], [1, 'down']]}, ['D', 'D', 'D', 'A']), ('control 25', {'floors': 13, 'cars': [{'id': 'C', 'floor': 2, 'dir': 'idle'}, {'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 0, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[7, 'down'], [0, 'up']]}, ['A', 'D']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
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:
Equal-score calls go to the highest car id or depend on car positions.

With N = floors-1 and d = distance to the call: an idle car scores N+1-d; a car moving strictly towards the call scores N+2-d if travelling in the call direction, N+1-d otherwise; a car moving away (or level with the call while moving) scores 1. Each call independently goes to the highest score, ties to the lowest car id.

split: open-access


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

N = 1
observations = []
def solve(x):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N + 2 - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] == cd:
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            if best is None or fs > best[0]:
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('control 5', {'floors': 10, 'cars': [{'id': 'C', 'floor': 4, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}], 'calls': [[6, 'up'], [4, 'up'], [7, 'up'], [1, 'down']]}, ['D', 'A', 'B', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A']), ('control 10', {'floors': 11, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 3, 'dir': 'up'}, {'id': 'A', 'floor': 5, 'dir': 'down'}], 'calls': [[6, 'up']]}, ['D'])], [('sampled regression 2', {'floors': 9, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'idle'}, {'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'down'}, {'id': 'C', 'floor': 8, 'dir': 'down'}], 'calls': [[3, 'down'], [7, 'up']]}, ['B', 'C']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 41', {'floors': 13, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'D', 'floor': 7, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down'], [0, 'up'], [0, 'up'], [4, 'up']]}, ['A', 'B', 'B', 'A']), ('control 79', {'floors': 14, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'up'}, {'id': 'B', 'floor': 4, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('control 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('sampled regression 41', {'floors': 13, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'D', 'floor': 7, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down'], [0, 'up'], [0, 'up'], [4, 'up']]}, ['A', 'B', 'B', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 2', {'floors': 9, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'idle'}, {'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'down'}, {'id': 'C', 'floor': 8, 'dir': 'down'}], 'calls': [[3, 'down'], [7, 'up']]}, ['B', 'C']), ('control 17', {'floors': 16, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'down'}, {'id': 'A', 'floor': 0, 'dir': 'idle'}, {'id': 'D', 'floor': 13, 'dir': 'up'}], 'calls': [[10, 'down'], [2, 'down']]}, ['A', 'A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 11', {'floors': 14, 'cars': [{'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 3, 'dir': 'up'}], 'calls': [[9, 'down'], [9, 'up'], [10, 'down'], [11, 'down']]}, ['A', 'A', 'A', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('control 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('sampled regression 55', {'floors': 11, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'C', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'up'}], 'calls': [[6, 'down'], [4, 'up']]}, ['C', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 76', {'floors': 8, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 4, 'dir': 'up'}], 'calls': [[3, 'up']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    N = x['floors'] - 1
    res = []
    for fl, cd in x['calls']:
        best = None
        for car in sorted(x['cars'], key=lambda c: c['id']):
            d = abs(car['floor'] - fl)
            if car['dir'] == 'idle':
                fs = N - d
            else:
                toward = (car['dir'] == 'up' and fl > car['floor']) or (car['dir'] == 'down' and fl < car['floor'])
                if not toward:
                    fs = 1
                elif car['dir'] == cd:
                    fs = N + 2 - d
                else:
                    fs = N + 1 - d
            if best is None or fs > best[0]:
                best = (fs, car['id'])
        res.append(best[1])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('control 5', {'floors': 10, 'cars': [{'id': 'C', 'floor': 4, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}], 'calls': [[6, 'up'], [4, 'up'], [7, 'up'], [1, 'down']]}, ['D', 'A', 'B', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 4', {'floors': 13, 'cars': [{'id': 'A', 'floor': 8, 'dir': 'up'}, {'id': 'C', 'floor': 12, 'dir': 'idle'}, {'id': 'D', 'floor': 10, 'dir': 'idle'}], 'calls': [[10, 'down'], [3, 'up']]}, ['D', 'D']), ('control 7', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'idle'}, {'id': 'C', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 1, 'dir': 'idle'}], 'calls': [[5, 'down'], [6, 'down']]}, ['A', 'A']), ('control 10', {'floors': 11, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 3, 'dir': 'up'}, {'id': 'A', 'floor': 5, 'dir': 'down'}], 'calls': [[6, 'up']]}, ['D'])], [('sampled regression 2', {'floors': 9, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'idle'}, {'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'down'}, {'id': 'C', 'floor': 8, 'dir': 'down'}], 'calls': [[3, 'down'], [7, 'up']]}, ['B', 'C']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 41', {'floors': 13, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'D', 'floor': 7, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down'], [0, 'up'], [0, 'up'], [4, 'up']]}, ['A', 'B', 'B', 'A']), ('control 79', {'floors': 14, 'cars': [{'id': 'D', 'floor': 6, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'up'}, {'id': 'B', 'floor': 4, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('control 12', {'floors': 9, 'cars': [{'id': 'C', 'floor': 0, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'A', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 0, 'dir': 'up'}], 'calls': [[0, 'up'], [7, 'up'], [6, 'down']]}, ['C', 'B', 'B']), ('control 15', {'floors': 15, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[10, 'down'], [4, 'down'], [12, 'down']]}, ['B', 'B', 'B']), ('control 18', {'floors': 12, 'cars': [{'id': 'B', 'floor': 8, 'dir': 'down'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[4, 'up'], [7, 'down'], [5, 'up'], [1, 'down']]}, ['B', 'B', 'B', 'B'])], [('sampled regression 41', {'floors': 13, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'D', 'floor': 7, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down'], [0, 'up'], [0, 'up'], [4, 'up']]}, ['A', 'B', 'B', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 2', {'floors': 9, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'idle'}, {'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'down'}, {'id': 'C', 'floor': 8, 'dir': 'down'}], 'calls': [[3, 'down'], [7, 'up']]}, ['B', 'C']), ('control 17', {'floors': 16, 'cars': [{'id': 'B', 'floor': 5, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'down'}, {'id': 'A', 'floor': 0, 'dir': 'idle'}, {'id': 'D', 'floor': 13, 'dir': 'up'}], 'calls': [[10, 'down'], [2, 'down']]}, ['A', 'A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 23', {'floors': 11, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'C', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'A', 'floor': 3, 'dir': 'up'}], 'calls': [[2, 'down'], [0, 'up']]}, ['D', 'A']), ('control 26', {'floors': 10, 'cars': [{'id': 'C', 'floor': 1, 'dir': 'down'}, {'id': 'B', 'floor': 1, 'dir': 'up'}], 'calls': [[6, 'up'], [0, 'up'], [7, 'up']]}, ['B', 'C', 'B']), ('control 29', {'floors': 15, 'cars': [{'id': 'C', 'floor': 8, 'dir': 'up'}, {'id': 'A', 'floor': 6, 'dir': 'idle'}, {'id': 'B', 'floor': 10, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'down'}], 'calls': [[14, 'down'], [5, 'up']]}, ['B', 'A'])], [('sampled regression 46', {'floors': 13, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 12, 'dir': 'down'}, {'id': 'A', 'floor': 10, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}], 'calls': [[7, 'down'], [5, 'down'], [7, 'up'], [11, 'up']]}, ['A', 'D', 'A', 'B']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 1', {'floors': 14, 'cars': [{'id': 'C', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 10, 'dir': 'down'}, {'id': 'D', 'floor': 6, 'dir': 'idle'}], 'calls': [[12, 'up'], [6, 'down'], [5, 'up'], [8, 'down']]}, ['D', 'D', 'C', 'B']), ('control 11', {'floors': 14, 'cars': [{'id': 'A', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 3, 'dir': 'up'}], 'calls': [[9, 'down'], [9, 'up'], [10, 'down'], [11, 'down']]}, ['A', 'A', 'A', 'A']), ('boundary: car level with the call while moving', {'floors': 10, 'cars': [{'id': 'A', 'floor': 5, 'dir': 'up'}, {'id': 'B', 'floor': 8, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['B']), ('control 34', {'floors': 14, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'C', 'floor': 13, 'dir': 'down'}, {'id': 'D', 'floor': 4, 'dir': 'down'}], 'calls': [[7, 'up'], [9, 'up']]}, ['A', 'C']), ('control 37', {'floors': 12, 'cars': [{'id': 'B', 'floor': 11, 'dir': 'down'}, {'id': 'C', 'floor': 10, 'dir': 'down'}], 'calls': [[7, 'down'], [10, 'up'], [11, 'down']]}, ['C', 'B', 'B']), ('control 40', {'floors': 8, 'cars': [{'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 3, 'dir': 'idle'}, {'id': 'B', 'floor': 6, 'dir': 'down'}, {'id': 'C', 'floor': 2, 'dir': 'up'}], 'calls': [[5, 'down']]}, ['B'])], [('sampled regression 55', {'floors': 11, 'cars': [{'id': 'A', 'floor': 3, 'dir': 'up'}, {'id': 'C', 'floor': 4, 'dir': 'idle'}, {'id': 'B', 'floor': 7, 'dir': 'up'}], 'calls': [[6, 'down'], [4, 'up']]}, ['C', 'A']), ('boundary: opposite-direction approach', {'floors': 10, 'cars': [{'id': 'A', 'floor': 2, 'dir': 'up'}, {'id': 'B', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('sampled regression 76', {'floors': 8, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'down'}, {'id': 'B', 'floor': 6, 'dir': 'idle'}, {'id': 'C', 'floor': 4, 'dir': 'up'}], 'calls': [[3, 'up']]}, ['A']), ('boundary: equal scores', {'floors': 10, 'cars': [{'id': 'B', 'floor': 3, 'dir': 'idle'}, {'id': 'A', 'floor': 7, 'dir': 'idle'}], 'calls': [[5, 'up']]}, ['A']), ('boundary: car moving away', {'floors': 10, 'cars': [{'id': 'A', 'floor': 6, 'dir': 'up'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[5, 'down']]}, ['B']), ('control 45', {'floors': 16, 'cars': [{'id': 'D', 'floor': 4, 'dir': 'up'}, {'id': 'C', 'floor': 10, 'dir': 'idle'}, {'id': 'B', 'floor': 9, 'dir': 'idle'}], 'calls': [[10, 'down'], [15, 'down']]}, ['C', 'C']), ('control 48', {'floors': 10, 'cars': [{'id': 'B', 'floor': 1, 'dir': 'down'}, {'id': 'C', 'floor': 5, 'dir': 'down'}, {'id': 'D', 'floor': 1, 'dir': 'up'}, {'id': 'A', 'floor': 9, 'dir': 'down'}], 'calls': [[3, 'up'], [1, 'down'], [3, 'up']]}, ['D', 'C', 'D']), ('control 51', {'floors': 14, 'cars': [{'id': 'C', 'floor': 3, 'dir': 'idle'}, {'id': 'D', 'floor': 7, 'dir': 'up'}, {'id': 'A', 'floor': 0, 'dir': 'up'}], 'calls': [[8, 'up'], [0, 'up'], [0, 'up'], [8, 'down']]}, ['D', 'C', 'C', 'D'])]]
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:
Idle cars beat or lose to approaching cars inconsistently with the stipulated scores.

With N = floors-1 and d = distance to the call: an idle car scores N+1-d; a car moving strictly towards the call scores N+2-d if travelling in the call direction, N+1-d otherwise; a car moving away (or level with the call while moving) scores 1. Each call independently goes to the highest score, ties to the lowest car id.

split: open-access


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

N = 1
observations = []
def solve(x):
    count = 0
    nudge = False
    block_start = None
    out = []
    for t, ev in x['events']:
        if ev == 'obstruct':
            if block_start is None:
                block_start = t
            if nudge:
                out.append('ignored')
            else:
                count += 1
                if count > 3 or t - block_start >= 20:
                    nudge = True
                    out.append('nudge')
                else:
                    out.append('reopen')
        elif ev == 'unblock':
            block_start = None
        elif ev == 'edge':
            out.append('reopen')
        elif ev == 'closed':
            count = 0
            nudge = False
            block_start = None
            out.append('done')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('regression: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('sampled regression 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('control 4', {'events': [[5, 'edge'], [10, 'unblock'], [11, 'obstruct'], [19, 'closed']]}, ['reopen', 'reopen', 'done']), ('control 7', {'events': [[2, 'unblock'], [10, 'edge'], [18, 'obstruct'], [23, 'unblock'], [28, 'edge'], [33, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 10', {'events': [[8, 'edge'], [13, 'obstruct'], [18, 'edge'], [30, 'unblock'], [35, 'obstruct'], [40, 'obstruct'], [42, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 17', {'events': [[5, 'unblock'], [13, 'unblock'], [14, 'closed'], [26, 'obstruct'], [34, 'edge'], [36, 'obstruct'], [48, 'unblock'], [60, 'obstruct'], [72, 'unblock']]}, ['done', 'reopen', 'reopen', 'reopen', 'nudge']), ('sampled regression 13', {'events': [[5, 'unblock'], [13, 'obstruct'], [21, 'closed'], [29, 'edge'], [34, 'obstruct'], [46, 'obstruct'], [47, 'unblock'], [55, 'obstruct'], [63, 'closed'], [64, 'unblock']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'done']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 12', {'events': [[5, 'obstruct'], [13, 'edge'], [15, 'unblock'], [16, 'obstruct'], [21, 'unblock'], [22, 'edge'], [30, 'closed'], [32, 'obstruct'], [44, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('sampled regression 18', {'events': [[12, 'obstruct'], [20, 'obstruct'], [22, 'obstruct']]}, ['reopen', 'reopen', 'nudge'])], [('regression: curtain broken then blocked again', {'events': [[0, 'obstruct'], [5, 'unblock'], [15, 'obstruct'], [26, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 28', {'events': [[12, 'unblock'], [20, 'edge'], [32, 'edge'], [33, 'obstruct'], [35, 'obstruct'], [40, 'obstruct'], [41, 'obstruct'], [53, 'obstruct'], [58, 'closed']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'done']), ('control 29', {'events': [[8, 'edge'], [10, 'obstruct'], [12, 'obstruct'], [20, 'closed']]}, ['reopen', 'reopen', 'reopen', 'done']), ('boundary: curtain held for twenty seconds', {'events': [[0, 'obstruct'], [20, 'obstruct']]}, ['reopen', 'nudge']), ('control 23', {'events': [[1, 'unblock'], [6, 'unblock'], [18, 'obstruct'], [30, 'closed']]}, ['reopen', 'done']), ('sampled regression 26', {'events': [[12, 'closed'], [13, 'closed'], [15, 'obstruct'], [17, 'obstruct'], [19, 'obstruct']]}, ['done', 'done', 'reopen', 'reopen', 'nudge']), ('sampled regression 32', {'events': [[8, 'closed'], [13, 'unblock'], [15, 'obstruct'], [16, 'obstruct'], [17, 'obstruct'], [19, 'unblock'], [31, 'obstruct'], [36, 'obstruct']]}, ['done', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored'])], [('regression: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('sampled regression 64', {'events': [[8, 'obstruct'], [13, 'edge'], [18, 'unblock'], [26, 'unblock'], [34, 'obstruct'], [36, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge']), ('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('sampled regression 34', {'events': [[8, 'edge'], [16, 'obstruct'], [24, 'obstruct'], [36, 'closed'], [48, 'obstruct'], [60, 'obstruct'], [62, 'obstruct'], [64, 'unblock'], [72, 'obstruct'], [80, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen', 'nudge', 'ignored']), ('control 37', {'events': [[2, 'closed'], [4, 'closed'], [9, 'obstruct'], [21, 'edge']]}, ['done', 'done', 'reopen', 'reopen']), ('control 40', {'events': [[2, 'closed'], [7, 'obstruct'], [15, 'edge'], [16, 'obstruct'], [18, 'closed']]}, ['done', 'reopen', 'reopen', 'reopen', 'done'])], [('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 72', {'events': [[12, 'obstruct'], [14, 'obstruct'], [15, 'unblock'], [20, 'obstruct'], [32, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('sampled regression 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('control 45', {'events': [[5, 'edge'], [17, 'closed'], [22, 'obstruct'], [24, 'closed']]}, ['reopen', 'done', 'reopen', 'done']), ('sampled regression 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('control 51', {'events': [[8, 'closed'], [9, 'closed'], [14, 'obstruct'], [26, 'closed'], [38, 'obstruct']]}, ['done', 'done', 'reopen', 'done', 'reopen'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    count = 0
    nudge = False
    block_start = None
    out = []
    for t, ev in x['events']:
        if ev == 'obstruct':
            if block_start is None:
                block_start = t
            if nudge:
                out.append('ignored')
            else:
                count += 1
                if count >= 3 or t - block_start >= 20:
                    nudge = True
                    out.append('nudge')
                else:
                    out.append('reopen')
        elif ev == 'unblock':
            block_start = None
        elif ev == 'edge':
            count += 1
            out.append('reopen')
        elif ev == 'closed':
            count = 0
            nudge = False
            block_start = None
            out.append('done')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('regression: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('sampled regression 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('control 4', {'events': [[5, 'edge'], [10, 'unblock'], [11, 'obstruct'], [19, 'closed']]}, ['reopen', 'reopen', 'done']), ('control 7', {'events': [[2, 'unblock'], [10, 'edge'], [18, 'obstruct'], [23, 'unblock'], [28, 'edge'], [33, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 10', {'events': [[8, 'edge'], [13, 'obstruct'], [18, 'edge'], [30, 'unblock'], [35, 'obstruct'], [40, 'obstruct'], [42, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 17', {'events': [[5, 'unblock'], [13, 'unblock'], [14, 'closed'], [26, 'obstruct'], [34, 'edge'], [36, 'obstruct'], [48, 'unblock'], [60, 'obstruct'], [72, 'unblock']]}, ['done', 'reopen', 'reopen', 'reopen', 'nudge']), ('sampled regression 13', {'events': [[5, 'unblock'], [13, 'obstruct'], [21, 'closed'], [29, 'edge'], [34, 'obstruct'], [46, 'obstruct'], [47, 'unblock'], [55, 'obstruct'], [63, 'closed'], [64, 'unblock']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'done']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 12', {'events': [[5, 'obstruct'], [13, 'edge'], [15, 'unblock'], [16, 'obstruct'], [21, 'unblock'], [22, 'edge'], [30, 'closed'], [32, 'obstruct'], [44, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('sampled regression 18', {'events': [[12, 'obstruct'], [20, 'obstruct'], [22, 'obstruct']]}, ['reopen', 'reopen', 'nudge'])], [('regression: curtain broken then blocked again', {'events': [[0, 'obstruct'], [5, 'unblock'], [15, 'obstruct'], [26, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 28', {'events': [[12, 'unblock'], [20, 'edge'], [32, 'edge'], [33, 'obstruct'], [35, 'obstruct'], [40, 'obstruct'], [41, 'obstruct'], [53, 'obstruct'], [58, 'closed']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'done']), ('control 29', {'events': [[8, 'edge'], [10, 'obstruct'], [12, 'obstruct'], [20, 'closed']]}, ['reopen', 'reopen', 'reopen', 'done']), ('boundary: curtain held for twenty seconds', {'events': [[0, 'obstruct'], [20, 'obstruct']]}, ['reopen', 'nudge']), ('control 23', {'events': [[1, 'unblock'], [6, 'unblock'], [18, 'obstruct'], [30, 'closed']]}, ['reopen', 'done']), ('sampled regression 26', {'events': [[12, 'closed'], [13, 'closed'], [15, 'obstruct'], [17, 'obstruct'], [19, 'obstruct']]}, ['done', 'done', 'reopen', 'reopen', 'nudge']), ('sampled regression 32', {'events': [[8, 'closed'], [13, 'unblock'], [15, 'obstruct'], [16, 'obstruct'], [17, 'obstruct'], [19, 'unblock'], [31, 'obstruct'], [36, 'obstruct']]}, ['done', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored'])], [('regression: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('sampled regression 64', {'events': [[8, 'obstruct'], [13, 'edge'], [18, 'unblock'], [26, 'unblock'], [34, 'obstruct'], [36, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge']), ('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('sampled regression 34', {'events': [[8, 'edge'], [16, 'obstruct'], [24, 'obstruct'], [36, 'closed'], [48, 'obstruct'], [60, 'obstruct'], [62, 'obstruct'], [64, 'unblock'], [72, 'obstruct'], [80, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen', 'nudge', 'ignored']), ('control 37', {'events': [[2, 'closed'], [4, 'closed'], [9, 'obstruct'], [21, 'edge']]}, ['done', 'done', 'reopen', 'reopen']), ('control 40', {'events': [[2, 'closed'], [7, 'obstruct'], [15, 'edge'], [16, 'obstruct'], [18, 'closed']]}, ['done', 'reopen', 'reopen', 'reopen', 'done'])], [('regression: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('sampled regression 72', {'events': [[12, 'obstruct'], [14, 'obstruct'], [15, 'unblock'], [20, 'obstruct'], [32, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('sampled regression 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('control 45', {'events': [[5, 'edge'], [17, 'closed'], [22, 'obstruct'], [24, 'closed']]}, ['reopen', 'done', 'reopen', 'done']), ('sampled regression 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('control 51', {'events': [[8, 'closed'], [9, 'closed'], [14, 'obstruct'], [26, 'closed'], [38, 'obstruct']]}, ['done', 'done', 'reopen', 'done', 'reopen'])]]
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 doors reopen a third time instead of nudging, or safety-edge contacts bring nudging forward.

During a door cycle each light-curtain obstruction reopens the doors and counts; the third obstruction, or an obstruction while the curtain has been blocked continuously for 20 s or more since the first unbroken obstruction, starts nudging (slow close, curtain ignored). While nudging, curtain obstructions are ignored. The mechanical safety edge always reopens and does not affect counting. unblock ends a continuous blockage. closed ends the cycle and resets everything.

split: open-access


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

N = 1
observations = []
def solve(x):
    count = 0
    nudge = False
    block_start = None
    out = []
    for t, ev in x['events']:
        if ev == 'obstruct':
            if block_start is None:
                block_start = t
            if nudge:
                out.append('ignored')
            else:
                count += 1
                if count >= 3 or t - block_start >= 20:
                    nudge = True
                    out.append('nudge')
                else:
                    out.append('reopen')
        elif ev == 'unblock':
            block_start = None
        elif ev == 'edge':
            out.append('ignored' if nudge else 'reopen')
        elif ev == 'closed':
            count = 0
            nudge = False
            block_start = None
            out.append('done')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 22', {'events': [[5, 'closed'], [7, 'obstruct'], [9, 'obstruct'], [14, 'obstruct'], [19, 'edge'], [20, 'edge'], [32, 'unblock']]}, ['done', 'reopen', 'reopen', 'nudge', 'reopen', 'reopen']), ('control 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('boundary: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('control 4', {'events': [[5, 'edge'], [10, 'unblock'], [11, 'obstruct'], [19, 'closed']]}, ['reopen', 'reopen', 'done']), ('control 7', {'events': [[2, 'unblock'], [10, 'edge'], [18, 'obstruct'], [23, 'unblock'], [28, 'edge'], [33, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('control 10', {'events': [[8, 'edge'], [13, 'obstruct'], [18, 'edge'], [30, 'unblock'], [35, 'obstruct'], [40, 'obstruct'], [42, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 77', {'events': [[5, 'obstruct'], [13, 'obstruct'], [25, 'obstruct'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [54, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen', 'reopen']), ('sampled regression 33', {'events': [[5, 'obstruct'], [17, 'unblock'], [18, 'obstruct'], [20, 'unblock'], [32, 'edge'], [34, 'edge'], [46, 'unblock'], [54, 'obstruct'], [62, 'edge'], [70, 'closed']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge', 'reopen', 'done']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 12', {'events': [[5, 'obstruct'], [13, 'edge'], [15, 'unblock'], [16, 'obstruct'], [21, 'unblock'], [22, 'edge'], [30, 'closed'], [32, 'obstruct'], [44, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('control 18', {'events': [[12, 'obstruct'], [20, 'obstruct'], [22, 'obstruct']]}, ['reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 67', {'events': [[12, 'obstruct'], [20, 'obstruct'], [28, 'edge'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [65, 'edge'], [67, 'edge'], [75, 'unblock'], [76, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'reopen', 'reopen', 'reopen', 'ignored']), ('sampled regression 76', {'events': [[2, 'obstruct'], [4, 'obstruct'], [5, 'obstruct'], [13, 'edge'], [15, 'edge'], [20, 'obstruct'], [22, 'obstruct'], [30, 'obstruct'], [42, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'reopen', 'ignored', 'ignored', 'ignored', 'ignored']), ('boundary: curtain held for twenty seconds', {'events': [[0, 'obstruct'], [20, 'obstruct']]}, ['reopen', 'nudge']), ('boundary: curtain broken then blocked again', {'events': [[0, 'obstruct'], [5, 'unblock'], [15, 'obstruct'], [26, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('control 23', {'events': [[1, 'unblock'], [6, 'unblock'], [18, 'obstruct'], [30, 'closed']]}, ['reopen', 'done']), ('control 26', {'events': [[12, 'closed'], [13, 'closed'], [15, 'obstruct'], [17, 'obstruct'], [19, 'obstruct']]}, ['done', 'done', 'reopen', 'reopen', 'nudge']), ('control 29', {'events': [[8, 'edge'], [10, 'obstruct'], [12, 'obstruct'], [20, 'closed']]}, ['reopen', 'reopen', 'reopen', 'done'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('control 17', {'events': [[5, 'unblock'], [13, 'unblock'], [14, 'closed'], [26, 'obstruct'], [34, 'edge'], [36, 'obstruct'], [48, 'unblock'], [60, 'obstruct'], [72, 'unblock']]}, ['done', 'reopen', 'reopen', 'reopen', 'nudge']), ('boundary: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('boundary: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('control 34', {'events': [[8, 'edge'], [16, 'obstruct'], [24, 'obstruct'], [36, 'closed'], [48, 'obstruct'], [60, 'obstruct'], [62, 'obstruct'], [64, 'unblock'], [72, 'obstruct'], [80, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen', 'nudge', 'ignored']), ('control 37', {'events': [[2, 'closed'], [4, 'closed'], [9, 'obstruct'], [21, 'edge']]}, ['done', 'done', 'reopen', 'reopen']), ('control 40', {'events': [[2, 'closed'], [7, 'obstruct'], [15, 'edge'], [16, 'obstruct'], [18, 'closed']]}, ['done', 'reopen', 'reopen', 'reopen', 'done'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 76', {'events': [[2, 'obstruct'], [4, 'obstruct'], [5, 'obstruct'], [13, 'edge'], [15, 'edge'], [20, 'obstruct'], [22, 'obstruct'], [30, 'obstruct'], [42, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'reopen', 'ignored', 'ignored', 'ignored', 'ignored']), ('sampled regression 67', {'events': [[12, 'obstruct'], [20, 'obstruct'], [28, 'edge'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [65, 'edge'], [67, 'edge'], [75, 'unblock'], [76, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'reopen', 'reopen', 'reopen', 'ignored']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 45', {'events': [[5, 'edge'], [17, 'closed'], [22, 'obstruct'], [24, 'closed']]}, ['reopen', 'done', 'reopen', 'done']), ('control 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('control 51', {'events': [[8, 'closed'], [9, 'closed'], [14, 'obstruct'], [26, 'closed'], [38, 'obstruct']]}, ['done', 'done', 'reopen', 'done', 'reopen'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    count = 0
    nudge = False
    block_start = None
    out = []
    for t, ev in x['events']:
        if ev == 'obstruct':
            if block_start is None:
                block_start = t
            if nudge:
                out.append('ignored')
            else:
                count += 1
                if count >= 3 or t - block_start >= 20:
                    nudge = True
                    out.append('nudge')
                else:
                    out.append('reopen')
        elif ev == 'unblock':
            block_start = None
        elif ev == 'edge':
            out.append('reopen')
            nudge = False
            count = 0
        elif ev == 'closed':
            count = 0
            nudge = False
            block_start = None
            out.append('done')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 22', {'events': [[5, 'closed'], [7, 'obstruct'], [9, 'obstruct'], [14, 'obstruct'], [19, 'edge'], [20, 'edge'], [32, 'unblock']]}, ['done', 'reopen', 'reopen', 'nudge', 'reopen', 'reopen']), ('control 1', {'events': [[8, 'obstruct'], [13, 'closed'], [18, 'obstruct'], [26, 'edge'], [28, 'obstruct'], [29, 'obstruct'], [41, 'obstruct'], [42, 'obstruct'], [54, 'obstruct'], [66, 'closed']]}, ['reopen', 'done', 'reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'ignored', 'done']), ('boundary: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('control 4', {'events': [[5, 'edge'], [10, 'unblock'], [11, 'obstruct'], [19, 'closed']]}, ['reopen', 'reopen', 'done']), ('control 7', {'events': [[2, 'unblock'], [10, 'edge'], [18, 'obstruct'], [23, 'unblock'], [28, 'edge'], [33, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('control 10', {'events': [[8, 'edge'], [13, 'obstruct'], [18, 'edge'], [30, 'unblock'], [35, 'obstruct'], [40, 'obstruct'], [42, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 77', {'events': [[5, 'obstruct'], [13, 'obstruct'], [25, 'obstruct'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [54, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen', 'reopen']), ('sampled regression 33', {'events': [[5, 'obstruct'], [17, 'unblock'], [18, 'obstruct'], [20, 'unblock'], [32, 'edge'], [34, 'edge'], [46, 'unblock'], [54, 'obstruct'], [62, 'edge'], [70, 'closed']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'nudge', 'reopen', 'done']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 12', {'events': [[5, 'obstruct'], [13, 'edge'], [15, 'unblock'], [16, 'obstruct'], [21, 'unblock'], [22, 'edge'], [30, 'closed'], [32, 'obstruct'], [44, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('control 18', {'events': [[12, 'obstruct'], [20, 'obstruct'], [22, 'obstruct']]}, ['reopen', 'reopen', 'nudge'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 67', {'events': [[12, 'obstruct'], [20, 'obstruct'], [28, 'edge'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [65, 'edge'], [67, 'edge'], [75, 'unblock'], [76, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'reopen', 'reopen', 'reopen', 'ignored']), ('sampled regression 76', {'events': [[2, 'obstruct'], [4, 'obstruct'], [5, 'obstruct'], [13, 'edge'], [15, 'edge'], [20, 'obstruct'], [22, 'obstruct'], [30, 'obstruct'], [42, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'reopen', 'ignored', 'ignored', 'ignored', 'ignored']), ('boundary: curtain held for twenty seconds', {'events': [[0, 'obstruct'], [20, 'obstruct']]}, ['reopen', 'nudge']), ('boundary: curtain broken then blocked again', {'events': [[0, 'obstruct'], [5, 'unblock'], [15, 'obstruct'], [26, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('control 23', {'events': [[1, 'unblock'], [6, 'unblock'], [18, 'obstruct'], [30, 'closed']]}, ['reopen', 'done']), ('control 26', {'events': [[12, 'closed'], [13, 'closed'], [15, 'obstruct'], [17, 'obstruct'], [19, 'obstruct']]}, ['done', 'done', 'reopen', 'reopen', 'nudge']), ('control 29', {'events': [[8, 'edge'], [10, 'obstruct'], [12, 'obstruct'], [20, 'closed']]}, ['reopen', 'reopen', 'reopen', 'done'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 15', {'events': [[8, 'obstruct'], [9, 'obstruct'], [10, 'obstruct'], [11, 'unblock'], [16, 'obstruct'], [24, 'obstruct'], [29, 'edge']]}, ['reopen', 'reopen', 'nudge', 'ignored', 'ignored', 'reopen']), ('control 17', {'events': [[5, 'unblock'], [13, 'unblock'], [14, 'closed'], [26, 'obstruct'], [34, 'edge'], [36, 'obstruct'], [48, 'unblock'], [60, 'obstruct'], [72, 'unblock']]}, ['done', 'reopen', 'reopen', 'reopen', 'nudge']), ('boundary: closing clears nudging', {'events': [[0, 'obstruct'], [1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'done', 'reopen']), ('boundary: third obstruction', {'events': [[1, 'obstruct'], [2, 'unblock'], [3, 'obstruct'], [4, 'unblock'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge']), ('control 34', {'events': [[8, 'edge'], [16, 'obstruct'], [24, 'obstruct'], [36, 'closed'], [48, 'obstruct'], [60, 'obstruct'], [62, 'obstruct'], [64, 'unblock'], [72, 'obstruct'], [80, 'unblock']]}, ['reopen', 'reopen', 'reopen', 'done', 'reopen', 'reopen', 'nudge', 'ignored']), ('control 37', {'events': [[2, 'closed'], [4, 'closed'], [9, 'obstruct'], [21, 'edge']]}, ['done', 'done', 'reopen', 'reopen']), ('control 40', {'events': [[2, 'closed'], [7, 'obstruct'], [15, 'edge'], [16, 'obstruct'], [18, 'closed']]}, ['done', 'reopen', 'reopen', 'reopen', 'done'])], [('regression: safety edge while nudging', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'obstruct'], [4, 'edge'], [5, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'ignored']), ('sampled regression 76', {'events': [[2, 'obstruct'], [4, 'obstruct'], [5, 'obstruct'], [13, 'edge'], [15, 'edge'], [20, 'obstruct'], [22, 'obstruct'], [30, 'obstruct'], [42, 'obstruct']]}, ['reopen', 'reopen', 'nudge', 'reopen', 'reopen', 'ignored', 'ignored', 'ignored', 'ignored']), ('sampled regression 67', {'events': [[12, 'obstruct'], [20, 'obstruct'], [28, 'edge'], [33, 'obstruct'], [41, 'obstruct'], [53, 'edge'], [65, 'edge'], [67, 'edge'], [75, 'unblock'], [76, 'obstruct']]}, ['reopen', 'reopen', 'reopen', 'nudge', 'ignored', 'reopen', 'reopen', 'reopen', 'ignored']), ('boundary: edge contacts do not count', {'events': [[1, 'obstruct'], [2, 'edge'], [3, 'unblock'], [4, 'obstruct'], [5, 'edge']]}, ['reopen', 'reopen', 'reopen', 'reopen']), ('boundary: new cycle after closing', {'events': [[1, 'obstruct'], [2, 'obstruct'], [3, 'closed'], [4, 'obstruct'], [5, 'unblock']]}, ['reopen', 'reopen', 'done', 'reopen']), ('control 45', {'events': [[5, 'edge'], [17, 'closed'], [22, 'obstruct'], [24, 'closed']]}, ['reopen', 'done', 'reopen', 'done']), ('control 48', {'events': [[2, 'obstruct'], [7, 'obstruct'], [15, 'obstruct'], [27, 'obstruct'], [35, 'unblock']]}, ['reopen', 'reopen', 'nudge', 'ignored']), ('control 51', {'events': [[8, 'closed'], [9, 'closed'], [14, 'obstruct'], [26, 'closed'], [38, 'obstruct']]}, ['done', 'done', 'reopen', 'done', 'reopen'])]]
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 safety edge is ignored while the door nudges.

During a door cycle each light-curtain obstruction reopens the doors and counts; the third obstruction, or an obstruction while the curtain has been blocked continuously for 20 s or more since the first unbroken obstruction, starts nudging (slow close, curtain ignored). While nudging, curtain obstructions are ignored. The mechanical safety edge always reopens and does not affect counting. unblock ends a continuous blockage. closed ends the cycle and resets everything.

split: open-access