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

N = 1
observations = []
def solve(x):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) :
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle' or f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 11', {'floors': 9, 'events': [['arrive', 2, 'down'], ['arrive', 5, 'idle'], ['press', 8, 'down'], ['press', 9, 'up'], ['press', 5, 'down'], ['press', 4, 'down'], ['press', 8, 'up'], ['press', 9, 'down']]}, {'log': ['served:', 'served:', 'lit', 'ignored', 'lit', 'lit', 'ignored', 'ignored'], 'pending': [[4, 'down'], [5, 'down'], [8, 'down']]}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('control 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]})], [('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('sampled regression 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('sampled regression 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('sampled regression 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 36', {'floors': 9, 'events': [['press', 5, 'down'], ['press', -1, 'down'], ['press', 0, 'down']]}, {'log': ['lit', 'ignored', 'ignored'], 'pending': [[5, 'down']]}), ('sampled regression 54', {'floors': 9, 'events': [['press', 3, 'down'], ['press', 7, 'down'], ['arrive', 2, 'idle'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 1, 'down'], ['arrive', 4, 'down'], ['press', 8, 'up'], ['press', 0, 'down'], ['press', 3, 'down']]}, {'log': ['lit', 'lit', 'served:', 'lit', 'served:', 'lit', 'served:down', 'ignored', 'ignored', 'lit'], 'pending': [[1, 'down'], [3, 'down'], [7, 'down']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('sampled regression 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 56', {'floors': 5, 'events': [['arrive', 3, 'down'], ['press', 2, 'up'], ['press', 0, 'down'], ['press', 4, 'down'], ['arrive', 0, 'up'], ['press', 0, 'down'], ['arrive', 1, 'down'], ['press', 4, 'up'], ['press', 5, 'down'], ['arrive', 4, 'up']]}, {'log': ['served:', 'lit', 'ignored', 'lit', 'served:', 'ignored', 'served:', 'ignored', 'ignored', 'served:down'], 'pending': [[2, 'up']]}), ('sampled regression 61', {'floors': 7, 'events': [['arrive', 5, 'up'], ['press', 0, 'down'], ['press', 6, 'up'], ['press', 0, 'down'], ['arrive', 6, 'down'], ['arrive', 2, 'down'], ['press', 3, 'up'], ['press', 0, 'down']]}, {'log': ['served:', 'ignored', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'ignored'], 'pending': [[3, 'up']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('sampled regression 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 67', {'floors': 5, 'events': [['arrive', 1, 'idle'], ['press', 4, 'up'], ['press', 5, 'up'], ['press', 1, 'down'], ['press', 1, 'up'], ['press', 2, 'up'], ['arrive', 3, 'idle']]}, {'log': ['served:', 'ignored', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[1, 'down'], [1, 'up'], [2, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) or (f == top and d == 'up'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle' or f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 11', {'floors': 9, 'events': [['arrive', 2, 'down'], ['arrive', 5, 'idle'], ['press', 8, 'down'], ['press', 9, 'up'], ['press', 5, 'down'], ['press', 4, 'down'], ['press', 8, 'up'], ['press', 9, 'down']]}, {'log': ['served:', 'served:', 'lit', 'ignored', 'lit', 'lit', 'ignored', 'ignored'], 'pending': [[4, 'down'], [5, 'down'], [8, 'down']]}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('control 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]})], [('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('sampled regression 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('sampled regression 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('sampled regression 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 36', {'floors': 9, 'events': [['press', 5, 'down'], ['press', -1, 'down'], ['press', 0, 'down']]}, {'log': ['lit', 'ignored', 'ignored'], 'pending': [[5, 'down']]}), ('sampled regression 54', {'floors': 9, 'events': [['press', 3, 'down'], ['press', 7, 'down'], ['arrive', 2, 'idle'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 1, 'down'], ['arrive', 4, 'down'], ['press', 8, 'up'], ['press', 0, 'down'], ['press', 3, 'down']]}, {'log': ['lit', 'lit', 'served:', 'lit', 'served:', 'lit', 'served:down', 'ignored', 'ignored', 'lit'], 'pending': [[1, 'down'], [3, 'down'], [7, 'down']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('sampled regression 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 56', {'floors': 5, 'events': [['arrive', 3, 'down'], ['press', 2, 'up'], ['press', 0, 'down'], ['press', 4, 'down'], ['arrive', 0, 'up'], ['press', 0, 'down'], ['arrive', 1, 'down'], ['press', 4, 'up'], ['press', 5, 'down'], ['arrive', 4, 'up']]}, {'log': ['served:', 'lit', 'ignored', 'lit', 'served:', 'ignored', 'served:', 'ignored', 'ignored', 'served:down'], 'pending': [[2, 'up']]}), ('sampled regression 61', {'floors': 7, 'events': [['arrive', 5, 'up'], ['press', 0, 'down'], ['press', 6, 'up'], ['press', 0, 'down'], ['arrive', 6, 'down'], ['arrive', 2, 'down'], ['press', 3, 'up'], ['press', 0, 'down']]}, {'log': ['served:', 'ignored', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'ignored'], 'pending': [[3, 'up']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('sampled regression 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('regression: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 67', {'floors': 5, 'events': [['arrive', 1, 'idle'], ['press', 4, 'up'], ['press', 5, 'up'], ['press', 1, 'down'], ['press', 1, 'up'], ['press', 2, 'up'], ['arrive', 3, 'idle']]}, {'log': ['served:', 'ignored', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[1, 'down'], [1, 'up'], [2, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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:
Non-existent terminal buttons register calls that no car will answer.

Hall buttons exist on floors 0..floors-1, except no up button at the top floor and no down button at the bottom floor; other presses are ignored. A registered call lights. A car arriving at a floor serves calls matching its direction; an idle car or a car arriving at a terminal floor (where it must reverse) serves both directions. Log lit/ignored and served:<dirs> (sorted), and list pending calls sorted.

split: open-access


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

N = 1
observations = []
def solve(x):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('sampled regression 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 63', {'floors': 8, 'events': [['press', 2, 'down'], ['press', 5, 'down'], ['press', 8, 'up'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', -1, 'down'], ['arrive', 2, 'idle'], ['press', 0, 'down']]}, {'log': ['lit', 'lit', 'ignored', 'served:', 'lit', 'ignored', 'served:down', 'ignored'], 'pending': [[1, 'down'], [5, 'down']]}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 49', {'floors': 6, 'events': [['press', 3, 'down'], ['press', 0, 'up'], ['arrive', 3, 'idle'], ['arrive', 4, 'idle'], ['arrive', 5, 'down']]}, {'log': ['lit', 'lit', 'served:down', 'served:', 'served:'], 'pending': [[0, 'up']]}), ('sampled regression 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('control 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 19', {'floors': 7, 'events': [['arrive', 6, 'down'], ['press', 0, 'up'], ['press', 1, 'up'], ['press', 1, 'down'], ['arrive', 1, 'idle'], ['arrive', 1, 'down'], ['arrive', 2, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:down,up', 'served:', 'served:', 'lit', 'served:'], 'pending': [[0, 'up'], [4, 'up']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('sampled regression 49', {'floors': 6, 'events': [['press', 3, 'down'], ['press', 0, 'up'], ['arrive', 3, 'idle'], ['arrive', 4, 'idle'], ['arrive', 5, 'down']]}, {'log': ['lit', 'lit', 'served:down', 'served:', 'served:'], 'pending': [[0, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d or (d == 'idle' and c[1] == 'up')))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('sampled regression 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 63', {'floors': 8, 'events': [['press', 2, 'down'], ['press', 5, 'down'], ['press', 8, 'up'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', -1, 'down'], ['arrive', 2, 'idle'], ['press', 0, 'down']]}, {'log': ['lit', 'lit', 'ignored', 'served:', 'lit', 'ignored', 'served:down', 'ignored'], 'pending': [[1, 'down'], [5, 'down']]}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 49', {'floors': 6, 'events': [['press', 3, 'down'], ['press', 0, 'up'], ['arrive', 3, 'idle'], ['arrive', 4, 'idle'], ['arrive', 5, 'down']]}, {'log': ['lit', 'lit', 'served:down', 'served:', 'served:'], 'pending': [[0, 'up']]}), ('sampled regression 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('control 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 19', {'floors': 7, 'events': [['arrive', 6, 'down'], ['press', 0, 'up'], ['press', 1, 'up'], ['press', 1, 'down'], ['arrive', 1, 'idle'], ['arrive', 1, 'down'], ['arrive', 2, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:down,up', 'served:', 'served:', 'lit', 'served:'], 'pending': [[0, 'up'], [4, 'up']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('sampled regression 49', {'floors': 6, 'events': [['press', 3, 'down'], ['press', 0, 'up'], ['arrive', 3, 'idle'], ['arrive', 4, 'idle'], ['arrive', 5, 'down']]}, {'log': ['lit', 'lit', 'served:down', 'served:', 'served:'], 'pending': [[0, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('boundary: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An idle car opening at a floor leaves the second lamp lit.

Hall buttons exist on floors 0..floors-1, except no up button at the top floor and no down button at the bottom floor; other presses are ignored. A registered call lights. A car arriving at a floor serves calls matching its direction; an idle car or a car arriving at a terminal floor (where it must reverse) serves both directions. Log lit/ignored and served:<dirs> (sorted), and list pending calls sorted.

split: open-access


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

N = 1
observations = []
def solve(x):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle'
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]})], [('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 77', {'floors': 6, 'events': [['press', 0, 'up'], ['press', -1, 'up'], ['arrive', 0, 'down'], ['arrive', 5, 'idle'], ['press', 3, 'up'], ['press', 5, 'up'], ['arrive', 5, 'up']]}, {'log': ['lit', 'ignored', 'served:up', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[3, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]}), ('control 32', {'floors': 5, 'events': [['press', -1, 'up'], ['arrive', 4, 'idle'], ['press', 2, 'up'], ['press', -1, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'ignored'], 'pending': [[2, 'up']]})], [('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 60', {'floors': 8, 'events': [['press', 0, 'up'], ['arrive', 0, 'down'], ['arrive', 1, 'idle'], ['press', 7, 'down'], ['press', 4, 'down'], ['arrive', 5, 'idle'], ['arrive', 5, 'idle'], ['press', 7, 'up']]}, {'log': ['lit', 'served:up', 'served:', 'lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[4, 'down'], [7, 'down']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 39', {'floors': 7, 'events': [['press', 4, 'down'], ['press', 1, 'up'], ['press', 6, 'down'], ['arrive', 6, 'up'], ['arrive', 0, 'up'], ['press', 6, 'down'], ['arrive', 1, 'idle'], ['press', 2, 'down']]}, {'log': ['lit', 'lit', 'lit', 'served:down', 'served:', 'lit', 'served:up', 'lit'], 'pending': [[2, 'down'], [4, 'down'], [6, 'down']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f <= top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle' or f == top
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('control 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]})], [('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 77', {'floors': 6, 'events': [['press', 0, 'up'], ['press', -1, 'up'], ['arrive', 0, 'down'], ['arrive', 5, 'idle'], ['press', 3, 'up'], ['press', 5, 'up'], ['arrive', 5, 'up']]}, {'log': ['lit', 'ignored', 'served:up', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[3, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]}), ('control 32', {'floors': 5, 'events': [['press', -1, 'up'], ['arrive', 4, 'idle'], ['press', 2, 'up'], ['press', -1, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'ignored'], 'pending': [[2, 'up']]})], [('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 60', {'floors': 8, 'events': [['press', 0, 'up'], ['arrive', 0, 'down'], ['arrive', 1, 'idle'], ['press', 7, 'down'], ['press', 4, 'down'], ['arrive', 5, 'idle'], ['arrive', 5, 'idle'], ['press', 7, 'up']]}, {'log': ['lit', 'served:up', 'served:', 'lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[4, 'down'], [7, 'down']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('boundary: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('regression: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('sampled regression 39', {'floors': 7, 'events': [['press', 4, 'down'], ['press', 1, 'up'], ['press', 6, 'down'], ['arrive', 6, 'up'], ['arrive', 0, 'up'], ['press', 6, 'down'], ['arrive', 1, 'idle'], ['press', 2, 'down']]}, {'log': ['lit', 'lit', 'lit', 'served:down', 'served:', 'lit', 'served:up', 'lit'], 'pending': [[2, 'down'], [4, 'down'], [6, 'down']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('control 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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 reaching a terminal floor leaves the reversing call lit.

Hall buttons exist on floors 0..floors-1, except no up button at the top floor and no down button at the bottom floor; other presses are ignored. A registered call lights. A car arriving at a floor serves calls matching its direction; an idle car or a car arriving at a terminal floor (where it must reverse) serves both directions. Log lit/ignored and served:<dirs> (sorted), and list pending calls sorted.

split: open-access


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

N = 1
observations = []
def solve(x):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (0 <= f < top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle' or f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('sampled regression 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]}), ('control 13', {'floors': 7, 'events': [['press', 0, 'down'], ['arrive', 4, 'up'], ['press', 3, 'up'], ['arrive', 2, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'served:'], 'pending': [[3, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 53', {'floors': 7, 'events': [['press', 2, 'up'], ['arrive', 3, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 6, 'down'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:', 'lit', 'lit', 'lit', 'served:'], 'pending': [[2, 'up'], [3, 'up'], [4, 'down'], [6, 'down']]}), ('control 32', {'floors': 5, 'events': [['press', -1, 'up'], ['arrive', 4, 'idle'], ['press', 2, 'up'], ['press', -1, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'ignored'], 'pending': [[2, 'up']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 71', {'floors': 10, 'events': [['press', 9, 'down'], ['press', 7, 'down'], ['press', 5, 'up'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'lit', 'lit'], 'pending': [[5, 'up'], [6, 'up'], [7, 'down'], [9, 'down']]}), ('sampled regression 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 66', {'floors': 7, 'events': [['press', 0, 'up'], ['arrive', 1, 'idle'], ['press', -1, 'down'], ['press', -1, 'down'], ['arrive', 0, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up'], ['press', -1, 'down']]}, {'log': ['lit', 'served:', 'ignored', 'ignored', 'served:up', 'lit', 'served:', 'ignored'], 'pending': [[2, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('sampled regression 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('sampled regression 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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):
    top = x['floors'] - 1
    calls = set()
    out = []
    for kind, f, d in x['events']:
        if kind == 'press':
            if not (f <= top) or (f == top and d == 'up') or (f == 0 and d == 'down'):
                out.append('ignored')
                continue
            calls.add((f, d))
            out.append('lit')
        else:
            both = d == 'idle' or f in (0, top)
            served = sorted(c for c in calls if c[0] == f and (both or c[1] == d))
            for c in served:
                calls.discard(c)
            out.append('served:' + ','.join(c[1] for c in served))
    return {'log': out, 'pending': sorted([list(c) for c in calls])}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('sampled regression 1', {'floors': 5, 'events': [['press', -1, 'down'], ['press', 4, 'down'], ['press', 4, 'down'], ['arrive', 3, 'idle'], ['press', 0, 'up'], ['press', 1, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up']]}, {'log': ['ignored', 'lit', 'lit', 'served:', 'lit', 'lit', 'lit', 'served:down'], 'pending': [[0, 'up'], [1, 'down'], [2, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('control 7', {'floors': 5, 'events': [['arrive', 4, 'idle'], ['press', 3, 'down'], ['arrive', 2, 'down'], ['arrive', 3, 'idle'], ['arrive', 3, 'up'], ['press', 1, 'down']]}, {'log': ['served:', 'lit', 'served:', 'served:down', 'served:', 'lit'], 'pending': [[1, 'down']]}), ('control 10', {'floors': 10, 'events': [['press', 7, 'down'], ['press', 3, 'up'], ['press', 3, 'up']]}, {'log': ['lit', 'lit', 'lit'], 'pending': [[3, 'up'], [7, 'down']]}), ('control 13', {'floors': 7, 'events': [['press', 0, 'down'], ['arrive', 4, 'up'], ['press', 3, 'up'], ['arrive', 2, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'served:'], 'pending': [[3, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 9', {'floors': 10, 'events': [['press', -1, 'up'], ['arrive', 3, 'idle'], ['press', 5, 'down'], ['arrive', 5, 'idle'], ['press', 2, 'up'], ['arrive', 9, 'down']]}, {'log': ['ignored', 'served:', 'lit', 'served:down', 'lit', 'served:'], 'pending': [[2, 'up']]}), ('boundary: idle car serves both lamps', {'floors': 6, 'events': [['press', 3, 'up'], ['press', 3, 'down'], ['arrive', 3, 'idle']]}, {'log': ['lit', 'lit', 'served:down,up'], 'pending': []}), ('sampled regression 12', {'floors': 7, 'events': [['press', 5, 'up'], ['press', 6, 'down'], ['arrive', 2, 'idle'], ['arrive', 5, 'down'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored'], 'pending': [[5, 'up'], [6, 'down']]}), ('control 15', {'floors': 10, 'events': [['press', 9, 'up'], ['arrive', 5, 'down'], ['arrive', 9, 'up'], ['press', 0, 'down'], ['press', 10, 'down'], ['press', 2, 'down']]}, {'log': ['ignored', 'served:', 'served:', 'ignored', 'ignored', 'lit'], 'pending': [[2, 'down']]}), ('control 18', {'floors': 9, 'events': [['press', 5, 'down'], ['press', 1, 'down'], ['press', 7, 'down'], ['arrive', 0, 'up'], ['arrive', 3, 'up'], ['press', 7, 'up'], ['press', 5, 'up'], ['press', 8, 'up'], ['arrive', 8, 'up']]}, {'log': ['lit', 'lit', 'lit', 'served:', 'served:', 'lit', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down'], [5, 'down'], [5, 'up'], [7, 'down'], [7, 'up']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 53', {'floors': 7, 'events': [['press', 2, 'up'], ['arrive', 3, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 6, 'down'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:', 'lit', 'lit', 'lit', 'served:'], 'pending': [[2, 'up'], [3, 'up'], [4, 'down'], [6, 'down']]}), ('control 32', {'floors': 5, 'events': [['press', -1, 'up'], ['arrive', 4, 'idle'], ['press', 2, 'up'], ['press', -1, 'up']]}, {'log': ['ignored', 'served:', 'lit', 'ignored'], 'pending': [[2, 'up']]}), ('boundary: down car at the lobby reverses', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'down']]}, {'log': ['lit', 'served:up'], 'pending': []}), ('control 23', {'floors': 10, 'events': [['press', 5, 'up'], ['press', 1, 'up'], ['arrive', 9, 'up'], ['arrive', 9, 'idle'], ['press', 9, 'up'], ['press', 9, 'up'], ['arrive', 1, 'down'], ['arrive', 9, 'up'], ['press', 4, 'up'], ['press', 4, 'down']]}, {'log': ['lit', 'lit', 'served:', 'served:', 'ignored', 'ignored', 'served:', 'served:', 'lit', 'lit'], 'pending': [[1, 'up'], [4, 'down'], [4, 'up'], [5, 'up']]}), ('sampled regression 26', {'floors': 5, 'events': [['press', 4, 'down'], ['press', 0, 'down'], ['arrive', 0, 'up'], ['press', 3, 'up'], ['press', 3, 'up'], ['press', 0, 'up'], ['arrive', 4, 'idle'], ['arrive', 0, 'down'], ['press', 4, 'down']]}, {'log': ['lit', 'ignored', 'served:', 'lit', 'lit', 'lit', 'served:down', 'served:up', 'lit'], 'pending': [[3, 'up'], [4, 'down']]}), ('control 29', {'floors': 6, 'events': [['press', 0, 'up'], ['arrive', 0, 'idle'], ['press', 5, 'up'], ['press', 6, 'down'], ['press', 0, 'up'], ['arrive', 5, 'down']]}, {'log': ['lit', 'served:up', 'ignored', 'ignored', 'lit', 'served:'], 'pending': [[0, 'up']]})], [('regression: up car at the top floor reverses', {'floors': 6, 'events': [['press', 5, 'down'], ['arrive', 5, 'up']]}, {'log': ['lit', 'served:down'], 'pending': []}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 71', {'floors': 10, 'events': [['press', 9, 'down'], ['press', 7, 'down'], ['press', 5, 'up'], ['press', 6, 'up']]}, {'log': ['lit', 'lit', 'lit', 'lit'], 'pending': [[5, 'up'], [6, 'up'], [7, 'down'], [9, 'down']]}), ('sampled regression 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('boundary: passing car in the other direction', {'floors': 6, 'events': [['press', 2, 'down'], ['arrive', 2, 'up']]}, {'log': ['lit', 'served:'], 'pending': [[2, 'down']]}), ('control 34', {'floors': 5, 'events': [['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 3, 'idle'], ['arrive', 1, 'idle'], ['arrive', 0, 'down'], ['arrive', 2, 'down'], ['arrive', 1, 'down'], ['press', 1, 'down'], ['press', 4, 'up'], ['arrive', 3, 'down']]}, {'log': ['served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'served:', 'lit', 'ignored', 'served:'], 'pending': [[1, 'down']]}), ('control 37', {'floors': 7, 'events': [['arrive', 4, 'up'], ['press', 1, 'up'], ['arrive', 2, 'down'], ['press', 4, 'down'], ['arrive', 0, 'idle'], ['press', 4, 'down']]}, {'log': ['served:', 'lit', 'served:', 'lit', 'served:', 'lit'], 'pending': [[1, 'up'], [4, 'down']]}), ('control 40', {'floors': 9, 'events': [['arrive', 1, 'idle'], ['press', 7, 'down'], ['arrive', 0, 'down'], ['press', -1, 'up']]}, {'log': ['served:', 'lit', 'served:', 'ignored'], 'pending': [[7, 'down']]})], [('regression: up button at the top floor', {'floors': 6, 'events': [['press', 5, 'up'], ['press', 5, 'down']]}, {'log': ['ignored', 'lit'], 'pending': [[5, 'down']]}), ('boundary: floor above the shaft', {'floors': 6, 'events': [['press', 6, 'down'], ['press', -1, 'up']]}, {'log': ['ignored', 'ignored'], 'pending': []}), ('sampled regression 4', {'floors': 6, 'events': [['arrive', 2, 'up'], ['press', 1, 'up'], ['press', 5, 'down'], ['press', 1, 'down'], ['arrive', 4, 'up'], ['arrive', 3, 'up'], ['arrive', 0, 'idle'], ['arrive', 0, 'idle'], ['arrive', 5, 'down'], ['press', 0, 'down']]}, {'log': ['served:', 'lit', 'lit', 'lit', 'served:', 'served:', 'served:', 'served:', 'served:down', 'ignored'], 'pending': [[1, 'down'], [1, 'up']]}), ('control 66', {'floors': 7, 'events': [['press', 0, 'up'], ['arrive', 1, 'idle'], ['press', -1, 'down'], ['press', -1, 'down'], ['arrive', 0, 'down'], ['press', 2, 'up'], ['arrive', 4, 'up'], ['press', -1, 'down']]}, {'log': ['lit', 'served:', 'ignored', 'ignored', 'served:up', 'lit', 'served:', 'ignored'], 'pending': [[2, 'up']]}), ('boundary: down button at the lobby', {'floors': 6, 'events': [['press', 0, 'down'], ['press', 0, 'up']]}, {'log': ['ignored', 'lit'], 'pending': [[0, 'up']]}), ('sampled regression 45', {'floors': 5, 'events': [['arrive', 4, 'up'], ['arrive', 2, 'up'], ['press', -1, 'up'], ['press', 4, 'down'], ['press', 3, 'up'], ['press', 4, 'down'], ['arrive', 2, 'up']]}, {'log': ['served:', 'served:', 'ignored', 'lit', 'lit', 'lit', 'served:'], 'pending': [[3, 'up'], [4, 'down']]}), ('sampled regression 48', {'floors': 9, 'events': [['arrive', 8, 'idle'], ['press', 2, 'down'], ['press', 2, 'down'], ['press', 9, 'down'], ['press', -1, 'up'], ['arrive', 0, 'idle'], ['press', 8, 'down']]}, {'log': ['served:', 'lit', 'lit', 'ignored', 'ignored', 'served:', 'lit'], 'pending': [[2, 'down'], [8, 'down']]}), ('sampled regression 51', {'floors': 7, 'events': [['press', 7, 'down'], ['press', 4, 'down'], ['press', 6, 'down']]}, {'log': ['ignored', 'lit', 'lit'], 'pending': [[4, 'down'], [6, 'down']]})]]
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:
Top-floor calls are ignored or basement presses are registered.

Hall buttons exist on floors 0..floors-1, except no up button at the top floor and no down button at the bottom floor; other presses are ignored. A registered call lights. A car arriving at a floor serves calls matching its direction; an idle car or a car arriving at a terminal floor (where it must reverse) serves both directions. Log lit/ignored and served:<dirs> (sorted), and list pending calls sorted.

split: open-access


prompt:
A car is reactivated at exactly 45 s, or reactivation runs past the fleet size.

Samples [t, demand, max wait]. If the max wait exceeds 45 s and some car is shut down, one car is reactivated and the low-demand timer cleared. Otherwise, while demand < low_demand, a timer runs from the first low sample; once it has run 600 s or more and more than min_active cars are active, one car shuts down and the timer restarts at that time. Any sample with normal demand clears the timer. Output active cars per sample.

split: open-access


prompt:
Cars are shut down on every quiet sample after the first shutdown.

Samples [t, demand, max wait]. If the max wait exceeds 45 s and some car is shut down, one car is reactivated and the low-demand timer cleared. Otherwise, while demand < low_demand, a timer runs from the first low sample; once it has run 600 s or more and more than min_active cars are active, one car shuts down and the timer restarts at that time. Any sample with normal demand clears the timer. Output active cars per sample.

split: open-access


prompt:
The group shuts down below the minimum number of active cars.

Samples [t, demand, max wait]. If the max wait exceeds 45 s and some car is shut down, one car is reactivated and the low-demand timer cleared. Otherwise, while demand < low_demand, a timer runs from the first low sample; once it has run 600 s or more and more than min_active cars are active, one car shuts down and the timer restarts at that time. Any sample with normal demand clears the timer. Output active cars per sample.

split: open-access


prompt:
A brief quiet spell after busy traffic triggers a shutdown.

Samples [t, demand, max wait]. If the max wait exceeds 45 s and some car is shut down, one car is reactivated and the low-demand timer cleared. Otherwise, while demand < low_demand, a timer runs from the first low sample; once it has run 600 s or more and more than min_active cars are active, one car shuts down and the timer restarts at that time. Any sample with normal demand clears the timer. Output active cars per sample.

split: open-access