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

N = 1
observations = []
def solve(x):
    waits = []
    for reg, ans in x['calls']:
        if ans is None:
            waits.append(x['end_s'] - reg)
        else:
            waits.append(max(0, ans - reg))
    if not waits:
        return {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}
    longs = sum(1 for w in waits if w > 60)
    return {'avg': round(sum(waits) / len(waits)), 'long_permille': longs * 1000 // len(waits), 'max': max(waits), 'count': len(waits)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('sampled regression 9', {'end_s': 600, 'calls': [[575, 595], [530, None], [76, None], [511, None], [173, 178], [76, 137], [46, 51], [370, 520]]}, {'avg': 115, 'long_permille': 625, 'max': 524, 'count': 8}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 1', {'end_s': 600, 'calls': [[93, 138], [499, 519], [546, None], [485, None], [376, 526], [329, 419], [42, None], [303, None]]}, {'avg': 166, 'long_permille': 625, 'max': 558, 'count': 8}), ('control 4', {'end_s': 600, 'calls': [[15, None], [80, 100], [304, 324], [560, 557], [73, 78], [574, None]]}, {'avg': 109, 'long_permille': 166, 'max': 585, 'count': 6}), ('sampled regression 7', {'end_s': 600, 'calls': [[196, 216], [228, 248], [100, None], [381, 471], [370, 415], [56, 76]]}, {'avg': 115, 'long_permille': 333, 'max': 500, 'count': 6})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('sampled regression 27', {'end_s': 600, 'calls': [[441, None], [579, None], [47, 137], [447, None]]}, {'avg': 105, 'long_permille': 750, 'max': 159, 'count': 4}), ('control 6', {'end_s': 600, 'calls': [[541, None], [503, 502], [554, None], [543, None], [284, 434]]}, {'avg': 62, 'long_permille': 200, 'max': 150, 'count': 5}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('control 12', {'end_s': 600, 'calls': [[549, None], [34, 94], [153, 243]]}, {'avg': 67, 'long_permille': 333, 'max': 90, 'count': 3}), ('sampled regression 15', {'end_s': 600, 'calls': [[427, 472], [290, 440], [125, None], [18, 79], [88, 178], [156, 306], [7, None], [120, None]]}, {'avg': 255, 'long_permille': 875, 'max': 593, 'count': 8}), ('control 18', {'end_s': 600, 'calls': [[508, 528]]}, {'avg': 20, 'long_permille': 0, 'max': 20, 'count': 1})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('sampled regression 61', {'end_s': 600, 'calls': [[410, 415], [504, 564], [213, 258], [291, None], [359, None], [364, 369], [125, None]]}, {'avg': 162, 'long_permille': 428, 'max': 475, 'count': 7}), ('control 13', {'end_s': 600, 'calls': [[451, 511], [494, 539], [553, None], [26, None], [306, 367], [164, 314], [548, None], [406, 556]]}, {'avg': 142, 'long_permille': 500, 'max': 574, 'count': 8}), ('boundary: no calls', {'end_s': 600, 'calls': []}, {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 23', {'end_s': 600, 'calls': [[121, 141], [388, None], [577, None]]}, {'avg': 85, 'long_permille': 333, 'max': 212, 'count': 3}), ('control 26', {'end_s': 600, 'calls': [[205, 225], [336, 381]]}, {'avg': 32, 'long_permille': 0, 'max': 45, 'count': 2}), ('sampled regression 29', {'end_s': 600, 'calls': [[26, 31], [282, 287], [487, 577], [127, 187], [568, None], [130, 280], [335, 395], [184, 274]]}, {'avg': 61, 'long_permille': 375, 'max': 150, 'count': 8})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('sampled regression 9', {'end_s': 600, 'calls': [[575, 595], [530, None], [76, None], [511, None], [173, 178], [76, 137], [46, 51], [370, 520]]}, {'avg': 115, 'long_permille': 625, 'max': 524, 'count': 8}), ('sampled regression 20', {'end_s': 600, 'calls': [[520, None], [447, 467], [161, 221], [506, 511], [146, 296], [576, None], [73, 223], [194, 214]]}, {'avg': 63, 'long_permille': 375, 'max': 150, 'count': 8}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 34', {'end_s': 600, 'calls': [[526, 531], [100, 160], [338, None], [152, 242], [413, 433], [56, 117]]}, {'avg': 83, 'long_permille': 500, 'max': 262, 'count': 6}), ('control 37', {'end_s': 600, 'calls': [[542, 547], [483, None], [421, 418], [216, None]]}, {'avg': 126, 'long_permille': 500, 'max': 384, 'count': 4}), ('control 40', {'end_s': 600, 'calls': [[286, 346], [342, None], [309, 308], [91, 96], [519, 524], [518, None], [12, 73]]}, {'avg': 67, 'long_permille': 428, 'max': 258, 'count': 7})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('sampled regression 27', {'end_s': 600, 'calls': [[441, None], [579, None], [47, 137], [447, None]]}, {'avg': 105, 'long_permille': 750, 'max': 159, 'count': 4}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('boundary: no calls', {'end_s': 600, 'calls': []}, {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}), ('control 45', {'end_s': 600, 'calls': [[54, 204], [360, None], [102, None], [487, None], [396, None]]}, {'avg': 241, 'long_permille': 1000, 'max': 498, 'count': 5}), ('sampled regression 48', {'end_s': 600, 'calls': [[235, 234], [112, 202], [453, 498], [10, 30], [166, 186], [359, 358], [466, 471]]}, {'avg': 25, 'long_permille': 142, 'max': 90, 'count': 7}), ('sampled regression 51', {'end_s': 600, 'calls': [[553, None], [377, 422], [370, None], [180, 241]]}, {'avg': 95, 'long_permille': 500, 'max': 230, 'count': 4})]]
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):
    waits = []
    for reg, ans in x['calls']:
        if ans is None:
            waits.append(x['end_s'] - reg)
        else:
            waits.append(max(0, ans - reg))
    if not waits:
        return {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}
    longs = sum(1 for w in waits if w > 60)
    return {'avg': -(-sum(waits) // len(waits)), 'long_permille': longs * 1000 // len(waits), 'max': max(waits), 'count': len(waits)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('sampled regression 9', {'end_s': 600, 'calls': [[575, 595], [530, None], [76, None], [511, None], [173, 178], [76, 137], [46, 51], [370, 520]]}, {'avg': 115, 'long_permille': 625, 'max': 524, 'count': 8}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 1', {'end_s': 600, 'calls': [[93, 138], [499, 519], [546, None], [485, None], [376, 526], [329, 419], [42, None], [303, None]]}, {'avg': 166, 'long_permille': 625, 'max': 558, 'count': 8}), ('control 4', {'end_s': 600, 'calls': [[15, None], [80, 100], [304, 324], [560, 557], [73, 78], [574, None]]}, {'avg': 109, 'long_permille': 166, 'max': 585, 'count': 6}), ('sampled regression 7', {'end_s': 600, 'calls': [[196, 216], [228, 248], [100, None], [381, 471], [370, 415], [56, 76]]}, {'avg': 115, 'long_permille': 333, 'max': 500, 'count': 6})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('sampled regression 27', {'end_s': 600, 'calls': [[441, None], [579, None], [47, 137], [447, None]]}, {'avg': 105, 'long_permille': 750, 'max': 159, 'count': 4}), ('control 6', {'end_s': 600, 'calls': [[541, None], [503, 502], [554, None], [543, None], [284, 434]]}, {'avg': 62, 'long_permille': 200, 'max': 150, 'count': 5}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('control 12', {'end_s': 600, 'calls': [[549, None], [34, 94], [153, 243]]}, {'avg': 67, 'long_permille': 333, 'max': 90, 'count': 3}), ('sampled regression 15', {'end_s': 600, 'calls': [[427, 472], [290, 440], [125, None], [18, 79], [88, 178], [156, 306], [7, None], [120, None]]}, {'avg': 255, 'long_permille': 875, 'max': 593, 'count': 8}), ('control 18', {'end_s': 600, 'calls': [[508, 528]]}, {'avg': 20, 'long_permille': 0, 'max': 20, 'count': 1})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('sampled regression 61', {'end_s': 600, 'calls': [[410, 415], [504, 564], [213, 258], [291, None], [359, None], [364, 369], [125, None]]}, {'avg': 162, 'long_permille': 428, 'max': 475, 'count': 7}), ('control 13', {'end_s': 600, 'calls': [[451, 511], [494, 539], [553, None], [26, None], [306, 367], [164, 314], [548, None], [406, 556]]}, {'avg': 142, 'long_permille': 500, 'max': 574, 'count': 8}), ('boundary: no calls', {'end_s': 600, 'calls': []}, {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 23', {'end_s': 600, 'calls': [[121, 141], [388, None], [577, None]]}, {'avg': 85, 'long_permille': 333, 'max': 212, 'count': 3}), ('control 26', {'end_s': 600, 'calls': [[205, 225], [336, 381]]}, {'avg': 32, 'long_permille': 0, 'max': 45, 'count': 2}), ('sampled regression 29', {'end_s': 600, 'calls': [[26, 31], [282, 287], [487, 577], [127, 187], [568, None], [130, 280], [335, 395], [184, 274]]}, {'avg': 61, 'long_permille': 375, 'max': 150, 'count': 8})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('sampled regression 9', {'end_s': 600, 'calls': [[575, 595], [530, None], [76, None], [511, None], [173, 178], [76, 137], [46, 51], [370, 520]]}, {'avg': 115, 'long_permille': 625, 'max': 524, 'count': 8}), ('sampled regression 20', {'end_s': 600, 'calls': [[520, None], [447, 467], [161, 221], [506, 511], [146, 296], [576, None], [73, 223], [194, 214]]}, {'avg': 63, 'long_permille': 375, 'max': 150, 'count': 8}), ('boundary: unanswered call at the end', {'end_s': 600, 'calls': [[500, None], [10, 30]]}, {'avg': 60, 'long_permille': 500, 'max': 100, 'count': 2}), ('control 34', {'end_s': 600, 'calls': [[526, 531], [100, 160], [338, None], [152, 242], [413, 433], [56, 117]]}, {'avg': 83, 'long_permille': 500, 'max': 262, 'count': 6}), ('control 37', {'end_s': 600, 'calls': [[542, 547], [483, None], [421, 418], [216, None]]}, {'avg': 126, 'long_permille': 500, 'max': 384, 'count': 4}), ('control 40', {'end_s': 600, 'calls': [[286, 346], [342, None], [309, 308], [91, 96], [519, 524], [518, None], [12, 73]]}, {'avg': 67, 'long_permille': 428, 'max': 258, 'count': 7})], [('regression: mean with a remainder', {'end_s': 600, 'calls': [[0, 10], [0, 11], [0, 11]]}, {'avg': 10, 'long_permille': 0, 'max': 11, 'count': 3}), ('boundary: long unanswered call', {'end_s': 600, 'calls': [[400, None], [0, 10], [5, 15]]}, {'avg': 73, 'long_permille': 333, 'max': 200, 'count': 3}), ('sampled regression 27', {'end_s': 600, 'calls': [[441, None], [579, None], [47, 137], [447, None]]}, {'avg': 105, 'long_permille': 750, 'max': 159, 'count': 4}), ('boundary: wait of exactly sixty seconds', {'end_s': 600, 'calls': [[0, 60], [100, 161]]}, {'avg': 60, 'long_permille': 500, 'max': 61, 'count': 2}), ('boundary: no calls', {'end_s': 600, 'calls': []}, {'avg': 0, 'long_permille': 0, 'max': 0, 'count': 0}), ('control 45', {'end_s': 600, 'calls': [[54, 204], [360, None], [102, None], [487, None], [396, None]]}, {'avg': 241, 'long_permille': 1000, 'max': 498, 'count': 5}), ('sampled regression 48', {'end_s': 600, 'calls': [[235, 234], [112, 202], [453, 498], [10, 30], [166, 186], [359, 358], [466, 471]]}, {'avg': 25, 'long_permille': 142, 'max': 90, 'count': 7}), ('sampled regression 51', {'end_s': 600, 'calls': [[553, None], [377, 422], [370, None], [180, 241]]}, {'avg': 95, 'long_permille': 500, 'max': 230, 'count': 4})]]
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 mean wait is one second high.

Each hall call has a registration time and an answer time (None if still unanswered at end_s). Waits are answer - registration clamped at zero (clock skew); unanswered calls count with the censored wait end_s - registration. Report the integer mean (floor), per-mille of waits over 60 s (floor), the maximum and the count; all zeros when there are no calls.

split: open-access


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

N = 1
observations = []
def solve(x):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s for s in x['stops'] if s != x['target']]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24), ('control 10', {'floor': 3, 'dir': 'up', 'target': 1, 'call_dir': 'down', 'stops': [15, 13], 'per_floor_s': 3, 'stop_s': 10}, 98)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 38', {'floor': 8, 'dir': 'down', 'target': 4, 'call_dir': 'up', 'stops': [11], 'per_floor_s': 2, 'stop_s': 8}, 8), ('sampled regression 19', {'floor': 15, 'dir': 'down', 'target': 7, 'call_dir': 'down', 'stops': [8, 13, 0], 'per_floor_s': 2, 'stop_s': 8}, 32), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 58', {'floor': 14, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [12, 9, 11], 'per_floor_s': 2, 'stop_s': 8}, 40), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 72', {'floor': 3, 'dir': 'down', 'target': 1, 'call_dir': 'up', 'stops': [4, 1, 3, 2], 'per_floor_s': 3, 'stop_s': 8}, 14), ('sampled regression 52', {'floor': 6, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [1, 2, 0, 15], 'per_floor_s': 2, 'stop_s': 12}, 74), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('sampled regression 66', {'floor': 14, 'dir': 'down', 'target': 5, 'call_dir': 'down', 'stops': [14, 8, 0], 'per_floor_s': 2, 'stop_s': 10}, 28), ('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('sampled regression 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24), ('control 10', {'floor': 3, 'dir': 'up', 'target': 1, 'call_dir': 'down', 'stops': [15, 13], 'per_floor_s': 3, 'stop_s': 10}, 98)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 38', {'floor': 8, 'dir': 'down', 'target': 4, 'call_dir': 'up', 'stops': [11], 'per_floor_s': 2, 'stop_s': 8}, 8), ('sampled regression 19', {'floor': 15, 'dir': 'down', 'target': 7, 'call_dir': 'down', 'stops': [8, 13, 0], 'per_floor_s': 2, 'stop_s': 8}, 32), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 58', {'floor': 14, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [12, 9, 11], 'per_floor_s': 2, 'stop_s': 8}, 40), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 72', {'floor': 3, 'dir': 'down', 'target': 1, 'call_dir': 'up', 'stops': [4, 1, 3, 2], 'per_floor_s': 3, 'stop_s': 8}, 14), ('sampled regression 52', {'floor': 6, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [1, 2, 0, 15], 'per_floor_s': 2, 'stop_s': 12}, 74), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('sampled regression 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('sampled regression 66', {'floor': 14, 'dir': 'down', 'target': 5, 'call_dir': 'down', 'stops': [14, 8, 0], 'per_floor_s': 2, 'stop_s': 10}, 28), ('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('sampled regression 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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:
ETAs for down-travelling cars count the wrong stops.

A moving car at floor with direction and car stops estimates its arrival at a hall call (target, call direction). Work in the car direction (mirror floors for down). If the target is strictly ahead and the call is in the car direction, the car goes straight there, stopping at stops strictly between. Otherwise it runs to the farthest of its stops ahead and the target, reverses and returns to the target, stopping at every stop ahead plus stops strictly between target and floor behind. A stop at the target floor is not extra. ETA = floors travelled * per_floor_s + stops * stop_s.

split: open-access


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

N = 1
observations = []
def solve(x):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t >= f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 74', {'floor': 6, 'dir': 'down', 'target': 5, 'call_dir': 'up', 'stops': [1, 14], 'per_floor_s': 3, 'stop_s': 8}, 35), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 77', {'floor': 12, 'dir': 'down', 'target': 8, 'call_dir': 'up', 'stops': [14, 10, 3], 'per_floor_s': 3, 'stop_s': 12}, 66), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 74', {'floor': 6, 'dir': 'down', 'target': 5, 'call_dir': 'up', 'stops': [1, 14], 'per_floor_s': 3, 'stop_s': 8}, 35), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 77', {'floor': 12, 'dir': 'down', 'target': 8, 'call_dir': 'up', 'stops': [14, 10, 3], 'per_floor_s': 3, 'stop_s': 12}, 66), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 6', {'floor': 5, 'dir': 'down', 'target': 3, 'call_dir': 'up', 'stops': [2], 'per_floor_s': 3, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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 call at the floor the car has just left, or a call wanting the other direction, is treated as directly on the way.

A moving car at floor with direction and car stops estimates its arrival at a hall call (target, call direction). Work in the car direction (mirror floors for down). If the target is strictly ahead and the call is in the car direction, the car goes straight there, stopping at stops strictly between. Otherwise it runs to the farthest of its stops ahead and the target, reverses and returns to the target, stopping at every stop ahead plus stops strictly between target and floor behind. A stop at the target floor is not extra. ETA = floors travelled * per_floor_s + stops * stop_s.

split: open-access


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

N = 1
observations = []
def solve(x):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead)
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('sampled regression 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('sampled regression 59', {'floor': 15, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [14, 13], 'per_floor_s': 3, 'stop_s': 10}, 59), ('control 3', {'floor': 13, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [2, 15, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 32), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 59', {'floor': 15, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [14, 13], 'per_floor_s': 3, 'stop_s': 10}, 59), ('control 52', {'floor': 6, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [1, 2, 0, 15], 'per_floor_s': 2, 'stop_s': 12}, 74), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('sampled regression 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 63', {'floor': 5, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [4, 11, 7, 9], 'per_floor_s': 2, 'stop_s': 8}, 52), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s <= far])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('sampled regression 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('sampled regression 59', {'floor': 15, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [14, 13], 'per_floor_s': 3, 'stop_s': 10}, 59), ('control 3', {'floor': 13, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [2, 15, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 32), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 59', {'floor': 15, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [14, 13], 'per_floor_s': 3, 'stop_s': 10}, 59), ('control 52', {'floor': 6, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [1, 2, 0, 15], 'per_floor_s': 2, 'stop_s': 12}, 74), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('sampled regression 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 9', {'floor': 15, 'dir': 'up', 'target': 9, 'call_dir': 'down', 'stops': [13, 11, 12], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 63', {'floor': 5, 'dir': 'down', 'target': 13, 'call_dir': 'down', 'stops': [4, 11, 7, 9], 'per_floor_s': 2, 'stop_s': 8}, 52), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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 ETA of calls behind the car ignores stops made on the way back.

A moving car at floor with direction and car stops estimates its arrival at a hall call (target, call direction). Work in the car direction (mirror floors for down). If the target is strictly ahead and the call is in the car direction, the car goes straight there, stopping at stops strictly between. Otherwise it runs to the farthest of its stops ahead and the target, reverses and returns to the target, stopping at every stop ahead plus stops strictly between target and floor behind. A stop at the target floor is not extra. ETA = floors travelled * per_floor_s + stops * stop_s.

split: open-access


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

N = 1
observations = []
def solve(x):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + abs(f - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('sampled regression 13', {'floor': 2, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [4], 'per_floor_s': 3, 'stop_s': 12}, 24), ('sampled regression 3', {'floor': 13, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [2, 15, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 32), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59), ('sampled regression 33', {'floor': 5, 'dir': 'up', 'target': 0, 'call_dir': 'down', 'stops': [6, 0, 15], 'per_floor_s': 3, 'stop_s': 10}, 95), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('sampled regression 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 53', {'floor': 0, 'dir': 'up', 'target': 5, 'call_dir': 'down', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 10), ('sampled regression 61', {'floor': 11, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [9, 11, 6, 8], 'per_floor_s': 2, 'stop_s': 8}, 50), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 71', {'floor': 13, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [6, 14, 15, 11], 'per_floor_s': 3, 'stop_s': 10}, 76), ('sampled regression 77', {'floor': 12, 'dir': 'down', 'target': 8, 'call_dir': 'up', 'stops': [14, 10, 3], 'per_floor_s': 3, 'stop_s': 12}, 66), ('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('sampled regression 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f < s < t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = abs(t - f)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24)], [('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('sampled regression 13', {'floor': 2, 'dir': 'up', 'target': 2, 'call_dir': 'down', 'stops': [4], 'per_floor_s': 3, 'stop_s': 12}, 24), ('sampled regression 3', {'floor': 13, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [2, 15, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 32), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59), ('sampled regression 33', {'floor': 5, 'dir': 'up', 'target': 0, 'call_dir': 'down', 'stops': [6, 0, 15], 'per_floor_s': 3, 'stop_s': 10}, 95), ('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('sampled regression 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('regression: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('sampled regression 53', {'floor': 0, 'dir': 'up', 'target': 5, 'call_dir': 'down', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 10), ('sampled regression 61', {'floor': 11, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [9, 11, 6, 8], 'per_floor_s': 2, 'stop_s': 8}, 50), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('sampled regression 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('regression: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('sampled regression 71', {'floor': 13, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [6, 14, 15, 11], 'per_floor_s': 3, 'stop_s': 10}, 76), ('sampled regression 77', {'floor': 12, 'dir': 'down', 'target': 8, 'call_dir': 'up', 'stops': [14, 10, 3], 'per_floor_s': 3, 'stop_s': 12}, 66), ('regression: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('regression: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('sampled regression 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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 ETA forgets the distance run beyond the car position before reversing.

A moving car at floor with direction and car stops estimates its arrival at a hall call (target, call direction). Work in the car direction (mirror floors for down). If the target is strictly ahead and the call is in the car direction, the car goes straight there, stopping at stops strictly between. Otherwise it runs to the farthest of its stops ahead and the target, reverses and returns to the target, stopping at every stop ahead plus stops strictly between target and floor behind. A stop at the target floor is not extra. ETA = floors travelled * per_floor_s + stops * stop_s.

split: open-access


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

N = 1
observations = []
def solve(x):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if f <= s <= t])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 41', {'floor': 11, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [8, 11, 13], 'per_floor_s': 3, 'stop_s': 12}, 27), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 10', {'floor': 3, 'dir': 'up', 'target': 1, 'call_dir': 'down', 'stops': [15, 13], 'per_floor_s': 3, 'stop_s': 10}, 98)], [('sampled regression 64', {'floor': 10, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [10, 15], 'per_floor_s': 3, 'stop_s': 8}, 9), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('sampled regression 66', {'floor': 14, 'dir': 'down', 'target': 5, 'call_dir': 'down', 'stops': [14, 8, 0], 'per_floor_s': 2, 'stop_s': 10}, 28), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 19', {'floor': 15, 'dir': 'down', 'target': 7, 'call_dir': 'down', 'stops': [8, 13, 0], 'per_floor_s': 2, 'stop_s': 8}, 32), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('sampled regression 41', {'floor': 11, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [8, 11, 13], 'per_floor_s': 3, 'stop_s': 12}, 27), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('sampled regression 64', {'floor': 10, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [10, 15], 'per_floor_s': 3, 'stop_s': 8}, 9), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 30', {'floor': 7, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [4, 0, 15, 2], 'per_floor_s': 3, 'stop_s': 12}, 6), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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):
    sg = 1 if x['dir'] == 'up' else -1
    f = x['floor'] * sg
    t = x['target'] * sg
    stops = [s * sg for s in x['stops'] if s * sg != t]
    same = x['call_dir'] == x['dir']
    if t > f and same:
        path = t - f
        n = len([s for s in stops if s > f])
    else:
        ahead = [s for s in stops if s > f]
        far = max(ahead + [t, f])
        path = (far - f) + (far - t)
        n = len(ahead) + len([s for s in stops if t < s < f])
    return path * x['per_floor_s'] + n * x['stop_s']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 41', {'floor': 11, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [8, 11, 13], 'per_floor_s': 3, 'stop_s': 12}, 27), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 7', {'floor': 7, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [1, 13, 9, 2], 'per_floor_s': 3, 'stop_s': 12}, 24), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('control 1', {'floor': 6, 'dir': 'down', 'target': 12, 'call_dir': 'down', 'stops': [3, 4], 'per_floor_s': 2, 'stop_s': 12}, 48), ('control 4', {'floor': 1, 'dir': 'down', 'target': 14, 'call_dir': 'down', 'stops': [3, 10, 5], 'per_floor_s': 2, 'stop_s': 12}, 62), ('control 10', {'floor': 3, 'dir': 'up', 'target': 1, 'call_dir': 'down', 'stops': [15, 13], 'per_floor_s': 3, 'stop_s': 10}, 98)], [('sampled regression 64', {'floor': 10, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [10, 15], 'per_floor_s': 3, 'stop_s': 8}, 9), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('boundary: call at the current floor', {'floor': 5, 'dir': 'up', 'target': 5, 'call_dir': 'up', 'stops': [9], 'per_floor_s': 2, 'stop_s': 10}, 26), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('control 12', {'floor': 12, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 8, 7, 15], 'per_floor_s': 3, 'stop_s': 10}, 3), ('control 15', {'floor': 15, 'dir': 'up', 'target': 11, 'call_dir': 'down', 'stops': [3], 'per_floor_s': 3, 'stop_s': 12}, 12), ('control 18', {'floor': 1, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [8, 2, 11, 1], 'per_floor_s': 2, 'stop_s': 10}, 16)], [('sampled regression 66', {'floor': 14, 'dir': 'down', 'target': 5, 'call_dir': 'down', 'stops': [14, 8, 0], 'per_floor_s': 2, 'stop_s': 10}, 28), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 19', {'floor': 15, 'dir': 'down', 'target': 7, 'call_dir': 'down', 'stops': [8, 13, 0], 'per_floor_s': 2, 'stop_s': 8}, 32), ('boundary: stops behind served on return', {'floor': 6, 'dir': 'up', 'target': 1, 'call_dir': 'up', 'stops': [9, 3], 'per_floor_s': 2, 'stop_s': 10}, 42), ('boundary: stop at the target floor', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'up', 'stops': [8, 5], 'per_floor_s': 2, 'stop_s': 10}, 22), ('control 23', {'floor': 4, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [], 'per_floor_s': 2, 'stop_s': 12}, 18), ('control 26', {'floor': 14, 'dir': 'up', 'target': 15, 'call_dir': 'down', 'stops': [1, 14], 'per_floor_s': 2, 'stop_s': 8}, 2), ('control 29', {'floor': 8, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [14, 15, 3], 'per_floor_s': 3, 'stop_s': 10}, 6)], [('sampled regression 41', {'floor': 11, 'dir': 'down', 'target': 6, 'call_dir': 'down', 'stops': [8, 11, 13], 'per_floor_s': 3, 'stop_s': 12}, 27), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('boundary: down car mirrored', {'floor': 10, 'dir': 'down', 'target': 4, 'call_dir': 'down', 'stops': [7], 'per_floor_s': 2, 'stop_s': 10}, 22), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 34', {'floor': 7, 'dir': 'down', 'target': 7, 'call_dir': 'up', 'stops': [10, 7], 'per_floor_s': 2, 'stop_s': 8}, 0), ('control 37', {'floor': 14, 'dir': 'up', 'target': 11, 'call_dir': 'up', 'stops': [7, 4, 13, 1], 'per_floor_s': 2, 'stop_s': 10}, 16), ('control 40', {'floor': 10, 'dir': 'down', 'target': 11, 'call_dir': 'down', 'stops': [4, 10, 12, 5], 'per_floor_s': 3, 'stop_s': 10}, 59)], [('sampled regression 64', {'floor': 10, 'dir': 'up', 'target': 13, 'call_dir': 'up', 'stops': [10, 15], 'per_floor_s': 3, 'stop_s': 8}, 9), ('boundary: stops beyond the target', {'floor': 2, 'dir': 'up', 'target': 6, 'call_dir': 'up', 'stops': [4, 10], 'per_floor_s': 2, 'stop_s': 10}, 18), ('control 30', {'floor': 7, 'dir': 'up', 'target': 9, 'call_dir': 'up', 'stops': [4, 0, 15, 2], 'per_floor_s': 3, 'stop_s': 12}, 6), ('boundary: call behind a down car', {'floor': 10, 'dir': 'down', 'target': 12, 'call_dir': 'up', 'stops': [6], 'per_floor_s': 2, 'stop_s': 10}, 30), ('boundary: call ahead but opposite direction', {'floor': 2, 'dir': 'up', 'target': 8, 'call_dir': 'down', 'stops': [5, 11], 'per_floor_s': 2, 'stop_s': 10}, 44), ('control 45', {'floor': 2, 'dir': 'down', 'target': 0, 'call_dir': 'down', 'stops': [3, 12, 7, 11], 'per_floor_s': 2, 'stop_s': 8}, 4), ('control 48', {'floor': 8, 'dir': 'down', 'target': 2, 'call_dir': 'up', 'stops': [8, 7, 4, 6], 'per_floor_s': 3, 'stop_s': 8}, 42), ('control 51', {'floor': 11, 'dir': 'up', 'target': 4, 'call_dir': 'down', 'stops': [], 'per_floor_s': 3, 'stop_s': 12}, 21)]]
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 direct run charges a stop at the car current floor or stops beyond the target.

A moving car at floor with direction and car stops estimates its arrival at a hall call (target, call direction). Work in the car direction (mirror floors for down). If the target is strictly ahead and the call is in the car direction, the car goes straight there, stopping at stops strictly between. Otherwise it runs to the farthest of its stops ahead and the target, reverses and returns to the target, stopping at every stop ahead plus stops strictly between target and floor behind. A stop at the target floor is not extra. ETA = floors travelled * per_floor_s + stops * stop_s.

split: open-access