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

N = 1
observations = []
def solve(x):
    secs = x['sections']
    bounds = []
    acc = 0
    for s in secs:
        bounds.append(acc)
        acc += s['len']
    k = x['train_sec']
    eoa = acc
    reason = 'end-of-route'
    for j in range(k + 1, len(secs)):
        if secs[j]['state'] != 'locked':
            eoa = bounds[j]
            reason = secs[j]['state']
            break
    front = bounds[k] + x['offset_m']
    if eoa - front > x['max_ma_m']:
        eoa = front + x['max_ma_m']
        reason = 'max-length'
    eoa -= x['margin_m']
    return {'eoa_m': eoa, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('sampled regression 24', {'sections': [{'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 108, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 2308, 'reason': 'max-length'}), ('boundary: unlocked section next', {'sections': [{'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 300, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 10, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'unlocked'}), ('boundary: occupied section two ahead', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 100, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'occupied'}), ('control 1', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'unlocked'}, {'len': 200, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 69, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 150, 'reason': 'unlocked'}), ('control 4', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 206, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 1325, 'reason': 'end-of-route'}), ('control 7', {'sections': [{'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 108, 'max_ma_m': 5000, 'margin_m': 0}, {'eoa_m': 550, 'reason': 'unlocked'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: unlocked section next', {'sections': [{'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 300, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 10, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'unlocked'}), ('sampled regression 63', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 197, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 497, 'reason': 'max-length'}), ('control 3', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 141, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 450, 'reason': 'unlocked'}), ('boundary: cap exactly at the obstacle', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 975, 'reason': 'occupied'}), ('sampled regression 12', {'sections': [{'len': 200, 'state': 'unlocked'}, {'len': 350, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 34, 'max_ma_m': 300, 'margin_m': 50}, {'eoa_m': 884, 'reason': 'max-length'}), ('control 15', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 4, 'offset_m': 137, 'max_ma_m': 5000, 'margin_m': 0}, {'eoa_m': 2100, 'reason': 'end-of-route'}), ('control 18', {'sections': [{'len': 200, 'state': 'unlocked'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 3, 'offset_m': 181, 'max_ma_m': 1000, 'margin_m': 0}, {'eoa_m': 1250, 'reason': 'occupied'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: end of route with margin', {'sections': [{'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 0, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 150, 'reason': 'end-of-route'}), ('sampled regression 26', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 9, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 409, 'reason': 'max-length'}), ('control 19', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 103, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 925, 'reason': 'unlocked'}), ('boundary: cap exactly at the obstacle', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 975, 'reason': 'occupied'}), ('control 23', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 20, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 1100, 'reason': 'unlocked'}), ('control 29', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 288, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 1000, 'reason': 'occupied'}), ('control 32', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 344, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 400, 'reason': 'occupied'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: unlocked section margin', {'sections': [{'len': 100, 'state': 'occupied'}, {'len': 150, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 20, 'max_ma_m': 5000, 'margin_m': 30}, {'eoa_m': 220, 'reason': 'unlocked'}), ('sampled regression 75', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 339, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 1439, 'reason': 'max-length'}), ('control 41', {'sections': [{'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 4, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 750, 'reason': 'end-of-route'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('control 34', {'sections': [{'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 222, 'max_ma_m': 600, 'margin_m': 0}, {'eoa_m': 850, 'reason': 'unlocked'}), ('sampled regression 37', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 2, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 602, 'reason': 'max-length'}), ('control 40', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'locked'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 25, 'max_ma_m': 1000, 'margin_m': 0}, {'eoa_m': 500, 'reason': 'unlocked'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('sampled regression 33', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 33, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 933, 'reason': 'max-length'}), ('control 62', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 203, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 650, 'reason': 'unlocked'}), ('boundary: occupied section two ahead', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 100, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'occupied'}), ('sampled regression 45', {'sections': [{'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 348, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 1198, 'reason': 'max-length'}), ('control 48', {'sections': [{'len': 500, 'state': 'unlocked'}, {'len': 200, 'state': 'unlocked'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 200, 'max_ma_m': 1000, 'margin_m': 25}, {'eoa_m': 1725, 'reason': 'end-of-route'}), ('control 51', {'sections': [{'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 18, 'max_ma_m': 600, 'margin_m': 0}, {'eoa_m': 1100, 'reason': 'occupied'})]]
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):
    secs = x['sections']
    bounds = []
    acc = 0
    for s in secs:
        bounds.append(acc)
        acc += s['len']
    k = x['train_sec']
    eoa = acc
    reason = 'end-of-route'
    for j in range(k + 1, len(secs)):
        if secs[j]['state'] != 'locked':
            eoa = bounds[j]
            reason = secs[j]['state']
            break
    front = bounds[k] + x['offset_m']
    if eoa - front > x['max_ma_m']:
        eoa = front + x['max_ma_m']
        reason = 'max-length'
    if reason == 'occupied':
        eoa -= x['margin_m']
    return {'eoa_m': eoa, 'reason': reason}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('sampled regression 24', {'sections': [{'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 108, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 2308, 'reason': 'max-length'}), ('boundary: unlocked section next', {'sections': [{'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 300, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 10, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'unlocked'}), ('boundary: occupied section two ahead', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 100, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'occupied'}), ('control 1', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'unlocked'}, {'len': 200, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 69, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 150, 'reason': 'unlocked'}), ('control 4', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 206, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 1325, 'reason': 'end-of-route'}), ('control 7', {'sections': [{'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 108, 'max_ma_m': 5000, 'margin_m': 0}, {'eoa_m': 550, 'reason': 'unlocked'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: unlocked section next', {'sections': [{'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 300, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 10, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'unlocked'}), ('sampled regression 63', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 197, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 497, 'reason': 'max-length'}), ('control 3', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 141, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 450, 'reason': 'unlocked'}), ('boundary: cap exactly at the obstacle', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 975, 'reason': 'occupied'}), ('sampled regression 12', {'sections': [{'len': 200, 'state': 'unlocked'}, {'len': 350, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 34, 'max_ma_m': 300, 'margin_m': 50}, {'eoa_m': 884, 'reason': 'max-length'}), ('control 15', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 4, 'offset_m': 137, 'max_ma_m': 5000, 'margin_m': 0}, {'eoa_m': 2100, 'reason': 'end-of-route'}), ('control 18', {'sections': [{'len': 200, 'state': 'unlocked'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'occupied'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 3, 'offset_m': 181, 'max_ma_m': 1000, 'margin_m': 0}, {'eoa_m': 1250, 'reason': 'occupied'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: end of route with margin', {'sections': [{'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 0, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 150, 'reason': 'end-of-route'}), ('sampled regression 26', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 9, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 409, 'reason': 'max-length'}), ('control 19', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 103, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 925, 'reason': 'unlocked'}), ('boundary: cap exactly at the obstacle', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'occupied'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 975, 'reason': 'occupied'}), ('control 23', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 20, 'max_ma_m': 5000, 'margin_m': 50}, {'eoa_m': 1100, 'reason': 'unlocked'}), ('control 29', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 288, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 1000, 'reason': 'occupied'}), ('control 32', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 344, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 400, 'reason': 'occupied'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: unlocked section margin', {'sections': [{'len': 100, 'state': 'occupied'}, {'len': 150, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 20, 'max_ma_m': 5000, 'margin_m': 30}, {'eoa_m': 220, 'reason': 'unlocked'}), ('sampled regression 75', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}, {'len': 350, 'state': 'unlocked'}, {'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 339, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 1439, 'reason': 'max-length'}), ('control 41', {'sections': [{'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 4, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 750, 'reason': 'end-of-route'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('control 34', {'sections': [{'len': 500, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}], 'train_sec': 1, 'offset_m': 222, 'max_ma_m': 600, 'margin_m': 0}, {'eoa_m': 850, 'reason': 'unlocked'}), ('sampled regression 37', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 200, 'state': 'unlocked'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 2, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 602, 'reason': 'max-length'}), ('control 40', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'locked'}, {'len': 500, 'state': 'unlocked'}, {'len': 100, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 25, 'max_ma_m': 1000, 'margin_m': 0}, {'eoa_m': 500, 'reason': 'unlocked'})], [('regression: length cap from the front', {'sections': [{'len': 500, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 400, 'max_ma_m': 600, 'margin_m': 25}, {'eoa_m': 1000, 'reason': 'max-length'}), ('boundary: own section occupied', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 50, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 675, 'reason': 'end-of-route'}), ('sampled regression 33', {'sections': [{'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 500, 'state': 'locked'}], 'train_sec': 3, 'offset_m': 33, 'max_ma_m': 600, 'margin_m': 50}, {'eoa_m': 933, 'reason': 'max-length'}), ('control 62', {'sections': [{'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 100, 'state': 'unlocked'}], 'train_sec': 0, 'offset_m': 203, 'max_ma_m': 1000, 'margin_m': 50}, {'eoa_m': 650, 'reason': 'unlocked'}), ('boundary: occupied section two ahead', {'sections': [{'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}, {'len': 300, 'state': 'occupied'}, {'len': 100, 'state': 'locked'}], 'train_sec': 0, 'offset_m': 100, 'max_ma_m': 5000, 'margin_m': 25}, {'eoa_m': 375, 'reason': 'occupied'}), ('sampled regression 45', {'sections': [{'len': 350, 'state': 'unlocked'}, {'len': 200, 'state': 'locked'}, {'len': 350, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'locked'}, {'len': 200, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 348, 'max_ma_m': 300, 'margin_m': 25}, {'eoa_m': 1198, 'reason': 'max-length'}), ('control 48', {'sections': [{'len': 500, 'state': 'unlocked'}, {'len': 200, 'state': 'unlocked'}, {'len': 350, 'state': 'occupied'}, {'len': 350, 'state': 'locked'}, {'len': 350, 'state': 'locked'}], 'train_sec': 2, 'offset_m': 200, 'max_ma_m': 1000, 'margin_m': 25}, {'eoa_m': 1725, 'reason': 'end-of-route'}), ('control 51', {'sections': [{'len': 500, 'state': 'locked'}, {'len': 100, 'state': 'occupied'}, {'len': 500, 'state': 'locked'}, {'len': 200, 'state': 'occupied'}, {'len': 200, 'state': 'locked'}], 'train_sec': 1, 'offset_m': 18, 'max_ma_m': 600, 'margin_m': 0}, {'eoa_m': 1100, 'reason': 'occupied'})]]
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 length-capped authority is shortened by the safety margin.

Sections have lengths and states locked, occupied or unlocked; the train front is offset_m into section train_sec (which it occupies itself). Scan the following sections; the end of authority is the start of the first section that is not locked (reason = its state) or the end of the last section (end-of-route). If that exceeds max_ma_m ahead of the train front, the authority is cut to front + max_ma_m (reason max-length). The margin is subtracted from the end except for a max-length cut.

split: open-access


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

N = 1
observations = []
def solve(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t > f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 2', {'isolate_after': 2, 'cycles': [[True, False, True], [None, True, False], [None, False, False], [False, None, False], [True, False, False], [True, False, True]]}, {'votes': [True, True, False, False, False, True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('sampled regression 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []})], [('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 42', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [False, False, False], [False, False, True], [False, True, False], [False, False, True], [None, False, False], [True, None, False], [False, True, True]]}, {'votes': [False, False, False, False, False, False, False, True, True], 'isolated': []}), ('control 13', {'isolate_after': 3, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [False, None, False], [False, False, True]]}, {'votes': [False, True, True, False, False], 'isolated': []}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 56', {'isolate_after': 2, 'cycles': [[False, True, None], [False, True, None], [False, False, False], [True, False, False], [False, False, True]]}, {'votes': [True, True, False, False, True], 'isolated': [0]}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 69', {'isolate_after': 3, 'cycles': [[False, True, True], [True, True, False], [False, False, False], [False, None, True]]}, {'votes': [True, True, False, True], 'isolated': []}), ('control 32', {'isolate_after': 3, 'cycles': [[False, True, True], [False, False, False], [False, False, None], [True, True, None], [False, False, False], [True, True, False], [True, None, True]]}, {'votes': [True, False, False, True, False, True, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t > f or len(healthy) == 2
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 2', {'isolate_after': 2, 'cycles': [[True, False, True], [None, True, False], [None, False, False], [False, None, False], [True, False, False], [True, False, True]]}, {'votes': [True, True, False, False, False, True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('sampled regression 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('sampled regression 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []})], [('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 42', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [False, False, False], [False, False, True], [False, True, False], [False, False, True], [None, False, False], [True, None, False], [False, True, True]]}, {'votes': [False, False, False, False, False, False, False, True, True], 'isolated': []}), ('control 13', {'isolate_after': 3, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [False, None, False], [False, False, True]]}, {'votes': [False, True, True, False, False], 'isolated': []}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 56', {'isolate_after': 2, 'cycles': [[False, True, None], [False, True, None], [False, False, False], [True, False, False], [False, False, True]]}, {'votes': [True, True, False, False, True], 'isolated': [0]}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []}), ('regression: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 69', {'isolate_after': 3, 'cycles': [[False, True, True], [True, True, False], [False, False, False], [False, None, True]]}, {'votes': [True, True, False, True], 'isolated': []}), ('control 32', {'isolate_after': 3, 'cycles': [[False, True, True], [False, False, False], [False, False, None], [True, True, None], [False, False, False], [True, True, False], [True, None, True]]}, {'votes': [True, False, False, True, False, True, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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:
Two healthy channels that disagree produce a clear vote.

Three channels report occupancy (True/False) or None when failed. A channel isolated earlier counts as None. With fewer than two healthy channels the vote is occupied. Otherwise the vote is occupied when occupied reports are at least as many as clear ones (ties are occupied). A healthy channel that disagrees with the vote increments its discrepancy count, otherwise (agreeing or None) the count resets; a channel is isolated for good when its count reaches isolate_after. Return all votes and isolated channel indices.

split: open-access


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

N = 1
observations = []
def solve(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 1:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('control 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 66', {'isolate_after': 3, 'cycles': [[False, False, False], [False, False, None], [False, None, None], [True, False, None], [None, False, False], [False, False, False], [False, True, False], [False, False, True], [True, True, False]]}, {'votes': [False, False, True, True, False, False, False, False, True], 'isolated': []}), ('control 13', {'isolate_after': 3, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [False, None, False], [False, False, True]]}, {'votes': [False, True, True, False, False], 'isolated': []}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('control 43', {'isolate_after': 3, 'cycles': [[True, False, True], [True, None, False], [False, True, False], [False, False, False], [True, False, False]]}, {'votes': [True, True, False, False, False], 'isolated': []})], [('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('control 32', {'isolate_after': 3, 'cycles': [[False, True, True], [False, False, False], [False, False, None], [True, True, None], [False, False, False], [True, True, False], [True, None, True]]}, {'votes': [True, False, False, True, False, True, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) <= 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('control 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('control 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 66', {'isolate_after': 3, 'cycles': [[False, False, False], [False, False, None], [False, None, None], [True, False, None], [None, False, False], [False, False, False], [False, True, False], [False, False, True], [True, True, False]]}, {'votes': [False, False, True, True, False, False, False, False, True], 'isolated': []}), ('control 13', {'isolate_after': 3, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [False, None, False], [False, False, True]]}, {'votes': [False, True, True, False, False], 'isolated': []}), ('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('control 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]}), ('control 21', {'isolate_after': 3, 'cycles': [[True, True, True], [False, True, False], [True, True, True], [True, True, False], [None, False, False], [False, False, False], [False, False, False]]}, {'votes': [True, False, True, True, False, False, False], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('control 43', {'isolate_after': 3, 'cycles': [[True, False, True], [True, None, False], [False, True, False], [False, False, False], [True, False, False]]}, {'votes': [True, True, False, False, False], 'isolated': []})], [('regression: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('control 32', {'isolate_after': 3, 'cycles': [[False, True, True], [False, False, False], [False, False, None], [True, True, None], [False, False, False], [True, True, False], [True, None, True]]}, {'votes': [True, False, False, True, False, True, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('control 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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 single surviving channel is trusted to declare the section clear.

Three channels report occupancy (True/False) or None when failed. A channel isolated earlier counts as None. With fewer than two healthy channels the vote is occupied. Otherwise the vote is occupied when occupied reports are at least as many as clear ones (ties are occupied). A healthy channel that disagrees with the vote increments its discrepancy count, otherwise (agreeing or None) the count resets; a channel is isolated for good when its count reaches isolate_after. Return all votes and isolated channel indices.

split: open-access


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

N = 1
observations = []
def solve(x):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            else:
                pass
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 10', {'isolate_after': 2, 'cycles': [[None, True, False], [False, None, True], [False, False, False], [False, True, False], [False, True, False], [True, True, False], [False, None, False], [True, True, True]]}, {'votes': [True, True, False, False, False, True, False, True], 'isolated': [1]}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 36', {'isolate_after': 3, 'cycles': [[None, True, False], [None, False, False], [False, False, True], [False, False, False], [True, True, False], [True, True, True], [True, True, None], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': []}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('control 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('sampled regression 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 71', {'isolate_after': 2, 'cycles': [[False, False, None], [True, False, True], [False, False, False], [False, True, False]]}, {'votes': [False, True, False, False], 'isolated': []}), ('sampled regression 20', {'isolate_after': 2, 'cycles': [[False, True, False], [True, False, False], [True, False, None], [False, None, False], [False, True, False], [False, None, None]]}, {'votes': [False, False, True, False, False, True], 'isolated': []}), ('boundary: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('sampled regression 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('control 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('sampled regression 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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):
    k = x['isolate_after']
    bad = [0, 0, 0]
    iso = [False, False, False]
    votes = []
    for cyc in x['cycles']:
        vals = [None if iso[i] else cyc[i] for i in range(3)]
        healthy = [v for v in vals if v is not None]
        if len(healthy) < 2:
            vote = True
        else:
            t = sum(1 for v in healthy if v)
            f = len(healthy) - t
            vote = t >= f
        votes.append(vote)
        for i in range(3):
            if vals[i] is not None and vals[i] != vote:
                bad[i] += 1
                if bad[i] >= k:
                    iso[i] = True
            elif vals[i] is not None:
                bad[i] = 0
    return {'votes': votes, 'isolated': [i for i in range(3) if iso[i]]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 10', {'isolate_after': 2, 'cycles': [[None, True, False], [False, None, True], [False, False, False], [False, True, False], [False, True, False], [True, True, False], [False, None, False], [True, True, True]]}, {'votes': [True, True, False, False, False, True, False, True], 'isolated': [1]}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('control 1', {'isolate_after': 2, 'cycles': [[False, False, False], [True, None, True], [True, True, True], [None, False, False]]}, {'votes': [False, True, True, False], 'isolated': []}), ('control 4', {'isolate_after': 2, 'cycles': [[False, True, True], [False, False, False], [False, False, False], [True, True, False], [True, True, True], [True, False, True], [False, False, False], [False, False, None], [True, True, True]]}, {'votes': [True, False, False, True, True, True, False, False, True], 'isolated': []}), ('control 7', {'isolate_after': 3, 'cycles': [[False, False, True], [False, False, False], [True, True, True], [False, True, True], [True, True, None], [False, False, False], [True, True, True], [False, False, False]]}, {'votes': [False, False, True, True, True, False, True, False], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 36', {'isolate_after': 3, 'cycles': [[None, True, False], [None, False, False], [False, False, True], [False, False, False], [True, True, False], [True, True, True], [True, True, None], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': []}), ('sampled regression 19', {'isolate_after': 2, 'cycles': [[True, True, True], [True, False, None], [True, False, True], [None, False, False], [True, True, None], [True, False, False], [False, False, True], [True, True, True]]}, {'votes': [True, True, True, True, True, True, True, True], 'isolated': [1]}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('boundary: persistent dissenter', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, False, False]]}, {'votes': [False, False, False], 'isolated': [0]}), ('control 12', {'isolate_after': 3, 'cycles': [[False, False, False], [False, True, False], [True, False, True], [True, False, True], [False, False, True], [False, False, False], [True, False, True], [True, True, True]]}, {'votes': [False, False, True, True, True, False, True, True], 'isolated': [1]}), ('control 15', {'isolate_after': 3, 'cycles': [[False, False, False], [False, None, False], [True, False, False], [True, None, False]]}, {'votes': [False, False, False, True], 'isolated': []}), ('sampled regression 18', {'isolate_after': 2, 'cycles': [[False, False, False], [None, False, True], [False, False, True], [True, False, False], [True, False, True], [False, False, False], [False, True, None], [False, False, False], [False, False, False]]}, {'votes': [False, True, False, False, True, False, True, False, False], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 71', {'isolate_after': 2, 'cycles': [[False, False, None], [True, False, True], [False, False, False], [False, True, False]]}, {'votes': [False, True, False, False], 'isolated': []}), ('sampled regression 20', {'isolate_after': 2, 'cycles': [[False, True, False], [True, False, False], [True, False, None], [False, None, False], [False, True, False], [False, None, None]]}, {'votes': [False, False, True, False, False, True], 'isolated': []}), ('boundary: two dissenters in turn', {'isolate_after': 2, 'cycles': [[True, False, False], [True, False, False], [False, True, False], [False, True, False], [False, False, False]]}, {'votes': [False, False, True, True, True], 'isolated': [0, 2]}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('control 23', {'isolate_after': 2, 'cycles': [[True, False, True], [None, False, False], [False, False, False], [False, False, False], [False, False, None], [False, False, False], [True, None, True]]}, {'votes': [True, False, False, False, False, False, True], 'isolated': []}), ('control 26', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, True], [False, False, None]]}, {'votes': [True, False, False, False], 'isolated': []}), ('sampled regression 29', {'isolate_after': 2, 'cycles': [[False, False, True], [False, False, False], [False, False, True], [False, True, False], [False, True, True]]}, {'votes': [False, False, False, False, True], 'isolated': []})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: isolated channel keeps reporting', {'isolate_after': 1, 'cycles': [[True, False, False], [True, True, False]]}, {'votes': [False, True], 'isolated': [0, 2]}), ('boundary: two healthy channels disagree', {'isolate_after': 3, 'cycles': [[True, False, None]]}, {'votes': [True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('sampled regression 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('control 37', {'isolate_after': 3, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False]]}, {'votes': [True, False, False, False, False, False], 'isolated': []}), ('control 40', {'isolate_after': 2, 'cycles': [[True, None, True], [False, False, None], [False, True, False], [False, True, False], [True, True, True], [True, None, False], [None, False, False], [True, True, True]]}, {'votes': [True, False, False, False, True, True, True, True], 'isolated': [1, 2]})], [('regression: dissent interrupted by failure', {'isolate_after': 2, 'cycles': [[True, False, False], [None, False, False], [True, False, False]]}, {'votes': [False, False, False], 'isolated': []}), ('sampled regression 34', {'isolate_after': 2, 'cycles': [[True, True, False], [False, True, False], [True, True, True], [True, True, True], [True, False, True], [False, False, False], [True, False, True]]}, {'votes': [True, False, True, True, True, False, True], 'isolated': []}), ('sampled regression 9', {'isolate_after': 3, 'cycles': [[None, False, False], [None, True, False], [False, None, None], [False, False, True], [True, None, False], [True, True, True], [None, False, None], [False, False, False], [True, None, False]]}, {'votes': [False, True, True, False, True, True, True, False, True], 'isolated': []}), ('boundary: two healthy channels agree clear', {'isolate_after': 3, 'cycles': [[False, False, None]]}, {'votes': [False], 'isolated': []}), ('boundary: single healthy channel says clear', {'isolate_after': 3, 'cycles': [[False, None, None]]}, {'votes': [True], 'isolated': []}), ('sampled regression 45', {'isolate_after': 2, 'cycles': [[True, True, True], [False, False, False], [False, False, False], [False, True, False], [None, True, False], [None, True, False], [True, False, False]]}, {'votes': [True, False, False, False, True, True, True], 'isolated': [2]}), ('sampled regression 48', {'isolate_after': 2, 'cycles': [[False, False, False], [False, False, False], [False, True, True], [True, True, None], [False, True, False], [True, True, True], [False, False, False], [False, False, False], [False, True, False]]}, {'votes': [False, False, True, True, False, True, False, False, False], 'isolated': []}), ('control 51', {'isolate_after': 3, 'cycles': [[False, False, False], [True, False, False], [True, True, True], [True, True, True], [True, True, True], [True, True, True], [True, False, True], [True, False, False], [True, True, True]]}, {'votes': [False, False, True, True, True, True, True, False, True], 'isolated': []})]]
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 channel is isolated after scattered, non-consecutive discrepancies.

Three channels report occupancy (True/False) or None when failed. A channel isolated earlier counts as None. With fewer than two healthy channels the vote is occupied. Otherwise the vote is occupied when occupied reports are at least as many as clear ones (ties are occupied). A healthy channel that disagrees with the vote increments its discrepancy count, otherwise (agreeing or None) the count resets; a channel is isolated for good when its count reaches isolate_after. Return all votes and isolated channel indices.

split: open-access