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

N = 1
observations = []
def solve(x):
    smoke = set(x['smoke'])
    des, alt = x['designated'], x['alternate']
    recall = alt if des in smoke and alt not in smoke else des
    res = {}
    for c in x['cars']:
        f = c['floor']
        if not c['moving']:
            res[c['id']] = ['travel', recall]
        elif (c['dir'] == 'up' and recall > f) or (c['dir'] == 'down' and recall < f):
            res[c['id']] = ['nonstop', recall]
        else:
            nxt = f + 1 if c['dir'] == 'up' else f - 1
            res[c['id']] = ['reverse', min(max(nxt, 0), x['top'])]
    return {'recall': recall, 'cars': res}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('control 1', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [11], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 10, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 9, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 1], 'L2': ['travel', 0], 'L3': ['nonstop', 0]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('boundary: smoke at both recall floors', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0, 5], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0]}}), ('control 4', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [6, 11], 'cars': [{'id': 'L1', 'floor': 1, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0]}}), ('control 7', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 7, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 1, 'moving': True, 'dir': 'down'}]}, {'recall': 1, 'cars': {'L1': ['reverse', 8], 'L2': ['reverse', 0]}}), ('control 10', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': False, 'dir': 'idle'}]}, {'recall': 1, 'cars': {'L1': ['travel', 1]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 6', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 10, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 2, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['open', 0]}}), ('control 52', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 1]}}), ('boundary: smoke elsewhere only', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [7], 'cars': [{'id': 'L1', 'floor': 6, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0]}}), ('control 12', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 10, 'moving': True, 'dir': 'up'}]}, {'recall': 2, 'cars': {'L1': ['travel', 2], 'L2': ['reverse', 11]}}), ('control 15', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [7, 0], 'cars': [{'id': 'L1', 'floor': 4, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 8, 'moving': True, 'dir': 'down'}]}, {'recall': 1, 'cars': {'L1': ['travel', 1], 'L2': ['travel', 1], 'L3': ['nonstop', 1]}}), ('control 18', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [8], 'cars': [{'id': 'L1', 'floor': 6, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 6, 'moving': True, 'dir': 'down'}, {'id': 'L3', 'floor': 2, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['nonstop', 0], 'L3': ['travel', 0]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 25', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [10, 5], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 1, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0], 'L2': ['travel', 0], 'L3': ['travel', 0]}}), ('boundary: moving away upwards', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 4, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 5]}}), ('boundary: moving away at the top', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': True, 'dir': 'up'}]}, {'recall': 5, 'cars': {'L1': ['reverse', 11]}}), ('control 23', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 3, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 8, 'moving': True, 'dir': 'down'}, {'id': 'L3', 'floor': 1, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0], 'L2': ['nonstop', 0], 'L3': ['reverse', 2]}}), ('control 26', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [10, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 7, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['nonstop', 0]}}), ('control 29', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [6], 'cars': [{'id': 'L1', 'floor': 9, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('control 45', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [4, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 1]}}), ('boundary: moving up towards the alternate floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 2, 'moving': True, 'dir': 'up'}]}, {'recall': 5, 'cars': {'L1': ['nonstop', 5]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('control 34', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 11, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 11, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 11, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['reverse', 11]}}), ('control 37', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [9, 8], 'cars': [{'id': 'L1', 'floor': 1, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 2], 'L2': ['travel', 0]}}), ('control 40', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [5, 3, 0], 'cars': [{'id': 'L1', 'floor': 3, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 10, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 4], 'L2': ['reverse', 11]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 6', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 10, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 2, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['open', 0]}}), ('control 79', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 7, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 4, 'moving': True, 'dir': 'up'}, {'id': 'L3', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 5], 'L3': ['reverse', 0]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('control 45', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [4, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 1]}}), ('control 48', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [1], 'cars': [{'id': 'L1', 'floor': 4, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0], 'L2': ['travel', 0]}}), ('control 51', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 4, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 10], 'L2': ['travel', 0]}})]]
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):
    smoke = set(x['smoke'])
    des, alt = x['designated'], x['alternate']
    recall = alt if des in smoke and alt not in smoke else des
    res = {}
    for c in x['cars']:
        f = c['floor']
        if f == recall:
            res[c['id']] = ['open', recall]
        elif not c['moving']:
            res[c['id']] = ['travel', recall]
        elif (c['dir'] == 'up' and recall > f) or (c['dir'] == 'down' and recall < f):
            res[c['id']] = ['nonstop', recall]
        else:
            nxt = f + 1 if c['dir'] == 'up' else f - 1
            res[c['id']] = ['reverse', min(max(nxt, 0), x['top'])]
    return {'recall': recall, 'cars': res}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('control 1', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [11], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 10, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 9, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 1], 'L2': ['travel', 0], 'L3': ['nonstop', 0]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('boundary: smoke at both recall floors', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0, 5], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0]}}), ('control 4', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [6, 11], 'cars': [{'id': 'L1', 'floor': 1, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0]}}), ('control 7', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 7, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 1, 'moving': True, 'dir': 'down'}]}, {'recall': 1, 'cars': {'L1': ['reverse', 8], 'L2': ['reverse', 0]}}), ('control 10', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': False, 'dir': 'idle'}]}, {'recall': 1, 'cars': {'L1': ['travel', 1]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 6', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 10, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 2, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['open', 0]}}), ('control 52', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 1]}}), ('boundary: smoke elsewhere only', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [7], 'cars': [{'id': 'L1', 'floor': 6, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0]}}), ('control 12', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 10, 'moving': True, 'dir': 'up'}]}, {'recall': 2, 'cars': {'L1': ['travel', 2], 'L2': ['reverse', 11]}}), ('control 15', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [7, 0], 'cars': [{'id': 'L1', 'floor': 4, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 8, 'moving': True, 'dir': 'down'}]}, {'recall': 1, 'cars': {'L1': ['travel', 1], 'L2': ['travel', 1], 'L3': ['nonstop', 1]}}), ('control 18', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [8], 'cars': [{'id': 'L1', 'floor': 6, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 6, 'moving': True, 'dir': 'down'}, {'id': 'L3', 'floor': 2, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['nonstop', 0], 'L3': ['travel', 0]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 25', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [10, 5], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 1, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0], 'L2': ['travel', 0], 'L3': ['travel', 0]}}), ('boundary: moving away upwards', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 4, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 5]}}), ('boundary: moving away at the top', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 11, 'moving': True, 'dir': 'up'}]}, {'recall': 5, 'cars': {'L1': ['reverse', 11]}}), ('control 23', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 3, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 8, 'moving': True, 'dir': 'down'}, {'id': 'L3', 'floor': 1, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0], 'L2': ['nonstop', 0], 'L3': ['reverse', 2]}}), ('control 26', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [10, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 7, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['nonstop', 0]}}), ('control 29', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [6], 'cars': [{'id': 'L1', 'floor': 9, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('control 45', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [4, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 1]}}), ('boundary: moving up towards the alternate floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 2, 'moving': True, 'dir': 'up'}]}, {'recall': 5, 'cars': {'L1': ['nonstop', 5]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('control 34', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 11, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 11, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 11, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['reverse', 11]}}), ('control 37', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [9, 8], 'cars': [{'id': 'L1', 'floor': 1, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 2], 'L2': ['travel', 0]}}), ('control 40', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [5, 3, 0], 'cars': [{'id': 'L1', 'floor': 3, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 10, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 4], 'L2': ['reverse', 11]}})], [('regression: parked at the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['open', 0]}}), ('boundary: passing the recall floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 0]}}), ('sampled regression 6', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 10, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 2, 'moving': False, 'dir': 'idle'}, {'id': 'L3', 'floor': 0, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 11], 'L2': ['travel', 0], 'L3': ['open', 0]}}), ('control 79', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 7, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 4, 'moving': True, 'dir': 'up'}, {'id': 'L3', 'floor': 0, 'moving': True, 'dir': 'down'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 5], 'L3': ['reverse', 0]}}), ('boundary: smoke at the designated floor', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [0], 'cars': [{'id': 'L1', 'floor': 6, 'moving': False, 'dir': 'idle'}]}, {'recall': 5, 'cars': {'L1': ['travel', 5]}}), ('control 45', {'designated': 0, 'alternate': 5, 'top': 11, 'smoke': [4, 11], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'down'}, {'id': 'L2', 'floor': 0, 'moving': True, 'dir': 'up'}]}, {'recall': 0, 'cars': {'L1': ['nonstop', 0], 'L2': ['reverse', 1]}}), ('control 48', {'designated': 0, 'alternate': 2, 'top': 11, 'smoke': [1], 'cars': [{'id': 'L1', 'floor': 4, 'moving': False, 'dir': 'idle'}, {'id': 'L2', 'floor': 5, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['travel', 0], 'L2': ['travel', 0]}}), ('control 51', {'designated': 0, 'alternate': 1, 'top': 11, 'smoke': [], 'cars': [{'id': 'L1', 'floor': 9, 'moving': True, 'dir': 'up'}, {'id': 'L2', 'floor': 4, 'moving': False, 'dir': 'idle'}]}, {'recall': 0, 'cars': {'L1': ['reverse', 10], 'L2': ['travel', 0]}})]]
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 parked at the recall floor keeps its doors shut or a passing car opens its doors.

The recall floor is the designated floor unless smoke is detected there and not at the alternate floor. Each car: stationary at the recall floor -> open; stationary elsewhere -> travel to recall; moving towards the recall floor (strictly) -> nonstop to it; otherwise (moving away, or passing the recall floor) -> reverse after stopping at the next floor in its direction, clipped to 0..top.

split: open-access


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

N = 1
observations = []
def solve(x):
    lo, hi = x['zone']
    served = {0} | set(range(lo, hi)) | set(x['sky_lobbies'])
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (abs(s - f), -s))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 6', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [23, 24, 8, 10, 36, 7]}, [[True, 23], [True, 24], [False, 0], [False, 20], [False, 25], [False, 0]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('sampled regression 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('sampled regression 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 17', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 9], 'requests': [1, 25, 34, 21, 29, 10]}, [[False, 0], [True, 25], [False, 27], [True, 21], [False, 27], [False, 9]]), ('sampled regression 11', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [40, 10, 38, 22, -1, 37]}, [[False, 19], [True, 10], [False, 19], [False, 19], [False, 0], [False, 19]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('sampled regression 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('sampled regression 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('control 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('sampled regression 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]]), ('sampled regression 35', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [25, 5], 'requests': [0, 30, 8, 17, 9, 40]}, [[True, 0], [False, 25], [False, 10], [False, 15], [False, 10], [False, 25]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]]), ('sampled regression 44', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [], 'requests': [40, 9, 17, 16, 9, 29]}, [[False, 32], [False, 0], [False, 20], [False, 20], [False, 0], [True, 29]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('control 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 43', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 9], 'requests': [24, 9]}, [[True, 24], [True, 9]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]]), ('control 53', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [6, 18, 14]}, [[False, 0], [False, 20], [False, 20]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('sampled regression 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 54', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [], 'requests': [26, 23]}, [[True, 26], [True, 23]])]]
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):
    lo, hi = x['zone']
    served = {0} | set(range(lo + 1, hi + 1)) | set(x['sky_lobbies'])
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (abs(s - f), -s))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 6', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [23, 24, 8, 10, 36, 7]}, [[True, 23], [True, 24], [False, 0], [False, 20], [False, 25], [False, 0]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('sampled regression 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('sampled regression 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 17', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 9], 'requests': [1, 25, 34, 21, 29, 10]}, [[False, 0], [True, 25], [False, 27], [True, 21], [False, 27], [False, 9]]), ('sampled regression 11', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [40, 10, 38, 22, -1, 37]}, [[False, 19], [True, 10], [False, 19], [False, 19], [False, 0], [False, 19]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('sampled regression 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('sampled regression 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('control 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('sampled regression 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]]), ('sampled regression 35', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [25, 5], 'requests': [0, 30, 8, 17, 9, 40]}, [[True, 0], [False, 25], [False, 10], [False, 15], [False, 10], [False, 25]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]]), ('sampled regression 44', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [], 'requests': [40, 9, 17, 16, 9, 29]}, [[False, 32], [False, 0], [False, 20], [False, 20], [False, 0], [True, 29]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('control 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 43', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 9], 'requests': [24, 9]}, [[True, 24], [True, 9]])], [('regression: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]]), ('control 53', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [6, 18, 14]}, [[False, 0], [False, 20], [False, 20]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('sampled regression 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 54', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [], 'requests': [26, 23]}, [[True, 26], [True, 23]])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The top floor of the zone is refused.

A zoned express car serves the lobby (0), the inclusive zone [lo, hi] and its sky lobbies, all within 0..floors-1. Each requested floor is accepted ([True, f]) or rejected with the nearest served floor as a suggestion, ties to the higher floor ([False, suggestion]).

split: open-access


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

N = 1
observations = []
def solve(x):
    lo, hi = x['zone']
    served = {0} | set(range(lo, hi + 1)) | set(x['sky_lobbies'])
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (abs(s - f), s))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 50', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 9], 'requests': [27, 24, 9, 5, 12, 14]}, [[True, 27], [True, 24], [True, 9], [False, 9], [False, 15], [False, 15]]), ('control 3', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25, 30], 'requests': [6, 8, 22]}, [[False, 0], [False, 0], [True, 22]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('control 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('control 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 13', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [30], 'requests': [14, 16, 0, 5, 11, 37]}, [[True, 14], [True, 16], [True, 0], [False, 10], [True, 11], [False, 30]]), ('control 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('control 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]]), ('control 21', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [5], 'requests': [25, 20, 29, 29, 31, 32]}, [[False, 20], [True, 20], [False, 20], [False, 20], [False, 20], [False, 20]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 6', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [23, 24, 8, 10, 36, 7]}, [[True, 23], [True, 24], [False, 0], [False, 20], [False, 25], [False, 0]]), ('control 24', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [27, 4, 24]}, [[False, 24], [False, 0], [True, 24]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('control 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('control 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('control 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 50', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 9], 'requests': [27, 24, 9, 5, 12, 14]}, [[True, 27], [True, 24], [True, 9], [False, 9], [False, 15], [False, 15]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('control 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]])]]
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):
    lo, hi = x['zone']
    served = {0} | set(range(lo, hi + 1)) | set(x['sky_lobbies'])
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (s < f, abs(s - f)))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 50', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 9], 'requests': [27, 24, 9, 5, 12, 14]}, [[True, 27], [True, 24], [True, 9], [False, 9], [False, 15], [False, 15]]), ('control 3', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25, 30], 'requests': [6, 8, 22]}, [[False, 0], [False, 0], [True, 22]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('control 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('control 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 13', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [30], 'requests': [14, 16, 0, 5, 11, 37]}, [[True, 14], [True, 16], [True, 0], [False, 10], [True, 11], [False, 30]]), ('control 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('control 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]]), ('control 21', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [5], 'requests': [25, 20, 29, 29, 31, 32]}, [[False, 20], [True, 20], [False, 20], [False, 20], [False, 20], [False, 20]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 6', {'floors': 40, 'zone': [20, 25], 'sky_lobbies': [], 'requests': [23, 24, 8, 10, 36, 7]}, [[True, 23], [True, 24], [False, 0], [False, 20], [False, 25], [False, 0]]), ('control 24', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [27, 4, 24]}, [[False, 24], [False, 0], [True, 24]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('control 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('control 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('control 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]])], [('regression: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('boundary: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 50', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 9], 'requests': [27, 24, 9, 5, 12, 14]}, [[True, 27], [True, 24], [True, 9], [False, 9], [False, 15], [False, 15]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]]), ('boundary: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('control 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]])]]
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:
Equidistant suggestions point downwards.

A zoned express car serves the lobby (0), the inclusive zone [lo, hi] and its sky lobbies, all within 0..floors-1. Each requested floor is accepted ([True, f]) or rejected with the nearest served floor as a suggestion, ties to the higher floor ([False, suggestion]).

split: open-access


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

N = 1
observations = []
def solve(x):
    lo, hi = x['zone']
    served = {0} | set(range(lo, hi + 1))
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (abs(s - f), -s))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 10', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [30], 'requests': [37, 4, 31]}, [[False, 30], [False, 0], [False, 30]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('control 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('control 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('sampled regression 17', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 9], 'requests': [1, 25, 34, 21, 29, 10]}, [[False, 0], [True, 25], [False, 27], [True, 21], [False, 27], [False, 9]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('sampled regression 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('control 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]])], [('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('sampled regression 25', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [9, 30], 'requests': [30, 37, 1]}, [[True, 30], [False, 30], [False, 0]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('sampled regression 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('sampled regression 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]])], [('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 55', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [9], 'requests': [25, 22, 14]}, [[True, 25], [True, 22], [False, 9]]), ('sampled regression 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('sampled regression 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]])], [('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 74', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [30], 'requests': [10, 34, 21]}, [[True, 10], [False, 30], [False, 15]]), ('sampled regression 43', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 9], 'requests': [24, 9]}, [[True, 24], [True, 9]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('control 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]])]]
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):
    lo, hi = x['zone']
    served = {0} | set(range(lo, hi + 1)) | {s for s in x['sky_lobbies'] if lo <= s <= hi}
    cand = sorted(s for s in served if 0 <= s < x['floors'])
    res = []
    for f in x['requests']:
        if f in cand:
            res.append([True, f])
        else:
            best = min(cand, key=lambda s: (abs(s - f), -s))
            res.append([False, best])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 10', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [30], 'requests': [37, 4, 31]}, [[False, 30], [False, 0], [False, 30]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('sampled regression 1', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [9, 30], 'requests': [28, 30, 24]}, [[False, 30], [True, 30], [False, 30]]), ('control 4', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [39, 4]}, [[False, 19], [False, 0]]), ('control 7', {'floors': 40, 'zone': [10, 22], 'sky_lobbies': [], 'requests': [33, 3, 3, 19, 14]}, [[False, 22], [False, 0], [False, 0], [True, 19], [True, 14]])], [('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('sampled regression 17', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 9], 'requests': [1, 25, 34, 21, 29, 10]}, [[False, 0], [True, 25], [False, 27], [True, 21], [False, 27], [False, 9]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('control 12', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [5, 25], 'requests': [31, 15, 26, 21, 33]}, [[False, 27], [True, 15], [True, 26], [True, 21], [False, 27]]), ('sampled regression 15', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30, 5], 'requests': [20, 16, 37, 2]}, [[True, 20], [True, 16], [False, 30], [False, 0]]), ('control 18', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [32, 19]}, [[False, 19], [True, 19]])], [('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('sampled regression 25', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [9, 30], 'requests': [30, 37, 1]}, [[True, 30], [False, 30], [False, 0]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('sampled regression 23', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [25, 9], 'requests': [27, 0, 11, 21, 32, 14]}, [[False, 25], [True, 0], [False, 9], [True, 21], [False, 25], [False, 15]]), ('control 26', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [5, 25], 'requests': [22, 21, 11]}, [[True, 22], [True, 21], [False, 15]]), ('sampled regression 29', {'floors': 40, 'zone': [15, 27], 'sky_lobbies': [25, 5], 'requests': [2, 33, 31, 2, 7]}, [[False, 0], [False, 27], [False, 27], [False, 0], [False, 5]])], [('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('sampled regression 55', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [9], 'requests': [25, 22, 14]}, [[True, 25], [True, 22], [False, 9]]), ('sampled regression 32', {'floors': 40, 'zone': [15, 20], 'sky_lobbies': [30], 'requests': [2, 20, 28]}, [[False, 0], [True, 20], [False, 30]]), ('boundary: bottom of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [10, 9]}, [[True, 10], [False, 10]]), ('boundary: midway between lobby and zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [5]}, [[False, 10]]), ('sampled regression 34', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [9, 30], 'requests': [31, 3, 34, 24]}, [[False, 30], [False, 0], [False, 30], [True, 24]]), ('sampled regression 37', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 30], 'requests': [39, 22, 18, 9, 40]}, [[False, 30], [True, 22], [False, 20], [False, 5], [False, 30]]), ('control 40', {'floors': 40, 'zone': [15, 24], 'sky_lobbies': [], 'requests': [36, 23, 1, 39, 21, 26]}, [[False, 24], [True, 23], [False, 0], [False, 24], [True, 21], [False, 24]])], [('regression: sky lobby transfer', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [9], 'requests': [9, 8]}, [[True, 9], [False, 9]]), ('sampled regression 74', {'floors': 40, 'zone': [10, 15], 'sky_lobbies': [30], 'requests': [10, 34, 21]}, [[True, 10], [False, 30], [False, 15]]), ('sampled regression 43', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [5, 9], 'requests': [24, 9]}, [[True, 24], [True, 9]]), ('regression: floor just below the sky lobby', {'floors': 40, 'zone': [20, 29], 'sky_lobbies': [15], 'requests': [14, 17]}, [[False, 15], [False, 15]]), ('boundary: top of the zone', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [19, 20]}, [[True, 19], [False, 19]]), ('control 45', {'floors': 40, 'zone': [10, 19], 'sky_lobbies': [], 'requests': [11, 35, 34, 2, 19, 25]}, [[True, 11], [False, 19], [False, 19], [False, 0], [True, 19], [False, 19]]), ('control 48', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [25], 'requests': [26, 30, 33, 4, 17, 40]}, [[True, 26], [True, 30], [False, 32], [False, 0], [False, 20], [False, 32]]), ('control 51', {'floors': 40, 'zone': [20, 32], 'sky_lobbies': [5], 'requests': [30, 40]}, [[True, 30], [False, 32]])]]
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:
Passengers are refused at the sky lobby where they transfer.

A zoned express car serves the lobby (0), the inclusive zone [lo, hi] and its sky lobbies, all within 0..floors-1. Each requested floor is accepted ([True, f]) or rejected with the nearest served floor as a suggestion, ties to the higher floor ([False, suggestion]).

split: open-access


prompt:
Round trip times assume every car leaves the lobby full.

Up-peak analysis with N floors above the lobby, P = 0.8*capacity passengers per trip (fractional), probable stops S = N(1-(1-1/N)^P), highest reversal floor H = N - sum_{i=1}^{N-1}(i/N)^P, RTT = 2*H*tv + (S+1)*ts + 2*P*tp, interval = RTT/cars and 5-minute handling capacity HC5 = 300*P*cars/RTT. Values rounded to 2 decimals.

split: open-access


prompt:
The number of probable stops is overstated.

Up-peak analysis with N floors above the lobby, P = 0.8*capacity passengers per trip (fractional), probable stops S = N(1-(1-1/N)^P), highest reversal floor H = N - sum_{i=1}^{N-1}(i/N)^P, RTT = 2*H*tv + (S+1)*ts + 2*P*tp, interval = RTT/cars and 5-minute handling capacity HC5 = 300*P*cars/RTT. Values rounded to 2 decimals.

split: open-access


prompt:
The highest reversal floor is one floor low or high.

Up-peak analysis with N floors above the lobby, P = 0.8*capacity passengers per trip (fractional), probable stops S = N(1-(1-1/N)^P), highest reversal floor H = N - sum_{i=1}^{N-1}(i/N)^P, RTT = 2*H*tv + (S+1)*ts + 2*P*tp, interval = RTT/cars and 5-minute handling capacity HC5 = 300*P*cars/RTT. Values rounded to 2 decimals.

split: open-access


prompt:
The round trip omits the stop at the main lobby.

Up-peak analysis with N floors above the lobby, P = 0.8*capacity passengers per trip (fractional), probable stops S = N(1-(1-1/N)^P), highest reversal floor H = N - sum_{i=1}^{N-1}(i/N)^P, RTT = 2*H*tv + (S+1)*ts + 2*P*tp, interval = RTT/cars and 5-minute handling capacity HC5 = 300*P*cars/RTT. Values rounded to 2 decimals.

split: open-access


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

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

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

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

prompt:
A car that is already passing the call floor is allocated the call.

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

split: open-access