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

N = 1
observations = []
def solve(alarms, scans):
    level = dict(alarms)
    prev = set()
    unacked = set()
    silenced = False
    out = []
    for s in scans:
        active = set(s.get('active', []))
        new = active - prev if prev else set()
        if new:
            silenced = False
        unacked = (unacked | new) & active
        if s.get('ack'):
            unacked = set()
        if s.get('silence'):
            silenced = True
        if any(level[a] == 'high' for a in active):
            shown = 'high'
        elif active:
            shown = 'low'
        else:
            shown = None
        color = {'high': 'red', 'low': 'amber', None: 'off'}[shown]
        flashing = any(level[a] == shown for a in unacked)
        horn = bool(unacked) and not silenced
        prev = active
        out.append([color, flashing, horn])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['ZS400'], 'ack': True, 'silence': True},
     {'active': []},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'ZS400'], 'ack': True}]],
   [['amber', False, False],
    ['amber', False, False],
    ['red', False, False],
    ['off', False, False],
    ['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'silence': True},
     {'active': ['ZS400']},
     {'active': ['LT200', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['amber', True, False],
    ['red', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'ack': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'ack': True}]],
   [['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False]]]],
 [['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400'], 'silence': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200']}]],
   [['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'ack': True},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['ZS400']},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'ZS400'], 'ack': True},
     {'active': ['PT101', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False]]]],
 [['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 5',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300', 'ZS400'], 'ack': True},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': [], 'ack': True}]],
   [['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['off', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200', 'PT101']},
     {'active': []},
     {'active': []},
     {'active': []},
     {'active': [], 'ack': True},
     {'active': ['LT200']},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['amber', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': []},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400']}]],
   [['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'silence': True}]],
   [['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True],
    ['red', False, False],
    ['amber', False, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['ZS400']},
     {'active': ['TT300', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', True, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: scenario 4',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300', 'ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['PT101', 'ZS400'], 'ack': True},
     {'active': ['LT200', 'PT101', 'ZS400'], 'ack': True, 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200']},
     {'active': ['LT200'], 'ack': True},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['amber', True, True],
    ['amber', False, False],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]]]]
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(alarms, scans):
    level = dict(alarms)
    prev = set()
    unacked = set()
    silenced = False
    out = []
    for s in scans:
        active = set(s.get('active', []))
        new = active - (prev & unacked)
        if new:
            silenced = False
        unacked = (unacked | new) & active
        if s.get('ack'):
            unacked = set()
        if s.get('silence'):
            silenced = True
        if any(level[a] == 'high' for a in active):
            shown = 'high'
        elif active:
            shown = 'low'
        else:
            shown = None
        color = {'high': 'red', 'low': 'amber', None: 'off'}[shown]
        flashing = any(level[a] == shown for a in unacked)
        horn = bool(unacked) and not silenced
        prev = active
        out.append([color, flashing, horn])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['ZS400'], 'ack': True, 'silence': True},
     {'active': []},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'ZS400'], 'ack': True}]],
   [['amber', False, False],
    ['amber', False, False],
    ['red', False, False],
    ['off', False, False],
    ['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'silence': True},
     {'active': ['ZS400']},
     {'active': ['LT200', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['amber', True, False],
    ['red', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'ack': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'ack': True}]],
   [['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False]]]],
 [['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400'], 'silence': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200']}]],
   [['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'ack': True},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['ZS400']},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'ZS400'], 'ack': True},
     {'active': ['PT101', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False]]]],
 [['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 5',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300', 'ZS400'], 'ack': True},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': [], 'ack': True}]],
   [['red', True, True],
    ['red', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['off', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200', 'PT101']},
     {'active': []},
     {'active': []},
     {'active': []},
     {'active': [], 'ack': True},
     {'active': ['LT200']},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['amber', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': []},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400']}]],
   [['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'silence': True}]],
   [['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True],
    ['red', False, False],
    ['amber', False, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['ZS400']},
     {'active': ['TT300', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', True, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: scenario 4',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['TT300', 'ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['PT101', 'ZS400'], 'ack': True},
     {'active': ['LT200', 'PT101', 'ZS400'], 'ack': True, 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']}]],
   [['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200']},
     {'active': ['LT200'], 'ack': True},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['amber', True, True],
    ['amber', False, False],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]]]]
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 alarm present when the panel starts never flashes or sounds the horn.

Stack light and horn logic. alarms is a list of [name, high|low]; each scan gives the active alarm names plus optional ack and silence buttons. An alarm becomes unacknowledged on its inactive-to-active transition and stops being unacknowledged when it clears or ack is pressed. Any new activation cancels silence; silence (pressed after that) mutes the horn. The lamp is red if any high alarm is active, else amber if any alarm is active, else off; it flashes if an unacknowledged alarm of the displayed level exists. The horn sounds while any unacknowledged alarm exists and not silenced. Return [color, flashing, horn] per scan.

split: open-access


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

N = 1
observations = []
def solve(alarms, scans):
    level = dict(alarms)
    prev = set()
    unacked = set()
    silenced = False
    out = []
    for s in scans:
        active = set(s.get('active', []))
        new = active - prev
        if new:
            silenced = False
        unacked = unacked | new
        if s.get('ack'):
            unacked = set()
        if s.get('silence'):
            silenced = True
        if any(level[a] == 'high' for a in active):
            shown = 'high'
        elif active:
            shown = 'low'
        else:
            shown = None
        color = {'high': 'red', 'low': 'amber', None: 'off'}[shown]
        flashing = any(level[a] == shown for a in unacked)
        horn = bool(unacked) and not silenced
        prev = active
        out.append([color, flashing, horn])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['ZS400'], 'ack': True, 'silence': True},
     {'active': []},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'ZS400'], 'ack': True}]],
   [['amber', False, False],
    ['amber', False, False],
    ['red', False, False],
    ['off', False, False],
    ['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'silence': True},
     {'active': ['ZS400']},
     {'active': ['LT200', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['amber', True, False],
    ['red', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'ack': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'ack': True}]],
   [['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False]]]],
 [['regression: scenario 8',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400']},
     {'active': ['TT300', 'ZS400'], 'ack': True, 'silence': True},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['red', True, True],
    ['red', False, False],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400'], 'silence': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200']}]],
   [['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False]]]],
 [['regression: scenario 11',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['PT101']},
     {'active': []},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200']}]],
   [['red', True, True],
    ['red', True, True],
    ['off', False, False],
    ['amber', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', True, False],
    ['amber', True, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200', 'PT101']},
     {'active': []},
     {'active': []},
     {'active': []},
     {'active': [], 'ack': True},
     {'active': ['LT200']},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['amber', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': []},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400']}]],
   [['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: scenario 12',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300'], 'silence': True},
     {'active': ['LT200', 'TT300']},
     {'active': ['TT300'], 'silence': True},
     {'active': ['TT300', 'ZS400'], 'ack': True, 'silence': True}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, False],
    ['amber', True, False],
    ['amber', False, False],
    ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True],
    ['red', False, False],
    ['amber', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'silence': True}]],
   [['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False]]]],
 [['regression: scenario 21',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': ['LT200'], 'ack': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'silence': True}]],
   [['off', False, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200']},
     {'active': ['LT200'], 'ack': True},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['amber', True, True],
    ['amber', False, False],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]]]]
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(alarms, scans):
    level = dict(alarms)
    prev = set()
    unacked = set()
    silenced = False
    out = []
    for s in scans:
        active = set(s.get('active', []))
        new = active - prev
        if new:
            silenced = False
        unacked = (unacked | new) & prev
        if s.get('ack'):
            unacked = set()
        if s.get('silence'):
            silenced = True
        if any(level[a] == 'high' for a in active):
            shown = 'high'
        elif active:
            shown = 'low'
        else:
            shown = None
        color = {'high': 'red', 'low': 'amber', None: 'off'}[shown]
        flashing = any(level[a] == shown for a in unacked)
        horn = bool(unacked) and not silenced
        prev = active
        out.append([color, flashing, horn])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['ZS400'], 'ack': True, 'silence': True},
     {'active': []},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'ZS400'], 'ack': True}]],
   [['amber', False, False],
    ['amber', False, False],
    ['red', False, False],
    ['off', False, False],
    ['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['TT300'], 'silence': True},
     {'active': ['ZS400']},
     {'active': ['LT200', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['amber', True, False],
    ['red', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False]]],
  ['regression: scenario 3',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'ack': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'ack': True}]],
   [['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', False, False]]]],
 [['regression: scenario 8',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400']},
     {'active': ['TT300', 'ZS400'], 'ack': True, 'silence': True},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True}]],
   [['red', True, True],
    ['red', False, False],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False],
    ['red', True, True],
    ['red', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['ZS400'], 'silence': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200']}]],
   [['red', True, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101']},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300', 'ZS400']},
     {'active': ['LT200', 'PT101', 'TT300', 'ZS400']},
     {'active': ['LT200', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['amber', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False]]]],
 [['regression: scenario 11',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['PT101']},
     {'active': []},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200']}]],
   [['red', True, True],
    ['red', True, True],
    ['off', False, False],
    ['amber', True, True],
    ['red', True, False],
    ['red', True, False],
    ['red', True, False],
    ['amber', True, False]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101']},
     {'active': ['LT200', 'PT101'], 'silence': True},
     {'active': ['LT200', 'PT101']},
     {'active': []},
     {'active': []},
     {'active': []},
     {'active': [], 'ack': True},
     {'active': ['LT200']},
     {'active': ['LT200', 'TT300']}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['amber', True, True],
    ['amber', True, True]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'silence': True},
     {'active': ['ZS400']},
     {'active': []},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'PT101', 'ZS400']},
     {'active': ['PT101', 'TT300', 'ZS400']}]],
   [['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, False],
    ['red', True, False],
    ['off', False, False],
    ['red', True, True],
    ['red', True, True],
    ['red', True, True]]]],
 [['regression: scenario 12',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['TT300'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300'], 'silence': True},
     {'active': ['LT200', 'TT300']},
     {'active': ['TT300'], 'silence': True},
     {'active': ['TT300', 'ZS400'], 'ack': True, 'silence': True}]],
   [['red', True, True],
    ['red', True, True],
    ['red', True, True],
    ['amber', False, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, False],
    ['amber', True, False],
    ['amber', False, False],
    ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']},
     {'active': ['LT200', 'PT101', 'TT300'], 'ack': True},
     {'active': ['LT200', 'TT300']}]],
   [['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True],
    ['red', False, False],
    ['amber', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': []},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'ZS400'], 'silence': True},
     {'active': ['PT101']},
     {'active': ['PT101'], 'silence': True}]],
   [['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['red', True, False],
    ['red', False, False],
    ['red', False, False]]]],
 [['regression: scenario 21',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': ['LT200'], 'ack': True},
     {'active': ['LT200', 'ZS400']},
     {'active': ['LT200', 'ZS400']},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300'], 'silence': True}]],
   [['off', False, False],
    ['amber', False, False],
    ['red', True, True],
    ['red', True, True],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: silence then new low alarm',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A']}, {'active': ['A'], 'silence': True}, {'active': ['A', 'B']}]],
   [['red', True, True], ['red', True, False], ['red', True, True]]],
  ['regression: escalation sequence',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['B']},
     {'active': ['B'], 'silence': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'ack': True},
     {'active': ['B']},
     {}]],
   [['amber', True, True],
    ['amber', True, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', False, False],
    ['off', False, False]]],
  ['regression: alarm clears unacknowledged',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {}, {'active': ['B']}]],
   [['red', True, True], ['off', False, False], ['amber', True, True]]],
  ['regression: low alarm while high acked',
   [[['A', 'high'], ['B', 'low']],
    [{'active': ['A'], 'ack': True},
     {'active': ['A', 'B']},
     {'active': ['A', 'B'], 'silence': True},
     {'active': ['A', 'B']}]],
   [['red', False, False], ['red', False, True], ['red', False, False], ['red', False, False]]],
  ['regression: alarm present at first scan',
   [[['A', 'high'], ['B', 'low']], [{'active': ['A']}, {'active': ['A']}]],
   [['red', True, True], ['red', True, True]]],
  ['regression: scenario 1',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': [], 'silence': True},
     {'active': []},
     {'active': ['ZS400']},
     {'active': ['ZS400'], 'ack': True},
     {'active': ['TT300']},
     {'active': ['PT101', 'TT300'], 'ack': True},
     {'active': ['PT101', 'TT300']},
     {'active': ['PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300'], 'silence': True},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['off', False, False],
    ['red', True, True],
    ['red', False, False],
    ['amber', True, True],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False]]],
  ['regression: scenario 2',
   [[['PT101', 'high'], ['LT200', 'low'], ['TT300', 'low'], ['ZS400', 'high']],
    [{'active': ['LT200']},
     {'active': ['LT200'], 'ack': True},
     {'active': []},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101'], 'ack': True},
     {'active': ['PT101']},
     {'active': ['LT200', 'PT101', 'TT300']}]],
   [['amber', True, True],
    ['amber', False, False],
    ['off', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, False],
    ['red', False, True]]]]]
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 horn keeps sounding after every alarm has returned to normal.

Stack light and horn logic. alarms is a list of [name, high|low]; each scan gives the active alarm names plus optional ack and silence buttons. An alarm becomes unacknowledged on its inactive-to-active transition and stops being unacknowledged when it clears or ack is pressed. Any new activation cancels silence; silence (pressed after that) mutes the horn. The lamp is red if any high alarm is active, else amber if any alarm is active, else off; it flashes if an unacknowledged alarm of the displayed level exists. The horn sounds while any unacknowledged alarm exists and not silenced. Return [color, flashing, horn] per scan.

split: open-access