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': ['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']):]:
        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: 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}), ('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}), ('sampled regression 17', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('boundary: 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}), ('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 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: 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}), ('boundary: 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 13', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('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}), ('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 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 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}), ('control 21', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, '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}), ('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}), ('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}), ('control 47', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: 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: 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}), ('boundary: 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}), ('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: 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}), ('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}), ('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: 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}), ('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}), ('sampled regression 65', {'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}), ('boundary: 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}), ('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}), ('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'], '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']):]:
        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: 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}), ('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}), ('sampled regression 17', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('boundary: 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}), ('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 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: 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}), ('boundary: 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 13', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': False}, 'G': {'main': False, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': True}), ('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}), ('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 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 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}), ('control 21', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', 'alarm': False, '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}), ('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}), ('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}), ('control 47', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: 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: 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}), ('boundary: 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}), ('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: 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}), ('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}), ('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: 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}), ('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}), ('sampled regression 65', {'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}), ('boundary: 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}), ('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}), ('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 double yellow is displayed with one of its two lamps dark.

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']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or any(not v['main'] for v in lamps.values())
    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}), ('boundary: 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: 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 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}), ('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 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}), ('boundary: 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 19', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('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}), ('sampled regression 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}), ('boundary: 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 36', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 47', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: 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: 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}), ('boundary: 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 54', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', '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}), ('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}), ('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}), ('sampled regression 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}), ('sampled regression 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}), ('boundary: 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 77', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('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 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}), ('sampled regression 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}), ('sampled regression 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)

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):
    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']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown == 'DARK' or not lamps[need[shown][0]]['main']
    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}), ('boundary: 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: 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 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}), ('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 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}), ('boundary: 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 19', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': True}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('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}), ('sampled regression 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}), ('boundary: 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 36', {'requested': 'R', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': False, 'aux': True}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'R', 'alarm': False, 'degraded': False}), ('control 47', {'requested': 'YY', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'YY', 'alarm': True, 'degraded': False}), ('boundary: 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: 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}), ('boundary: 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 54', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': True}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': True}}}, {'shown': 'Y', '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}), ('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}), ('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}), ('sampled regression 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}), ('sampled regression 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}), ('boundary: 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 77', {'requested': 'Y', 'lamps': {'R': {'main': True, 'aux': False}, 'Y1': {'main': True, 'aux': False}, 'Y2': {'main': False, 'aux': True}, 'G': {'main': True, 'aux': False}}}, {'shown': 'Y', 'alarm': False, 'degraded': False}), ('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 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}), ('sampled regression 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}), ('sampled regression 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 filament alarm is raised for a lamp that is not in use, or missed for one that is.

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']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = shown != 'DARK' and 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: 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, '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}), ('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 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('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}), ('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: 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}), ('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}), ('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}), ('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}), ('boundary: 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}), ('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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', '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}), ('boundary: 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}), ('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}), ('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: 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('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}), ('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 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 order[order.index(x['requested']):]:
        if all(lit(l) for l in need[asp]):
            shown = asp
            break
    alarm = any(not lamps[l]['main'] for l in need.get(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: 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, '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}), ('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 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('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}), ('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: 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}), ('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}), ('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}), ('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}), ('boundary: 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}), ('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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', '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}), ('boundary: 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}), ('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}), ('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: 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}), ('sampled regression 43', {'requested': 'R', 'lamps': {'R': {'main': False, 'aux': False}, 'Y1': {'main': False, 'aux': False}, 'Y2': {'main': True, 'aux': True}, 'G': {'main': False, 'aux': False}}}, {'shown': 'DARK', 'alarm': True, 'degraded': True}), ('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}), ('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 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 completely dark signal raises no alarm.

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):
    mode = x['mode']
    state = 'danger'
    stick = False
    prev_route = False
    out = []
    for occ, route, appr in x['steps']:
        if mode == 'auto':
            route = True
        if (route and not prev_route) or mode == 'auto':
            stick = False
        if occ:
            pass
            state = 'danger'
        elif route and not stick and (mode != 'approach' or appr):
            state = 'clear'
        else:
            state = 'danger'
        prev_route = route
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 5', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True], [False, True, True], [True, True, False], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'danger']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('control 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('sampled regression 4', {'mode': 'controlled', 'steps': [[False, False, False], [False, True, True], [True, True, True], [False, True, True], [False, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger']), ('control 7', {'mode': 'approach', 'steps': [[False, False, False], [False, False, False], [False, False, True], [False, False, True], [False, True, False], [False, False, True], [False, True, True], [False, True, True], [False, True, True], [True, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'clear', 'clear', 'danger'])], [('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 64', {'mode': 'approach', 'steps': [[True, True, True], [False, False, True], [False, True, True], [True, True, True], [True, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('sampled regression 50', {'mode': 'approach', 'steps': [[True, True, True], [False, True, True], [True, True, False], [True, True, False], [False, True, True], [False, False, False], [False, False, False], [True, False, True], [False, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('control 12', {'mode': 'controlled', 'steps': [[False, False, True], [False, True, True], [True, False, True], [False, False, False], [False, False, True], [True, True, True], [True, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 15', {'mode': 'approach', 'steps': [[False, True, True], [False, True, False], [False, True, True]]}, ['clear', 'danger', 'clear']), ('control 18', {'mode': 'approach', 'steps': [[False, True, False], [False, False, False], [False, False, False], [True, True, False], [False, True, False], [True, True, True], [False, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear'])], [('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 19', {'mode': 'controlled', 'steps': [[True, False, False], [False, False, True], [True, True, True], [False, False, True], [False, False, True], [False, True, True], [True, True, True], [False, True, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'danger', 'danger']), ('sampled regression 64', {'mode': 'approach', 'steps': [[True, True, True], [False, False, True], [False, True, True], [True, True, True], [True, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 23', {'mode': 'controlled', 'steps': [[False, True, True], [False, True, False], [False, True, True], [True, True, False], [False, True, False]]}, ['clear', 'clear', 'clear', 'danger', 'danger']), ('control 26', {'mode': 'approach', 'steps': [[False, False, False], [False, True, True], [True, True, False], [True, False, True], [True, True, False], [True, False, True], [False, False, False], [False, True, True], [False, False, True], [False, True, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'danger', 'danger']), ('control 29', {'mode': 'auto', 'steps': [[True, False, False], [False, False, False], [True, False, False], [False, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, False], [True, False, True], [False, True, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear'])], [('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('control 34', {'mode': 'approach', 'steps': [[False, True, True], [False, False, False], [False, True, True], [False, False, False], [True, False, True], [False, False, True], [True, False, False], [True, False, True]]}, ['clear', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 37', {'mode': 'approach', 'steps': [[False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, False, True], [False, False, False], [False, False, True], [False, False, True], [False, False, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 40', {'mode': 'auto', 'steps': [[False, True, True], [True, True, True], [False, True, True], [False, True, False], [True, False, True], [True, False, True], [True, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger'])], [('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 24', {'mode': 'controlled', 'steps': [[False, False, True], [False, False, True], [False, True, False], [False, True, True], [False, True, True], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'clear', 'clear', 'danger', 'danger', 'danger']), ('sampled regression 5', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True], [False, True, True], [True, True, False], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'danger']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('control 45', {'mode': 'approach', 'steps': [[False, False, False], [False, False, False], [False, True, False], [False, True, False], [True, True, False], [False, True, False], [False, True, False], [False, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear']), ('control 48', {'mode': 'approach', 'steps': [[True, True, False], [False, True, True], [False, False, False], [False, False, True], [False, True, True], [True, True, False]]}, ['danger', 'clear', 'danger', 'danger', 'clear', 'danger']), ('control 51', {'mode': 'controlled', 'steps': [[False, False, True], [False, False, False], [False, True, False], [False, True, True], [True, False, True], [False, False, True], [True, True, False]]}, ['danger', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger'])]]
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):
    mode = x['mode']
    state = 'danger'
    stick = False
    prev_route = False
    out = []
    for occ, route, appr in x['steps']:
        if mode == 'auto':
            route = True
        if (route and not prev_route) or mode == 'auto':
            stick = False
        if occ:
            if state == 'clear' and mode == 'controlled':
                stick = True
            state = 'danger'
        elif route and not stick and (mode != 'approach' or appr):
            state = 'clear'
        else:
            state = 'danger'
        prev_route = route
        out.append(state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 5', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True], [False, True, True], [True, True, False], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'danger']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('control 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('sampled regression 4', {'mode': 'controlled', 'steps': [[False, False, False], [False, True, True], [True, True, True], [False, True, True], [False, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger']), ('control 7', {'mode': 'approach', 'steps': [[False, False, False], [False, False, False], [False, False, True], [False, False, True], [False, True, False], [False, False, True], [False, True, True], [False, True, True], [False, True, True], [True, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'clear', 'clear', 'danger'])], [('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 64', {'mode': 'approach', 'steps': [[True, True, True], [False, False, True], [False, True, True], [True, True, True], [True, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('sampled regression 50', {'mode': 'approach', 'steps': [[True, True, True], [False, True, True], [True, True, False], [True, True, False], [False, True, True], [False, False, False], [False, False, False], [True, False, True], [False, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('control 12', {'mode': 'controlled', 'steps': [[False, False, True], [False, True, True], [True, False, True], [False, False, False], [False, False, True], [True, True, True], [True, False, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 15', {'mode': 'approach', 'steps': [[False, True, True], [False, True, False], [False, True, True]]}, ['clear', 'danger', 'clear']), ('control 18', {'mode': 'approach', 'steps': [[False, True, False], [False, False, False], [False, False, False], [True, True, False], [False, True, False], [True, True, True], [False, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear'])], [('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 19', {'mode': 'controlled', 'steps': [[True, False, False], [False, False, True], [True, True, True], [False, False, True], [False, False, True], [False, True, True], [True, True, True], [False, True, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'danger', 'danger']), ('sampled regression 64', {'mode': 'approach', 'steps': [[True, True, True], [False, False, True], [False, True, True], [True, True, True], [True, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 23', {'mode': 'controlled', 'steps': [[False, True, True], [False, True, False], [False, True, True], [True, True, False], [False, True, False]]}, ['clear', 'clear', 'clear', 'danger', 'danger']), ('control 26', {'mode': 'approach', 'steps': [[False, False, False], [False, True, True], [True, True, False], [True, False, True], [True, True, False], [True, False, True], [False, False, False], [False, True, True], [False, False, True], [False, True, False]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear', 'danger', 'danger']), ('control 29', {'mode': 'auto', 'steps': [[True, False, False], [False, False, False], [True, False, False], [False, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, False], [True, False, True], [False, True, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear'])], [('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('control 34', {'mode': 'approach', 'steps': [[False, True, True], [False, False, False], [False, True, True], [False, False, False], [True, False, True], [False, False, True], [True, False, False], [True, False, True]]}, ['clear', 'danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 37', {'mode': 'approach', 'steps': [[False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, False, True], [False, False, False], [False, False, True], [False, False, True], [False, False, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 40', {'mode': 'auto', 'steps': [[False, True, True], [True, True, True], [False, True, True], [False, True, False], [True, False, True], [True, False, True], [True, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger'])], [('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 24', {'mode': 'controlled', 'steps': [[False, False, True], [False, False, True], [False, True, False], [False, True, True], [False, True, True], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'danger', 'clear', 'clear', 'clear', 'danger', 'danger', 'danger']), ('sampled regression 5', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True], [False, True, True], [True, True, False], [True, True, True], [False, True, True], [False, True, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'danger']), ('boundary: route re-set after a train', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear']), ('control 45', {'mode': 'approach', 'steps': [[False, False, False], [False, False, False], [False, True, False], [False, True, False], [True, True, False], [False, True, False], [False, True, False], [False, True, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'clear']), ('control 48', {'mode': 'approach', 'steps': [[True, True, False], [False, True, True], [False, False, False], [False, False, True], [False, True, True], [True, True, False]]}, ['danger', 'clear', 'danger', 'danger', 'clear', 'danger']), ('control 51', {'mode': 'controlled', 'steps': [[False, False, True], [False, False, False], [False, True, False], [False, True, True], [True, False, True], [False, False, True], [True, True, False]]}, ['danger', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger'])]]
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 re-clears behind a train for a following train on the same route setting.

Each step gives [section beyond occupied, route set, approach occupied]. An auto signal behaves as permanently routed. A signal shows danger whenever the section beyond is occupied; a signal that was clear when a train occupies that section latches a stick that keeps it at danger until the route is set afresh (off then on); auto signals drop the stick every step. Otherwise it clears when routed, not stuck, and for approach-released signals only with the approach occupied. Output the state per step.

split: open-access