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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            b[i] = None
            if i >= n - 2:
                exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('control 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 11', {'berths': 5, 'events': [['step', 1], ['step', 3], ['interpose', 0, '5X99'], ['step', 3], ['interpose', 1, '5X99'], ['step', 1], ['step', 2], ['cancel', 2], ['step', 4]]}, {'berths': ['5X99', None, None, '5X99', None], 'clashes': [4, 2], 'exited': ['????']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []})], [('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 22', {'berths': 4, 'events': [['step', 3], ['step', 2], ['interpose', 1, '9Z10'], ['step', 3]]}, {'berths': [None, '9Z10', None, None], 'clashes': [], 'exited': ['????', '????']}), ('control 24', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 3]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []})], [('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 33', {'berths': 4, 'events': [['step', 3], ['step', 3], ['step', 3], ['step', 2], ['step', 1], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '????'], 'clashes': [2, 2], 'exited': ['????', '????', '????']}), ('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('control 43', {'berths': 4, 'events': [['interpose', 2, '9Z10'], ['interpose', 3, '5X99'], ['step', 0], ['interpose', 2, '1A01']]}, {'berths': [None, '????', '1A01', '5X99'], 'clashes': [], 'exited': []})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 47', {'berths': 4, 'events': [['step', 2], ['step', 3], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('control 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            b[i] = None
            if i == n - 1:
                if tid != '????':
                    exited.append(tid)
            else:
                if b[i + 1] is not None:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('control 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []}), ('sampled regression 10', {'berths': 3, 'events': [['interpose', 1, '9Z10'], ['interpose', 0, '2B17'], ['step', 1], ['step', 1], ['step', 0], ['step', 0], ['step', 2], ['interpose', 2, '2B17'], ['step', 1]]}, {'berths': [None, None, '????'], 'clashes': [2, 1, 2], 'exited': ['????']})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('sampled regression 11', {'berths': 5, 'events': [['step', 1], ['step', 3], ['interpose', 0, '5X99'], ['step', 3], ['interpose', 1, '5X99'], ['step', 1], ['step', 2], ['cancel', 2], ['step', 4]]}, {'berths': ['5X99', None, None, '5X99', None], 'clashes': [4, 2], 'exited': ['????']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []}), ('sampled regression 21', {'berths': 5, 'events': [['step', 3], ['step', 3], ['step', 0], ['step', 1], ['step', 1], ['step', 3], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????', None, '????'], 'clashes': [4, 2, 4, 2], 'exited': []})], [('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 22', {'berths': 4, 'events': [['step', 3], ['step', 2], ['interpose', 1, '9Z10'], ['step', 3]]}, {'berths': [None, '9Z10', None, None], 'clashes': [], 'exited': ['????', '????']}), ('control 24', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 3]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('boundary: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []})], [('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 33', {'berths': 4, 'events': [['step', 3], ['step', 3], ['step', 3], ['step', 2], ['step', 1], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '????'], 'clashes': [2, 2], 'exited': ['????', '????', '????']}), ('regression: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('control 43', {'berths': 4, 'events': [['interpose', 2, '9Z10'], ['interpose', 3, '5X99'], ['step', 0], ['interpose', 2, '1A01']]}, {'berths': [None, '????', '1A01', '5X99'], 'clashes': [], 'exited': []})], [('regression: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 47', {'berths': 4, 'events': [['step', 2], ['step', 3], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('regression: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('control 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']})]]
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:
Trains leave the describer area one berth early, or unknown trains vanish without trace.

A train describer has berths 0..n-1. interpose writes a headcode, cancel blanks a berth. step i moves the description from berth i to i+1 (or out of the area from the last berth, recorded in exited); stepping an empty berth carries the unknown description ????. Stepping onto a filled berth records a clash at the destination and the stepped description overwrites it. The source berth is always blanked.

split: open-access


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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            b[i] = None
            if i == n - 1:
                exited.append(tid)
            else:
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 6', {'berths': 4, 'events': [['interpose', 1, '1A01'], ['step', 2], ['interpose', 1, '9Z10'], ['interpose', 1, '1A01'], ['step', 0], ['interpose', 3, '9Z10'], ['step', 1], ['step', 2], ['interpose', 1, '1A01']]}, {'berths': [None, '1A01', None, '????'], 'clashes': [1, 3], 'exited': []}), ('sampled regression 2', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['interpose', 1, '9Z10'], ['step', 1], ['interpose', 1, '2B17'], ['interpose', 2, '9Z10'], ['interpose', 2, '5X99']]}, {'berths': [None, '2B17', '5X99'], 'clashes': [2], 'exited': []}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('sampled regression 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 14', {'berths': 4, 'events': [['step', 0], ['interpose', 0, '1A01'], ['step', 0], ['interpose', 3, '1A01'], ['interpose', 0, '1A01'], ['interpose', 3, '9Z10'], ['interpose', 2, '2B17'], ['cancel', 0], ['step', 3]]}, {'berths': [None, '1A01', '2B17', None], 'clashes': [1], 'exited': ['9Z10']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 30', {'berths': 4, 'events': [['step', 0], ['step', 1], ['step', 3], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '5X99']]}, {'berths': [None, '5X99', '5X99', None], 'clashes': [2], 'exited': ['????']}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 44', {'berths': 3, 'events': [['step', 1], ['step', 1], ['interpose', 1, '9Z10']]}, {'berths': [None, '9Z10', '????'], 'clashes': [2], 'exited': []}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('control 43', {'berths': 4, 'events': [['interpose', 2, '9Z10'], ['interpose', 3, '5X99'], ['step', 0], ['interpose', 2, '1A01']]}, {'berths': [None, '????', '1A01', '5X99'], 'clashes': [], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('sampled regression 55', {'berths': 3, 'events': [['interpose', 1, '1A01'], ['step', 0], ['step', 2], ['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 1, '1A01']]}, {'berths': [None, '1A01', None], 'clashes': [1, 1, 1], 'exited': ['????', '????', '????']}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']}), ('sampled regression 54', {'berths': 3, 'events': [['step', 2], ['step', 2], ['step', 2], ['step', 1], ['interpose', 2, '5X99'], ['step', 0], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [2], 'exited': ['????', '????', '????', '????']})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    n = x['berths']
    b = [None] * n
    clashes = []
    exited = []
    for ev in x['events']:
        kind = ev[0]
        if kind == 'interpose':
            b[ev[1]] = ev[2]
        elif kind == 'cancel':
            b[ev[1]] = None
        elif kind == 'step':
            i = ev[1]
            tid = b[i] if b[i] is not None else '????'
            b[i] = None
            if i == n - 1:
                exited.append(tid)
            else:
                if b[i + 1] is not None and b[i + 1] != tid:
                    clashes.append(i + 1)
                b[i + 1] = tid
    return {'berths': b, 'clashes': clashes, 'exited': exited}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 6', {'berths': 4, 'events': [['interpose', 1, '1A01'], ['step', 2], ['interpose', 1, '9Z10'], ['interpose', 1, '1A01'], ['step', 0], ['interpose', 3, '9Z10'], ['step', 1], ['step', 2], ['interpose', 1, '1A01']]}, {'berths': [None, '1A01', None, '????'], 'clashes': [1, 3], 'exited': []}), ('sampled regression 2', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['interpose', 1, '9Z10'], ['step', 1], ['interpose', 1, '2B17'], ['interpose', 2, '9Z10'], ['interpose', 2, '5X99']]}, {'berths': [None, '2B17', '5X99'], 'clashes': [2], 'exited': []}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 1', {'berths': 5, 'events': [['cancel', 1], ['step', 3], ['step', 4], ['step', 1], ['interpose', 1, '1A01'], ['cancel', 2], ['interpose', 0, '2B17'], ['step', 4]]}, {'berths': ['2B17', '1A01', None, None, None], 'clashes': [], 'exited': ['????', '????']}), ('control 4', {'berths': 4, 'events': [['step', 1], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', '????', None], 'clashes': [], 'exited': []}), ('sampled regression 7', {'berths': 4, 'events': [['interpose', 3, '5X99'], ['step', 1], ['step', 1]]}, {'berths': [None, None, '????', '5X99'], 'clashes': [2], 'exited': []})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 14', {'berths': 4, 'events': [['step', 0], ['interpose', 0, '1A01'], ['step', 0], ['interpose', 3, '1A01'], ['interpose', 0, '1A01'], ['interpose', 3, '9Z10'], ['interpose', 2, '2B17'], ['cancel', 0], ['step', 3]]}, {'berths': [None, '1A01', '2B17', None], 'clashes': [1], 'exited': ['9Z10']}), ('sampled regression 16', {'berths': 4, 'events': [['step', 0], ['cancel', 3], ['step', 0], ['interpose', 3, '5X99'], ['interpose', 0, '9Z10'], ['step', 3], ['interpose', 2, '5X99'], ['step', 2]]}, {'berths': ['9Z10', '????', None, '5X99'], 'clashes': [1], 'exited': ['5X99']}), ('boundary: exit from the last berth', {'berths': 3, 'events': [['interpose', 1, '2B17'], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [], 'exited': ['2B17']}), ('boundary: unknown train leaves the area', {'berths': 2, 'events': [['step', 1]]}, {'berths': [None, None], 'clashes': [], 'exited': ['????']}), ('sampled regression 12', {'berths': 3, 'events': [['step', 1], ['interpose', 1, '5X99'], ['cancel', 0], ['cancel', 1], ['step', 2], ['step', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1], 'exited': ['????']}), ('control 15', {'berths': 4, 'events': [['step', 0], ['interpose', 3, '5X99'], ['cancel', 2]]}, {'berths': [None, '????', None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 18', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['cancel', 2], ['step', 0], ['step', 0], ['cancel', 1], ['step', 0], ['step', 1], ['step', 0]]}, {'berths': [None, '????', '????'], 'clashes': [1], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 26', {'berths': 5, 'events': [['step', 1], ['cancel', 3], ['interpose', 4, '5X99'], ['cancel', 2], ['interpose', 1, '9Z10'], ['interpose', 3, '1A01'], ['step', 3], ['step', 2], ['step', 1]]}, {'berths': [None, None, '9Z10', '????', '1A01'], 'clashes': [4], 'exited': []}), ('sampled regression 30', {'berths': 4, 'events': [['step', 0], ['step', 1], ['step', 3], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '5X99']]}, {'berths': [None, '5X99', '5X99', None], 'clashes': [2], 'exited': ['????']}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('sampled regression 23', {'berths': 3, 'events': [['interpose', 2, '9Z10'], ['step', 1], ['step', 2], ['cancel', 1], ['interpose', 0, '1A01'], ['step', 2]]}, {'berths': ['1A01', None, None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 29', {'berths': 5, 'events': [['interpose', 4, '1A01'], ['cancel', 4], ['step', 1], ['interpose', 1, '2B17'], ['step', 3], ['cancel', 3], ['interpose', 2, '9Z10'], ['step', 1]]}, {'berths': [None, None, '2B17', None, '????'], 'clashes': [2], 'exited': []}), ('sampled regression 32', {'berths': 3, 'events': [['step', 0], ['step', 0], ['interpose', 1, '2B17'], ['step', 1], ['interpose', 2, '5X99'], ['interpose', 1, '2B17'], ['step', 2], ['cancel', 0], ['step', 0]]}, {'berths': [None, '????', None], 'clashes': [1, 1], 'exited': ['5X99']})], [('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 34', {'berths': 3, 'events': [['step', 2], ['step', 0], ['interpose', 2, '9Z10'], ['step', 1], ['cancel', 1], ['step', 0], ['step', 2]]}, {'berths': [None, '????', None], 'clashes': [2], 'exited': ['????', '????']}), ('sampled regression 44', {'berths': 3, 'events': [['step', 1], ['step', 1], ['interpose', 1, '9Z10']]}, {'berths': [None, '9Z10', '????'], 'clashes': [2], 'exited': []}), ('boundary: stepping from the penultimate berth', {'berths': 4, 'events': [['interpose', 2, '5X99'], ['step', 2]]}, {'berths': [None, None, None, '5X99'], 'clashes': [], 'exited': []}), ('boundary: step from an empty berth', {'berths': 3, 'events': [['step', 0]]}, {'berths': [None, '????', None], 'clashes': [], 'exited': []}), ('control 37', {'berths': 4, 'events': [['step', 1], ['cancel', 1], ['step', 3], ['interpose', 0, '9Z10']]}, {'berths': ['9Z10', None, '????', None], 'clashes': [], 'exited': ['????']}), ('sampled regression 40', {'berths': 4, 'events': [['step', 3], ['step', 1], ['interpose', 3, '5X99'], ['step', 2], ['interpose', 2, '5X99'], ['step', 3], ['step', 0], ['step', 1]]}, {'berths': [None, None, '????', None], 'clashes': [3, 2], 'exited': ['????', '????']}), ('control 43', {'berths': 4, 'events': [['interpose', 2, '9Z10'], ['interpose', 3, '5X99'], ['step', 0], ['interpose', 2, '1A01']]}, {'berths': [None, '????', '1A01', '5X99'], 'clashes': [], 'exited': []})], [('regression: clash with a different train', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '2B17'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('regression: clash with the same headcode', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['interpose', 1, '1A01'], ['step', 0]]}, {'berths': [None, '1A01', None], 'clashes': [1], 'exited': []}), ('sampled regression 48', {'berths': 4, 'events': [['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 0, '9Z10'], ['interpose', 1, '1A01'], ['cancel', 2], ['step', 2]]}, {'berths': ['9Z10', '1A01', None, '????'], 'clashes': [3, 1, 3], 'exited': []}), ('sampled regression 55', {'berths': 3, 'events': [['interpose', 1, '1A01'], ['step', 0], ['step', 2], ['step', 2], ['step', 2], ['step', 0], ['step', 0], ['interpose', 1, '1A01']]}, {'berths': [None, '1A01', None], 'clashes': [1, 1, 1], 'exited': ['????', '????', '????']}), ('boundary: normal stepping', {'berths': 3, 'events': [['interpose', 0, '1A01'], ['step', 0], ['step', 1]]}, {'berths': [None, None, '1A01'], 'clashes': [], 'exited': []}), ('control 45', {'berths': 3, 'events': [['interpose', 0, '9Z10'], ['interpose', 0, '5X99'], ['interpose', 0, '2B17']]}, {'berths': ['2B17', None, None], 'clashes': [], 'exited': []}), ('sampled regression 51', {'berths': 3, 'events': [['step', 2], ['step', 2], ['interpose', 1, '5X99'], ['interpose', 1, '9Z10'], ['step', 0], ['step', 0], ['interpose', 2, '9Z10'], ['step', 0], ['step', 0]]}, {'berths': [None, '????', '9Z10'], 'clashes': [1, 1, 1, 1], 'exited': ['????', '????']}), ('sampled regression 54', {'berths': 3, 'events': [['step', 2], ['step', 2], ['step', 2], ['step', 1], ['interpose', 2, '5X99'], ['step', 0], ['step', 1], ['step', 2]]}, {'berths': [None, None, None], 'clashes': [2], 'exited': ['????', '????', '????', '????']})]]
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:
Overwriting a description in an occupied berth goes unreported.

A train describer has berths 0..n-1. interpose writes a headcode, cancel blanks a berth. step i moves the description from berth i to i+1 (or out of the area from the last berth, recorded in exited); stepping an empty berth carries the unknown description ????. Stepping onto a filled berth records a clash at the destination and the stepped description overwrites it. The source berth is always blanked.

split: open-access


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

N = 1
observations = []
def solve(x):
    lamps = x['lamps']
    need = {'G': ['G'], 'YY': ['Y1', 'Y2'], 'Y': ['Y1'], 'R': ['R']}
    order = ['G', 'YY', 'Y', 'R']
    def lit(l):
        return lamps[l]['main']
    shown = 'DARK'
    for asp in order[order.index(x['requested']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or any(not lamps[l]['main'] for l in need[shown])
    return {'shown': shown, 'alarm': alarm, 'degraded': shown != x['requested']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 2', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('control 1', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 4', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 7', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 30', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('boundary: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 12', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False}), ('sampled regression 15', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 18', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': True, 'degraded': False})], [('regression: second yellow on auxiliary', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('sampled regression 69', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 23', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 26', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 29', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('regression: second yellow on auxiliary', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('boundary: unused lamp on auxiliary', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('sampled regression 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 37', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 40', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})], [('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 25', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 53', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: all yellows dead', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('control 45', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': False}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 48', {'requested': 'G', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 51', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})]]
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):
    lamps = x['lamps']
    need = {'G': ['G'], 'YY': ['Y1', 'Y2'], 'Y': ['Y1'], 'R': ['R']}
    order = ['G', 'YY', 'Y', 'R']
    def lit(l):
        return lamps[l]['main'] or (lamps[l]['aux'] and l != 'R')
    shown = 'DARK'
    for asp in order[order.index(x['requested']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or any(not lamps[l]['main'] for l in need[shown])
    return {'shown': shown, 'alarm': alarm, 'degraded': shown != x['requested']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 2', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('control 1', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 4', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 7', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 30', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('boundary: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 12', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False}), ('sampled regression 15', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 18', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': True, 'degraded': False})], [('regression: second yellow on auxiliary', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('sampled regression 69', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 23', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 26', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 29', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('regression: second yellow on auxiliary', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('boundary: unused lamp on auxiliary', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('sampled regression 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 37', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 40', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})], [('regression: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('sampled regression 25', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('sampled regression 53', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('boundary: all yellows dead', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('control 45', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': False}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 48', {'requested': 'G', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 51', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})]]
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 signal degrades although its auxiliary filament is working.

Aspects need lamps: G needs G; YY needs Y1 and Y2; Y needs Y1; R needs R. A lamp is lit if its main or auxiliary filament works. If the requested aspect cannot be lit, show the next more restrictive aspect that can (G, YY, Y, R); if even R cannot be lit the signal is DARK. alarm is raised if the signal is DARK or any lamp used by the shown aspect runs on its auxiliary filament. degraded means shown != requested.

split: open-access


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

N = 1
observations = []
def solve(x):
    lamps = x['lamps']
    need = {'G': ['G'], 'YY': ['Y1', 'Y2'], 'Y': ['Y1'], 'R': ['R']}
    order = ['G', 'YY', 'Y', 'R']
    def lit(l):
        return lamps[l]['main'] or lamps[l]['aux']
    shown = 'DARK'
    for asp in order[:order.index(x['requested']) + 1][::-1]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or any(not lamps[l]['main'] for l in need[shown])
    return {'shown': shown, 'alarm': alarm, 'degraded': shown != x['requested']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('boundary: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 1', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 4', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 7', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('sampled regression 70', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('sampled regression 14', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 12', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False}), ('control 15', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('control 18', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': True, 'degraded': False})], [('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('sampled regression 14', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': True}), ('sampled regression 58', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('control 23', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 26', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 29', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('boundary: unused lamp on auxiliary', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 37', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 40', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})], [('regression: all yellows dead', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('control 45', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': False}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 48', {'requested': 'G', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 51', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})]]
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):
    lamps = x['lamps']
    need = {'G': ['G'], 'YY': ['Y1', 'Y2'], 'Y': ['Y1'], 'R': ['R']}
    order = ['G', 'YY', 'Y', 'R']
    def lit(l):
        return lamps[l]['main'] or lamps[l]['aux']
    shown = 'DARK'
    for asp in [x['requested'], 'R']:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or any(not lamps[l]['main'] for l in need[shown])
    return {'shown': shown, 'alarm': alarm, 'degraded': shown != x['requested']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('boundary: red on auxiliary filament', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 1', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 4', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 7', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('sampled regression 70', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('sampled regression 14', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('control 12', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False}), ('control 15', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('control 18', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': True, 'degraded': False})], [('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('sampled regression 14', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': True}), ('sampled regression 58', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('control 23', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 26', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 29', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False})], [('regression: red lamp dead', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('regression: upper yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('boundary: unused lamp on auxiliary', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('control 34', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': True, 'degraded': False}), ('control 37', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 40', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})], [('regression: all yellows dead', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('regression: green lamp dead', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': False, 'degraded': True}), ('sampled regression 62', {'requested': 'Y', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': True, 'degraded': True}), ('regression: lower yellow dead under double yellow', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': False}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, 'degraded': True}), ('boundary: green on auxiliary filament', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': True}}}, {'shown': 'G', 'alarm': True, 'degraded': False}), ('control 45', {'requested': 'G', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': True, 'aux': False}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 48', {'requested': 'G', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'G', 'alarm': False, 'degraded': False}), ('control 51', {'requested': 'YY', 'lamps': {'R': {'main': False, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'YY', 'alarm': False, 'degraded': False})]]
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 signal with a failed lamp shows a less restrictive aspect than requested.

Aspects need lamps: G needs G; YY needs Y1 and Y2; Y needs Y1; R needs R. A lamp is lit if its main or auxiliary filament works. If the requested aspect cannot be lit, show the next more restrictive aspect that can (G, YY, Y, R); if even R cannot be lit the signal is DARK. alarm is raised if the signal is DARK or any lamp used by the shown aspect runs on its auxiliary filament. degraded means shown != requested.

split: open-access