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

N = 1
observations = []
def solve(x):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 56', {'occupied': [False, False, False, True, False], 'lamp_fail': [3], 'diverging': [], 'open_end': False}, ['YY', 'Y', 'R', 'DARK', 'Y']), ('sampled regression 63', {'occupied': [False, False, False, False, False, True, False], 'lamp_fail': [5, 6], 'diverging': [], 'open_end': True}, ['G', 'G', 'YY', 'Y', 'R', 'DARK', 'G']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('sampled regression 56', {'occupied': [False, False, False, True, False], 'lamp_fail': [3], 'diverging': [], 'open_end': False}, ['YY', 'Y', 'R', 'DARK', 'Y']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('control 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 76', {'occupied': [False, True, False, True, True], 'lamp_fail': [3, 4], 'diverging': [1], 'open_end': False}, ['Y', 'R', 'R', 'DARK', 'DARK']), ('sampled regression 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 78', {'occupied': [False, False, False, False, True, False, False], 'lamp_fail': [4, 5], 'diverging': [6], 'open_end': False}, ['G', 'YY', 'Y', 'R', 'DARK', 'YY', 'Y']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 80', {'occupied': [False, False, False, False, False, False, True], 'lamp_fail': [6], 'diverging': [], 'open_end': False}, ['G', 'G', 'G', 'YY', 'Y', 'R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('sampled regression 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' and x['open_end'] else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 56', {'occupied': [False, False, False, True, False], 'lamp_fail': [3], 'diverging': [], 'open_end': False}, ['YY', 'Y', 'R', 'DARK', 'Y']), ('sampled regression 63', {'occupied': [False, False, False, False, False, True, False], 'lamp_fail': [5, 6], 'diverging': [], 'open_end': True}, ['G', 'G', 'YY', 'Y', 'R', 'DARK', 'G']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('sampled regression 56', {'occupied': [False, False, False, True, False], 'lamp_fail': [3], 'diverging': [], 'open_end': False}, ['YY', 'Y', 'R', 'DARK', 'Y']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('control 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 76', {'occupied': [False, True, False, True, True], 'lamp_fail': [3, 4], 'diverging': [1], 'open_end': False}, ['Y', 'R', 'R', 'DARK', 'DARK']), ('sampled regression 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 78', {'occupied': [False, False, False, False, True, False, False], 'lamp_fail': [4, 5], 'diverging': [6], 'open_end': False}, ['G', 'YY', 'Y', 'R', 'DARK', 'YY', 'Y']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 80', {'occupied': [False, False, False, False, False, False, True], 'lamp_fail': [6], 'diverging': [], 'open_end': False}, ['G', 'G', 'G', 'YY', 'Y', 'R', 'DARK']), ('sampled regression 75', {'occupied': [False, False, True, False], 'lamp_fail': [0, 2], 'diverging': [0, 2, 3], 'open_end': False}, ['Y', 'R', 'DARK', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('sampled regression 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The signal in rear of a dark signal shows a proceed aspect.

Signals 0..n-1 each protect one block; occupied[i] is the block after signal i. Evaluate from the far end: a signal shows R if its block is occupied, else Y if the next signal is R, R if the next signal is DARK, YY if the next is Y, otherwise G. Beyond the last signal the next aspect is G on an open line and R at a buffer stop. A diverging signal is capped at Y. A signal whose red lamp has failed shows DARK instead of R.

split: open-access


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

N = 1
observations = []
def solve(x):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 2', {'occupied': [False, True, False, False, False, False, True], 'lamp_fail': [2, 4], 'diverging': [1], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y', 'R']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R']), ('control 10', {'occupied': [True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['R', 'G'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G']), ('sampled regression 36', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [0, 1], 'open_end': True}, ['Y', 'Y']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('sampled regression 53', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [2], 'diverging': [0], 'open_end': True}, ['Y', 'YY', 'Y', 'R', 'G', 'G', 'G']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('sampled regression 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 68', {'occupied': [False, True, False, False, False], 'lamp_fail': [2, 3], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'YY', 'Y']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a in ('R', 'Y') and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 2', {'occupied': [False, True, False, False, False, False, True], 'lamp_fail': [2, 4], 'diverging': [1], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y', 'R']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R']), ('control 10', {'occupied': [True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['R', 'G'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G']), ('sampled regression 36', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [0, 1], 'open_end': True}, ['Y', 'Y']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('sampled regression 53', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [2], 'diverging': [0], 'open_end': True}, ['Y', 'YY', 'Y', 'R', 'G', 'G', 'G']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('sampled regression 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 68', {'occupied': [False, True, False, False, False], 'lamp_fail': [2, 3], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'YY', 'Y']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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:
Signals with a failed red filament go dark even while showing a proceed aspect.

Signals 0..n-1 each protect one block; occupied[i] is the block after signal i. Evaluate from the far end: a signal shows R if its block is occupied, else Y if the next signal is R, R if the next signal is DARK, YY if the next is Y, otherwise G. Beyond the last signal the next aspect is G on an open line and R at a buffer stop. A diverging signal is capped at Y. A signal whose red lamp has failed shows DARK instead of R.

split: open-access


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

N = 1
observations = []
def solve(x):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a == 'G':
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('control 9', {'occupied': [False, False, False, False, True, False, False], 'lamp_fail': [1], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'YY', 'Y', 'R', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 64', {'occupied': [False, False, True, False, False, True], 'lamp_fail': [4], 'diverging': [0], 'open_end': False}, ['Y', 'Y', 'R', 'YY', 'Y', 'R']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 28', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [6], 'diverging': [1, 5], 'open_end': True}, ['YY', 'Y', 'Y', 'R', 'YY', 'Y', 'G']), ('control 44', {'occupied': [False, False], 'lamp_fail': [0, 1], 'diverging': [1], 'open_end': True}, ['YY', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('control 58', {'occupied': [True, False], 'lamp_fail': [0], 'diverging': [0, 1], 'open_end': True}, ['DARK', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 39', {'occupied': [False, False, True, False, False, True], 'lamp_fail': [0, 4], 'diverging': [3], 'open_end': False}, ['YY', 'Y', 'R', 'Y', 'Y', 'R']), ('control 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a == 'YY':
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('control 9', {'occupied': [False, False, False, False, True, False, False], 'lamp_fail': [1], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'YY', 'Y', 'R', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 64', {'occupied': [False, False, True, False, False, True], 'lamp_fail': [4], 'diverging': [0], 'open_end': False}, ['Y', 'Y', 'R', 'YY', 'Y', 'R']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 28', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [6], 'diverging': [1, 5], 'open_end': True}, ['YY', 'Y', 'Y', 'R', 'YY', 'Y', 'G']), ('control 44', {'occupied': [False, False], 'lamp_fail': [0, 1], 'diverging': [1], 'open_end': True}, ['YY', 'Y']), ('boundary: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('control 58', {'occupied': [True, False], 'lamp_fail': [0], 'diverging': [0, 1], 'open_end': True}, ['DARK', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('boundary: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 39', {'occupied': [False, False, True, False, False, True], 'lamp_fail': [0, 4], 'diverging': [3], 'open_end': False}, ['YY', 'Y', 'R', 'Y', 'Y', 'R']), ('control 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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 diverging junction signal displays a preliminary caution or green.

Signals 0..n-1 each protect one block; occupied[i] is the block after signal i. Evaluate from the far end: a signal shows R if its block is occupied, else Y if the next signal is R, R if the next signal is DARK, YY if the next is Y, otherwise G. Beyond the last signal the next aspect is G on an open line and R at a buffer stop. A diverging signal is capped at Y. A signal whose red lamp has failed shows DARK instead of R.

split: open-access


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

N = 1
observations = []
def solve(x):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 3', {'occupied': [True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['R', 'G', 'YY', 'Y']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 41', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 14', {'occupied': [False, False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'YY', 'Y', 'R', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: open line', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 67', {'occupied': [False, True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'YY', 'Y']), ('control 28', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [6], 'diverging': [1, 5], 'open_end': True}, ['YY', 'Y', 'Y', 'R', 'YY', 'Y', 'G']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('sampled regression 3', {'occupied': [True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['R', 'G', 'YY', 'Y']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 41', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 66', {'occupied': [False, False, False], 'lamp_fail': [2], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'Y' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 3', {'occupied': [True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['R', 'G', 'YY', 'Y']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('control 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: diverging junction behind a green', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G']), ('sampled regression 41', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 14', {'occupied': [False, False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'YY', 'Y', 'R', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: open line', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 67', {'occupied': [False, True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'YY', 'Y']), ('control 28', {'occupied': [False, False, False, True, False, False, False], 'lamp_fail': [6], 'diverging': [1, 5], 'open_end': True}, ['YY', 'Y', 'Y', 'R', 'YY', 'Y', 'G']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('control 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('sampled regression 3', {'occupied': [True, False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['R', 'G', 'YY', 'Y']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('control 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('sampled regression 41', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('control 66', {'occupied': [False, False, False], 'lamp_fail': [2], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('control 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('control 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The last signal before a buffer stop shows green.

Signals 0..n-1 each protect one block; occupied[i] is the block after signal i. Evaluate from the far end: a signal shows R if its block is occupied, else Y if the next signal is R, R if the next signal is DARK, YY if the next is Y, otherwise G. Beyond the last signal the next aspect is G on an open line and R at a buffer stop. A diverging signal is capped at Y. A signal whose red lamp has failed shows DARK instead of R.

split: open-access


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

N = 1
observations = []
def solve(x):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt == 'Y':
            a = 'G'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('sampled regression 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R']), ('control 10', {'occupied': [True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['R', 'G'])], [('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 13', {'occupied': [False, True, False, False, False, False, True], 'lamp_fail': [3, 5], 'diverging': [], 'open_end': True}, ['Y', 'R', 'G', 'G', 'YY', 'Y', 'R']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G']), ('control 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('sampled regression 22', {'occupied': [True, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['DARK', 'G', 'YY', 'Y']), ('boundary: open line', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('sampled regression 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G']), ('control 43', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 47', {'occupied': [False, False, False, False, False], 'lamp_fail': [2], 'diverging': [], 'open_end': False}, ['G', 'G', 'G', 'YY', 'Y']), ('sampled regression 54', {'occupied': [False, False, True, False, False, False, False], 'lamp_fail': [5], 'diverging': [3], 'open_end': False}, ['YY', 'Y', 'R', 'Y', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('sampled regression 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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):
    occ = x['occupied']
    n = len(occ)
    fail = set(x['lamp_fail'])
    div = set(x['diverging'])
    nxt = 'G' if x['open_end'] else 'R'
    out = [None] * n
    for i in range(n - 1, -1, -1):
        if occ[i]:
            a = 'R'
        elif nxt in ('R', 'DARK'):
            a = 'R' if nxt == 'DARK' else 'Y'
        elif nxt in ('Y', 'YY'):
            a = 'YY'
        else:
            a = 'G'
        if i in div and a in ('YY', 'G'):
            a = 'Y'
        if a == 'R' and i in fail:
            a = 'DARK'
        out[i] = a
        nxt = a
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 1', {'occupied': [False, True, False, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['Y', 'R', 'G', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('boundary: failed red lamp on a clear signal', {'occupied': [False, False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('control 4', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R']), ('sampled regression 7', {'occupied': [True, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': True}, ['R', 'YY', 'Y', 'R']), ('control 10', {'occupied': [True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['R', 'G'])], [('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 12', {'occupied': [False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('sampled regression 13', {'occupied': [False, True, False, False, False, False, True], 'lamp_fail': [3, 5], 'diverging': [], 'open_end': True}, ['Y', 'R', 'G', 'G', 'YY', 'Y', 'R']), ('boundary: diverging junction behind a double yellow', {'occupied': [False, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['Y', 'Y', 'R']), ('control 15', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['Y', 'R']), ('control 18', {'occupied': [False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G']), ('control 21', {'occupied': [True, False, True, False, False, False], 'lamp_fail': [1, 5], 'diverging': [1, 3], 'open_end': True}, ['R', 'Y', 'R', 'Y', 'G', 'G'])], [('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 24', {'occupied': [False, False, False, True], 'lamp_fail': [1], 'diverging': [1], 'open_end': True}, ['YY', 'Y', 'Y', 'R']), ('sampled regression 22', {'occupied': [True, False, False, False], 'lamp_fail': [0], 'diverging': [], 'open_end': False}, ['DARK', 'G', 'YY', 'Y']), ('boundary: open line', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['G', 'G', 'G']), ('control 23', {'occupied': [True, False, True], 'lamp_fail': [], 'diverging': [0], 'open_end': True}, ['R', 'Y', 'R']), ('sampled regression 26', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [3], 'open_end': False}, ['G', 'YY', 'Y', 'R']), ('control 29', {'occupied': [False, True], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['Y', 'R'])], [('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 34', {'occupied': [False, False, False, False, False, False, False], 'lamp_fail': [], 'diverging': [1], 'open_end': False}, ['YY', 'Y', 'G', 'G', 'G', 'YY', 'Y']), ('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: dark signal at the buffer end', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': False}, ['YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('sampled regression 37', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0, 3], 'open_end': True}, ['Y', 'G', 'YY', 'Y']), ('control 40', {'occupied': [False, False, False, False], 'lamp_fail': [0], 'diverging': [0], 'open_end': True}, ['Y', 'G', 'G', 'G']), ('control 43', {'occupied': [False, False], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['G', 'G'])], [('regression: train two blocks ahead', {'occupied': [False, False, True, False], 'lamp_fail': [], 'diverging': [], 'open_end': True}, ['YY', 'Y', 'R', 'G']), ('regression: buffer stop at the end', {'occupied': [False, False, False], 'lamp_fail': [], 'diverging': [], 'open_end': False}, ['G', 'YY', 'Y']), ('sampled regression 47', {'occupied': [False, False, False, False, False], 'lamp_fail': [2], 'diverging': [], 'open_end': False}, ['G', 'G', 'G', 'YY', 'Y']), ('sampled regression 54', {'occupied': [False, False, True, False, False, False, False], 'lamp_fail': [5], 'diverging': [3], 'open_end': False}, ['YY', 'Y', 'R', 'Y', 'G', 'YY', 'Y']), ('boundary: dark signal ahead', {'occupied': [False, True], 'lamp_fail': [1], 'diverging': [], 'open_end': True}, ['R', 'DARK']), ('control 45', {'occupied': [True, False, False, True], 'lamp_fail': [3], 'diverging': [1], 'open_end': True}, ['R', 'Y', 'R', 'DARK']), ('sampled regression 48', {'occupied': [False, False, False, False], 'lamp_fail': [1], 'diverging': [2], 'open_end': True}, ['G', 'YY', 'Y', 'G']), ('sampled regression 51', {'occupied': [False, False, False, True], 'lamp_fail': [], 'diverging': [0, 2, 3], 'open_end': True}, ['Y', 'YY', 'Y', 'R'])]]
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 two blocks behind a red shows green instead of double yellow.

Signals 0..n-1 each protect one block; occupied[i] is the block after signal i. Evaluate from the far end: a signal shows R if its block is occupied, else Y if the next signal is R, R if the next signal is DARK, YY if the next is Y, otherwise G. Beyond the last signal the next aspect is G on an open line and R at a buffer stop. A diverging signal is capped at Y. A signal whose red lamp has failed shows DARK instead of R.

split: open-access


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

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': False}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 13', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 2999}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 5', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('sampled regression 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 67', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 22', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 21', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 75', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 4500}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 30', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 42', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': 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):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos != cmd}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 13', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 2999}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 5', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('sampled regression 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 67', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 22', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 21', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 75', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 4500}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('sampled regression 30', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 42', {'pos': 'R', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'route-locked', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': 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 locked point without detection raises no alarm, or a healthy locked point raises one.

A point command is answered as in-position when already detected in the commanded lie (even if locked or occupied). Otherwise route locking refuses (route-locked), then track locking refuses (track-locked); the alarm flag on refusals is raised only when the point has lost detection (X). A throw that fails to regain detection within limit_ms (inclusive; None means never) leaves the point X with alarm; otherwise it lies in the commanded position. detected_ms of 0 means detection was immediate.

split: open-access