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 or mode == 'auto':
            stick = False
        if occ:
            if state == 'clear':
                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']), ('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']), ('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']), ('control 17', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, True], [False, False, False], [True, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear', 'clear', 'danger', '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']), ('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']), ('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: 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']), ('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']), ('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']), ('control 49', {'mode': 'controlled', 'steps': [[False, False, False], [True, True, False], [False, True, True], [True, False, False], [True, False, True], [False, False, False], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'clear']), ('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']), ('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']), ('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('control 17', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, True], [False, False, False], [True, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [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']), ('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']), ('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']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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 and not appr) or mode == 'auto':
            stick = False
        if occ:
            if state == 'clear':
                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']), ('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']), ('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']), ('control 17', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, True], [False, False, False], [True, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear', 'clear', 'danger', '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']), ('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']), ('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: 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']), ('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']), ('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']), ('control 49', {'mode': 'controlled', 'steps': [[False, False, False], [True, True, False], [False, True, True], [True, False, False], [True, False, True], [False, False, False], [False, True, True]]}, ['danger', 'danger', 'clear', 'danger', 'danger', 'danger', 'clear']), ('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']), ('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']), ('regression: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('control 17', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, False], [False, True, True], [False, True, True], [False, False, True], [False, False, False], [True, False, True], [False, True, True]]}, ['clear', 'danger', 'danger', 'clear', 'clear', 'danger', 'danger', 'danger', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [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']), ('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']), ('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']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('regression: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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:
The stick never holds a signal at danger, or it cannot be reset while a train approaches.

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


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:
            if state == 'clear':
                stick = True
            state = 'danger'
        elif route and not stick:
            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: 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']), ('sampled regression 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']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('control 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 10', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, True], [False, False, True], [False, False, False], [True, False, True], [True, False, True]]}, ['clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger'])], [('regression: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 33', {'mode': 'approach', 'steps': [[False, True, False], [True, False, True], [False, True, False], [False, False, True], [True, False, False], [False, False, False], [True, False, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 25', {'mode': 'auto', 'steps': [[False, False, True], [False, True, True], [False, False, True], [False, True, True], [False, True, False], [False, False, True], [False, True, True], [False, True, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 15', {'mode': 'approach', 'steps': [[False, True, True], [False, True, False], [False, True, True]]}, ['clear', 'danger', 'clear']), ('sampled regression 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: 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']), ('sampled regression 52', {'mode': 'approach', 'steps': [[False, True, False], [True, True, False], [True, True, False], [True, True, False], [True, True, False], [False, True, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 47', {'mode': 'auto', 'steps': [[True, True, True], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, True, False], [False, True, True], [True, True, False], [False, False, False], [False, False, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'danger', 'clear', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('control 23', {'mode': 'controlled', 'steps': [[False, True, True], [False, True, False], [False, True, True], [True, True, False], [False, True, False]]}, ['clear', 'clear', 'clear', 'danger', 'danger']), ('sampled regression 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 with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 78', {'mode': 'approach', 'steps': [[False, False, True], [False, True, True], [False, True, False], [False, True, False], [False, True, False], [True, True, True], [True, False, True], [True, True, True]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 65', {'mode': 'auto', 'steps': [[False, False, True], [False, False, False], [True, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [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: 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']), ('sampled regression 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']), ('control 74', {'mode': 'auto', 'steps': [[True, False, True], [False, False, True], [False, False, True], [True, True, False], [True, True, True], [False, True, False], [False, False, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'clear', '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']), ('sampled regression 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)

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):
    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':
                stick = True
            state = 'danger'
        elif route and not stick and (mode == 'controlled' 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: 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']), ('sampled regression 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']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('control 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 10', {'mode': 'controlled', 'steps': [[False, True, False], [True, False, True], [False, False, True], [False, False, True], [False, False, False], [True, False, True], [True, False, True]]}, ['clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger'])], [('regression: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 33', {'mode': 'approach', 'steps': [[False, True, False], [True, False, True], [False, True, False], [False, False, True], [True, False, False], [False, False, False], [True, False, True]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 25', {'mode': 'auto', 'steps': [[False, False, True], [False, True, True], [False, False, True], [False, True, True], [False, True, False], [False, False, True], [False, True, True], [False, True, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 15', {'mode': 'approach', 'steps': [[False, True, True], [False, True, False], [False, True, True]]}, ['clear', 'danger', 'clear']), ('sampled regression 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: 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']), ('sampled regression 52', {'mode': 'approach', 'steps': [[False, True, False], [True, True, False], [True, True, False], [True, True, False], [True, True, False], [False, True, False]]}, ['danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 47', {'mode': 'auto', 'steps': [[True, True, True], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, True, False], [False, True, True], [True, True, False], [False, False, False], [False, False, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'danger', 'clear', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('control 23', {'mode': 'controlled', 'steps': [[False, True, True], [False, True, False], [False, True, True], [True, True, False], [False, True, False]]}, ['clear', 'clear', 'clear', 'danger', 'danger']), ('sampled regression 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 with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 78', {'mode': 'approach', 'steps': [[False, False, True], [False, True, True], [False, True, False], [False, True, False], [False, True, False], [True, True, True], [True, False, True], [True, True, True]]}, ['danger', 'clear', 'danger', 'danger', 'danger', 'danger', 'danger', 'danger']), ('control 65', {'mode': 'auto', 'steps': [[False, False, True], [False, False, False], [True, False, False], [False, False, False], [False, True, False], [True, False, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [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: 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']), ('sampled regression 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']), ('control 74', {'mode': 'auto', 'steps': [[True, False, True], [False, False, True], [False, False, True], [True, True, False], [True, True, True], [False, True, False], [False, False, True]]}, ['danger', 'clear', 'clear', 'danger', 'danger', 'clear', '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']), ('sampled regression 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:
An approach-released signal clears before the train arrives on the approach.

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


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):
            stick = False
        if occ:
            if state == 'clear':
                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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 22', {'mode': 'auto', 'steps': [[True, False, True], [False, False, True], [False, True, False], [False, True, True], [False, False, False], [True, False, True], [False, True, True], [False, False, False], [True, False, False]]}, ['danger', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', '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 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('control 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 60', {'mode': 'auto', 'steps': [[False, False, False], [True, True, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', '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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('control 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']), ('sampled regression 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 47', {'mode': 'auto', 'steps': [[True, True, True], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, True, False], [False, True, True], [True, True, False], [False, False, False], [False, False, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'danger', 'clear', 'clear']), ('sampled regression 60', {'mode': 'auto', 'steps': [[False, False, False], [True, True, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 70', {'mode': 'auto', 'steps': [[False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, False, False], [False, False, True], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', '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 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' and appr):
            stick = False
        if occ:
            if state == 'clear':
                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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 22', {'mode': 'auto', 'steps': [[True, False, True], [False, False, True], [False, True, False], [False, True, True], [False, False, False], [True, False, True], [False, True, True], [False, False, False], [True, False, False]]}, ['danger', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', '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 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('control 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 60', {'mode': 'auto', 'steps': [[False, False, False], [True, True, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', '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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear']), ('boundary: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('control 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']), ('sampled regression 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 47', {'mode': 'auto', 'steps': [[True, True, True], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, True, False], [False, True, True], [True, True, False], [False, False, False], [False, False, False]]}, ['danger', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'danger', 'clear', 'clear']), ('sampled regression 60', {'mode': 'auto', 'steps': [[False, False, False], [True, True, False], [False, False, False], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 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: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 70', {'mode': 'auto', 'steps': [[False, False, True], [True, False, False], [False, False, True], [False, False, True], [True, False, False], [False, False, True], [False, False, False], [False, False, True]]}, ['clear', 'danger', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('sampled regression 11', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, False, False], [True, False, True], [False, False, False], [False, False, False], [True, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'danger', 'clear', '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 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:
An automatic signal stays at danger for good after the first train.

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


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 and state == 'clear':
            if state == 'clear':
                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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 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']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', '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 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('control 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: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('regression: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 31', {'mode': 'auto', 'steps': [[False, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, False], [False, True, False], [True, True, False], [True, False, True], [True, False, True]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'danger', 'danger']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 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']), ('sampled regression 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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 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']), ('sampled regression 54', {'mode': 'auto', 'steps': [[True, True, False], [False, True, False], [False, False, True], [False, False, True], [False, False, True], [False, True, True], [True, True, True], [False, True, False], [False, True, True], [False, True, False]]}, ['danger', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('regression: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('control 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']), ('sampled regression 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: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('regression: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 71', {'mode': 'approach', 'steps': [[False, True, False], [True, True, True], [False, True, True], [False, True, True], [True, True, True], [False, True, False]]}, ['danger', 'danger', 'clear', 'clear', 'danger', 'danger']), ('control 69', {'mode': 'auto', 'steps': [[False, False, False], [False, True, False], [False, True, False], [False, False, False], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 79', {'mode': 'auto', 'steps': [[False, True, False], [True, True, False], [True, True, False]]}, ['clear', '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 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']), ('sampled regression 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 and mode != 'auto':
            if state == 'clear':
                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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 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']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', '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 1', {'mode': 'auto', 'steps': [[False, True, False], [False, False, True], [False, True, False], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear']), ('control 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: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('regression: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 31', {'mode': 'auto', 'steps': [[False, True, False], [False, True, False], [False, True, False], [False, True, True], [False, True, False], [False, True, False], [True, True, False], [True, False, True], [True, False, True]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'danger', 'danger']), ('boundary: approach-released signal with empty approach', {'mode': 'approach', 'steps': [[False, True, False], [False, True, True]]}, ['danger', 'clear']), ('boundary: approach-released signal replaced by train', {'mode': 'approach', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('sampled regression 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']), ('sampled regression 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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 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']), ('sampled regression 54', {'mode': 'auto', 'steps': [[True, True, False], [False, True, False], [False, False, True], [False, False, True], [False, False, True], [False, True, True], [True, True, True], [False, True, False], [False, True, True], [False, True, False]]}, ['danger', 'clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('regression: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('control 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']), ('sampled regression 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: controlled signal with a standing train', {'mode': 'controlled', 'steps': [[True, True, True], [False, True, True]]}, ['danger', 'clear']), ('regression: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('sampled regression 71', {'mode': 'approach', 'steps': [[False, True, False], [True, True, True], [False, True, True], [False, True, True], [True, True, True], [False, True, False]]}, ['danger', 'danger', 'clear', 'clear', 'danger', 'danger']), ('control 69', {'mode': 'auto', 'steps': [[False, False, False], [False, True, False], [False, True, False], [False, False, False], [False, False, True], [True, False, False], [False, False, True], [False, False, True], [False, False, False]]}, ['clear', 'clear', 'clear', 'clear', 'clear', 'danger', 'clear', 'clear', 'clear']), ('boundary: second train behind on the same route', {'mode': 'controlled', 'steps': [[False, True, True], [True, True, True], [False, True, True]]}, ['clear', 'danger', 'danger']), ('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']), ('sampled regression 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: occupied before clearing', {'mode': 'auto', 'steps': [[True, False, False], [True, False, False], [False, False, False]]}, ['danger', 'danger', 'clear']), ('boundary: automatic signal re-clears', {'mode': 'auto', 'steps': [[False, False, False], [True, False, True], [False, False, False]]}, ['clear', 'danger', 'clear']), ('sampled regression 79', {'mode': 'auto', 'steps': [[False, True, False], [True, True, False], [True, True, False]]}, ['clear', '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 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']), ('sampled regression 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 clears into a section that is already occupied.

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