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

N = 1
observations = []
def solve(min_scans, latched, scans):
    in_alarm = False
    acked = True
    count = 0
    out = []
    for cond, ack, reset in scans:
        count = count + 1 if cond else 0
        if count >= min_scans and cond and not in_alarm:
            in_alarm = True
            acked = False
        elif in_alarm and (not cond and not latched or reset):
            in_alarm = False
        if ack and not acked:
            acked = True
        out.append([in_alarm, acked])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['regression: scenario 5',
   [1,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [False, True, False],
     [True, True, False],
     [True, False, False],
     [False, False, False],
     [True, True, True],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [False, True],
    [True, True],
    [True, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [1,
    False,
    [[True, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, False]]],
   [[True, False],
    [False, False],
    [True, False],
    [False, False],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False]]],
  ['control: scenario 2',
   [1,
    True,
    [[False, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, True],
     [False, False, False],
     [False, True, False],
     [True, False, False],
     [False, False, False]]],
   [[False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [False, False],
    [False, True],
    [True, False],
    [True, False]]]],
 [['regression: scenario 3',
   [2,
    False,
    [[True, False, False],
     [True, False, True],
     [False, True, True],
     [False, False, False],
     [False, False, True],
     [True, False, False],
     [True, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, True],
     [False, False, False],
     [False, False, False]]],
   [[False, True],
    [True, False],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True]]],
  ['regression: scenario 5',
   [1,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False]]],
   [[True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [True, False],
    [True, False]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [1,
    False,
    [[False, False, False],
     [False, False, True],
     [False, False, False],
     [True, True, False],
     [False, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [True, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [True, False]]]],
 [['regression: scenario 3',
   [3,
    True,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [False, True, False],
     [False, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False]]],
   [[False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]],
  ['regression: scenario 9',
   [1,
    True,
    [[False, True, True],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [False, False, False],
     [False, False, False],
     [False, True, False]]],
   [[False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [False, False, True]]],
   [[False, True],
    [False, True],
    [True, False],
    [True, False],
    [False, False],
    [False, False],
    [False, False],
    [True, False],
    [False, False],
    [False, False]]]],
 [['regression: scenario 4',
   [2,
    False,
    [[True, False, False],
     [True, True, False],
     [True, False, True],
     [False, False, True],
     [True, True, False],
     [True, False, True],
     [True, True, False],
     [False, False, False],
     [True, True, False],
     [False, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False]]],
   [[False, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False],
    [True, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False]]],
  ['regression: scenario 5',
   [2,
    True,
    [[False, False, True],
     [True, False, False],
     [False, False, True],
     [True, False, True],
     [True, False, True],
     [False, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, True],
     [False, False, False],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [2,
    True,
    [[False, True, False],
     [True, False, False],
     [False, False, False],
     [False, False, True],
     [False, False, True],
     [True, False, True],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, True, False],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]]],
 [['regression: scenario 7',
   [1,
    False,
    [[True, True, False],
     [True, False, True],
     [False, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, True, True],
     [False, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True]]],
   [[True, True],
    [True, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [True, True],
    [False, True],
    [True, False],
    [True, False],
    [False, False],
    [True, False],
    [True, False],
    [True, False]]],
  ['regression: scenario 11',
   [2,
    True,
    [[True, False, True],
     [True, True, False],
     [True, False, False],
     [False, True, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [False, True, True],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, True, False]]],
   [[False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [2,
    False,
    [[False, False, False],
     [True, True, False],
     [True, True, False],
     [False, False, True],
     [False, False, True],
     [True, True, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, True]]],
   [[False, True],
    [False, True],
    [True, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [False, False],
    [False, False],
    [True, False]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(min_scans, latched, scans):
    in_alarm = False
    acked = True
    count = 0
    out = []
    for cond, ack, reset in scans:
        count = count + 1 if cond else 0
        if count >= min_scans and cond and not in_alarm:
            in_alarm = True
            acked = False
        elif in_alarm and (not cond and not latched or reset and not ack):
            in_alarm = False
        if ack and not acked:
            acked = True
        out.append([in_alarm, acked])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['regression: scenario 5',
   [1,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [False, True, False],
     [True, True, False],
     [True, False, False],
     [False, False, False],
     [True, True, True],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [False, True],
    [True, True],
    [True, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [1,
    False,
    [[True, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, False]]],
   [[True, False],
    [False, False],
    [True, False],
    [False, False],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False]]],
  ['control: scenario 2',
   [1,
    True,
    [[False, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, True],
     [False, False, False],
     [False, True, False],
     [True, False, False],
     [False, False, False]]],
   [[False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [False, False],
    [False, True],
    [True, False],
    [True, False]]]],
 [['regression: scenario 3',
   [2,
    False,
    [[True, False, False],
     [True, False, True],
     [False, True, True],
     [False, False, False],
     [False, False, True],
     [True, False, False],
     [True, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, True],
     [False, False, False],
     [False, False, False]]],
   [[False, True],
    [True, False],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True]]],
  ['regression: scenario 5',
   [1,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False]]],
   [[True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [True, False],
    [True, False]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [1,
    False,
    [[False, False, False],
     [False, False, True],
     [False, False, False],
     [True, True, False],
     [False, False, False],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [True, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [True, False]]]],
 [['regression: scenario 3',
   [3,
    True,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [False, True, False],
     [False, False, False],
     [False, False, False],
     [True, False, False],
     [False, False, False]]],
   [[False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]],
  ['regression: scenario 9',
   [1,
    True,
    [[False, True, True],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [False, False, False],
     [False, False, False],
     [False, True, False]]],
   [[False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [False, False, True],
     [False, False, True]]],
   [[False, True],
    [False, True],
    [True, False],
    [True, False],
    [False, False],
    [False, False],
    [False, False],
    [True, False],
    [False, False],
    [False, False]]]],
 [['regression: scenario 4',
   [2,
    False,
    [[True, False, False],
     [True, True, False],
     [True, False, True],
     [False, False, True],
     [True, True, False],
     [True, False, True],
     [True, True, False],
     [False, False, False],
     [True, True, False],
     [False, False, False],
     [True, False, False],
     [True, False, True],
     [True, False, False]]],
   [[False, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False],
    [True, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False]]],
  ['regression: scenario 5',
   [2,
    True,
    [[False, False, True],
     [True, False, False],
     [False, False, True],
     [True, False, True],
     [True, False, True],
     [False, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, True],
     [True, False, False],
     [False, False, False],
     [False, False, False],
     [True, False, True],
     [False, False, False],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False],
    [True, False]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [2,
    True,
    [[False, True, False],
     [True, False, False],
     [False, False, False],
     [False, False, True],
     [False, False, True],
     [True, False, True],
     [True, True, False],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, True, False],
     [True, False, False]]],
   [[False, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True]]]],
 [['regression: scenario 7',
   [1,
    False,
    [[True, True, False],
     [True, False, True],
     [False, False, False],
     [True, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, True, True],
     [False, False, True],
     [True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True]]],
   [[True, True],
    [True, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [False, False],
    [True, True],
    [False, True],
    [True, False],
    [True, False],
    [False, False],
    [True, False],
    [True, False],
    [True, False]]],
  ['regression: scenario 11',
   [2,
    True,
    [[True, False, True],
     [True, True, False],
     [True, False, False],
     [False, True, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [False, True, True],
     [True, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, True],
     [True, True, False]]],
   [[False, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [True, True],
    [False, True],
    [False, True],
    [True, False],
    [True, False],
    [True, False],
    [True, True]]],
  ['control: latched with ack and reset',
   [2,
    True,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [False, True, False],
     [False, False, True],
     [True, False, False]]],
   [[False, True], [True, False], [True, False], [True, True], [False, True], [False, True]]],
  ['control: chattering condition',
   [3,
    False,
    [[True, False, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, False],
     [True, False, False]]],
   [[False, True], [False, True], [False, True], [False, True], [False, True], [True, False]]],
  ['control: realarm after ack',
   [1, False, [[True, False, False], [True, True, False], [False, False, False], [True, False, False]]],
   [[True, False], [True, True], [False, True], [True, False]]],
  ['regression: reset while condition true',
   [1, False, [[True, False, False], [True, False, True], [True, False, False]]],
   [[True, False], [True, False], [True, False]]],
  ['control: ack on latched alarm',
   [1, True, [[True, False, False], [False, True, False], [False, False, False], [False, False, True]]],
   [[True, False], [True, True], [True, True], [False, True]]],
  ['control: scenario 1',
   [2,
    False,
    [[False, False, False],
     [True, True, False],
     [True, True, False],
     [False, False, True],
     [False, False, True],
     [True, True, False],
     [True, False, False],
     [False, False, False],
     [True, False, False],
     [True, False, True]]],
   [[False, True],
    [False, True],
    [True, True],
    [False, True],
    [False, True],
    [False, True],
    [True, False],
    [False, False],
    [False, False],
    [True, False]]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Pressing reset during an active condition briefly clears it and then re-announces it unacknowledged.

Digital alarm instruction evaluated per scan; scans is a list of [condition, ack, reset], min_scans >= 1. The alarm activates when the condition has been true for min_scans consecutive scans; activation clears the acknowledged flag. A non-latched alarm clears when the condition goes false; a latched alarm clears only on a reset while the condition is false. ack sets acknowledged. Return [in_alarm, acknowledged] per scan.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
A transmitter at 4 mA reads a fifth of full scale instead of the bottom of range.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
Readings are compressed and full scale is never reached at 20 mA.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
Displayed values sit one tenth low about half the time.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
Signals between 3.6 and 4 mA or between 20 and 20.5 mA report values outside the calibrated range.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
A broken transmitter wire makes the process value jump to its low limit instead of holding.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
A transmitter drifting slightly under 4 mA is treated as a broken wire.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


prompt:
A transmitter calibrated slightly high trips over-range at full scale.

Scale a 4-20 mA analog channel read once per scan. Raw counts are proportional to 0-20 mA with 20 mA = 31208 counts, so 4 mA = 6242. Below 3.6 mA (raw*200 < 36*31208) the channel reports open wire and above 20.5 mA (raw*40 > 41*31208) over-range; in both cases it returns the last good value (None before any). Otherwise the engineering value in tenths is eng_lo*10 + (raw-6242)*(eng_hi-eng_lo)*10 / 24966 rounded half up, clamped to the configured range (reverse-acting ranges allowed). Return [status, tenths] per scan.

split: open-access


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

N = 1
observations = []
def solve(preset, samples):
    start = None
    done = False
    out = []
    for enable, clock in samples:
        if not enable:
            start = None
            done = False
            out.append([False, 0])
            continue
        if start is None:
            start = clock
        elapsed = clock - start
        if elapsed >= preset:
            done = True
        out.append([done, preset if done else elapsed])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: scenario 6',
   [40000,
    [[True, 63614],
     [True, 63728],
     [True, 22150],
     [True, 22324],
     [True, 22510],
     [True, 22616],
     [True, 22811],
     [True, 26381],
     [True, 40962],
     [True, 4300],
     [True, 4446],
     [True, 6819]]],
   [[False, 0],
    [False, 114],
    [False, 24072],
    [False, 24246],
    [False, 24432],
    [False, 24538],
    [False, 24733],
    [False, 28303],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['regression: scenario 1',
   [100,
    [[True, 53593],
     [True, 53635],
     [True, 10212],
     [False, 10250],
     [True, 24553],
     [True, 35364],
     [True, 35501],
     [True, 35591],
     [True, 65279],
     [True, 65379],
     [True, 65509]]],
   [[False, 0],
    [False, 42],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 2',
   [100,
    [[True, 17304],
     [True, 20531],
     [True, 27559],
     [False, 57396],
     [True, 19489],
     [True, 46000],
     [True, 46035],
     [True, 46209],
     [True, 5526]]],
   [[False, 0],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 3',
   [40000,
    [[True, 42783],
     [False, 4625],
     [True, 4670],
     [True, 8857],
     [False, 15422],
     [False, 15500],
     [True, 15560],
     [True, 27335],
     [True, 27471]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 4187],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 11775],
    [False, 11911]]]],
 [['regression: scenario 1',
   [1000,
    [[False, 39404],
     [False, 39599],
     [True, 39752],
     [True, 39914],
     [False, 49270],
     [True, 53547],
     [True, 53700],
     [True, 4426]]],
   [[False, 0], [False, 0], [False, 0], [False, 162], [False, 0], [False, 0], [False, 153], [True, 1000]]],
  ['regression: scenario 9',
   [65535,
    [[True, 50243],
     [True, 50414],
     [True, 54443],
     [True, 54585],
     [True, 54684],
     [False, 63787],
     [True, 63849],
     [True, 7734]]],
   [[False, 0],
    [False, 171],
    [False, 4200],
    [False, 4342],
    [False, 4441],
    [False, 0],
    [False, 0],
    [False, 9421]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 2',
   [5,
    [[True, 40525],
     [True, 40666],
     [True, 40725],
     [True, 58227],
     [True, 18319],
     [False, 25775],
     [True, 25797],
     [True, 25799]]],
   [[False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [False, 0], [False, 0], [False, 2]]],
  ['control: scenario 3',
   [5,
    [[False, 30258],
     [True, 30296],
     [True, 45510],
     [True, 2343],
     [True, 12538],
     [True, 12596],
     [False, 12635],
     [True, 37410],
     [True, 53676],
     [True, 10497],
     [True, 10628],
     [False, 10824],
     [True, 27527],
     [True, 55148]]],
   [[False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5]]]],
 [['regression: scenario 5',
   [5,
    [[True, 36141],
     [True, 56668],
     [False, 56831],
     [True, 56893],
     [True, 6106],
     [True, 24708],
     [True, 45326],
     [True, 65076],
     [True, 65184]]],
   [[False, 0], [True, 5], [False, 0], [False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5]]],
  ['regression: scenario 9',
   [65535,
    [[True, 44901],
     [False, 62429],
     [True, 62596],
     [True, 62792],
     [True, 21296],
     [True, 21309],
     [False, 21419],
     [False, 21455],
     [True, 21477]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 196],
    [False, 24236],
    [False, 24249],
    [False, 0],
    [False, 0],
    [False, 0]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[False, 22859],
     [True, 23009],
     [True, 46893],
     [True, 47082],
     [True, 47173],
     [True, 47274],
     [False, 47358],
     [True, 47448],
     [True, 54303],
     [True, 54477],
     [False, 54574]]],
   [[False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [False, 0]]],
  ['regression: scenario 2',
   [40000,
    [[True, 54821],
     [True, 18035],
     [True, 32212],
     [True, 38340],
     [True, 38521],
     [True, 38565],
     [True, 38691],
     [True, 52834],
     [True, 6573],
     [False, 6717],
     [True, 13602]]],
   [[False, 0],
    [False, 28750],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [False, 0],
    [False, 0]]]],
 [['regression: scenario 12',
   [1000,
    [[True, 53638],
     [True, 11442],
     [False, 11564],
     [True, 24156],
     [False, 44990],
     [True, 45016],
     [True, 539],
     [False, 562],
     [True, 677],
     [True, 8181],
     [True, 18211],
     [False, 18406],
     [True, 18528],
     [True, 18593]]],
   [[False, 0],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 65]]],
  ['regression: scenario 26',
   [40000,
    [[False, 62137],
     [True, 62189],
     [True, 62205],
     [True, 3058],
     [True, 3093],
     [True, 3203],
     [True, 3254],
     [False, 3435],
     [False, 3460],
     [True, 3482],
     [True, 3516],
     [True, 3537],
     [False, 3676],
     [True, 22059]]],
   [[False, 0],
    [False, 0],
    [False, 16],
    [False, 6405],
    [False, 6440],
    [False, 6550],
    [False, 6601],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 34],
    [False, 55],
    [False, 0],
    [False, 0]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [65535,
    [[False, 3784],
     [False, 8211],
     [False, 33966],
     [True, 50163],
     [True, 63009],
     [False, 63184],
     [True, 63243],
     [True, 63325]]],
   [[False, 0], [False, 0], [False, 0], [False, 0], [False, 12846], [False, 0], [False, 0], [False, 82]]],
  ['control: scenario 2',
   [1000,
    [[False, 46148],
     [True, 57365],
     [False, 57416],
     [True, 57439],
     [True, 57613],
     [True, 57776],
     [True, 61872],
     [True, 62038],
     [True, 9532],
     [True, 32841],
     [True, 32973]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 174],
    [False, 337],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]]],
 [['regression: scenario 13',
   [65535,
    [[True, 49642],
     [True, 49736],
     [True, 12136],
     [False, 12149],
     [False, 22343],
     [True, 34105],
     [True, 34175],
     [True, 49582],
     [False, 8498],
     [True, 10010],
     [True, 10081],
     [True, 10163],
     [True, 38620],
     [True, 62085]]],
   [[False, 0],
    [False, 94],
    [False, 28030],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 70],
    [False, 15477],
    [False, 0],
    [False, 0],
    [False, 71],
    [False, 153],
    [False, 28610],
    [False, 52075]]],
  ['regression: scenario 28',
   [40000,
    [[True, 34331],
     [False, 34410],
     [False, 34523],
     [True, 34686],
     [True, 34828],
     [True, 35005],
     [True, 43248],
     [True, 221]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 142],
    [False, 319],
    [False, 8562],
    [False, 31071]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [40000,
    [[True, 14860],
     [True, 43167],
     [True, 43310],
     [True, 43470],
     [False, 65246],
     [False, 2333],
     [True, 20092],
     [True, 45967],
     [False, 64834],
     [True, 20225],
     [False, 20250],
     [True, 21773],
     [True, 26780]]],
   [[False, 0],
    [False, 28307],
    [False, 28450],
    [False, 28610],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 25875],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 5007]]],
  ['control: scenario 2',
   [1000,
    [[True, 51184],
     [True, 56535],
     [True, 13279],
     [True, 24517],
     [True, 24685],
     [True, 32146],
     [True, 59255],
     [False, 21739],
     [True, 21822],
     [True, 43196]]],
   [[False, 0],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000]]]]]
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(preset, samples):
    start = None
    done = False
    out = []
    for enable, clock in samples:
        if not enable:
            start = None
            done = False
            out.append([False, 0])
            continue
        if start is None:
            start = clock
        elapsed = abs(clock - start)
        if elapsed >= preset:
            done = True
        out.append([done, preset if done else elapsed])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: scenario 6',
   [40000,
    [[True, 63614],
     [True, 63728],
     [True, 22150],
     [True, 22324],
     [True, 22510],
     [True, 22616],
     [True, 22811],
     [True, 26381],
     [True, 40962],
     [True, 4300],
     [True, 4446],
     [True, 6819]]],
   [[False, 0],
    [False, 114],
    [False, 24072],
    [False, 24246],
    [False, 24432],
    [False, 24538],
    [False, 24733],
    [False, 28303],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['regression: scenario 1',
   [100,
    [[True, 53593],
     [True, 53635],
     [True, 10212],
     [False, 10250],
     [True, 24553],
     [True, 35364],
     [True, 35501],
     [True, 35591],
     [True, 65279],
     [True, 65379],
     [True, 65509]]],
   [[False, 0],
    [False, 42],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 2',
   [100,
    [[True, 17304],
     [True, 20531],
     [True, 27559],
     [False, 57396],
     [True, 19489],
     [True, 46000],
     [True, 46035],
     [True, 46209],
     [True, 5526]]],
   [[False, 0],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 3',
   [40000,
    [[True, 42783],
     [False, 4625],
     [True, 4670],
     [True, 8857],
     [False, 15422],
     [False, 15500],
     [True, 15560],
     [True, 27335],
     [True, 27471]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 4187],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 11775],
    [False, 11911]]]],
 [['regression: scenario 1',
   [1000,
    [[False, 39404],
     [False, 39599],
     [True, 39752],
     [True, 39914],
     [False, 49270],
     [True, 53547],
     [True, 53700],
     [True, 4426]]],
   [[False, 0], [False, 0], [False, 0], [False, 162], [False, 0], [False, 0], [False, 153], [True, 1000]]],
  ['regression: scenario 9',
   [65535,
    [[True, 50243],
     [True, 50414],
     [True, 54443],
     [True, 54585],
     [True, 54684],
     [False, 63787],
     [True, 63849],
     [True, 7734]]],
   [[False, 0],
    [False, 171],
    [False, 4200],
    [False, 4342],
    [False, 4441],
    [False, 0],
    [False, 0],
    [False, 9421]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 2',
   [5,
    [[True, 40525],
     [True, 40666],
     [True, 40725],
     [True, 58227],
     [True, 18319],
     [False, 25775],
     [True, 25797],
     [True, 25799]]],
   [[False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [False, 0], [False, 0], [False, 2]]],
  ['control: scenario 3',
   [5,
    [[False, 30258],
     [True, 30296],
     [True, 45510],
     [True, 2343],
     [True, 12538],
     [True, 12596],
     [False, 12635],
     [True, 37410],
     [True, 53676],
     [True, 10497],
     [True, 10628],
     [False, 10824],
     [True, 27527],
     [True, 55148]]],
   [[False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5]]]],
 [['regression: scenario 5',
   [5,
    [[True, 36141],
     [True, 56668],
     [False, 56831],
     [True, 56893],
     [True, 6106],
     [True, 24708],
     [True, 45326],
     [True, 65076],
     [True, 65184]]],
   [[False, 0], [True, 5], [False, 0], [False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5]]],
  ['regression: scenario 9',
   [65535,
    [[True, 44901],
     [False, 62429],
     [True, 62596],
     [True, 62792],
     [True, 21296],
     [True, 21309],
     [False, 21419],
     [False, 21455],
     [True, 21477]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 196],
    [False, 24236],
    [False, 24249],
    [False, 0],
    [False, 0],
    [False, 0]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[False, 22859],
     [True, 23009],
     [True, 46893],
     [True, 47082],
     [True, 47173],
     [True, 47274],
     [False, 47358],
     [True, 47448],
     [True, 54303],
     [True, 54477],
     [False, 54574]]],
   [[False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [False, 0]]],
  ['regression: scenario 2',
   [40000,
    [[True, 54821],
     [True, 18035],
     [True, 32212],
     [True, 38340],
     [True, 38521],
     [True, 38565],
     [True, 38691],
     [True, 52834],
     [True, 6573],
     [False, 6717],
     [True, 13602]]],
   [[False, 0],
    [False, 28750],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [False, 0],
    [False, 0]]]],
 [['regression: scenario 12',
   [1000,
    [[True, 53638],
     [True, 11442],
     [False, 11564],
     [True, 24156],
     [False, 44990],
     [True, 45016],
     [True, 539],
     [False, 562],
     [True, 677],
     [True, 8181],
     [True, 18211],
     [False, 18406],
     [True, 18528],
     [True, 18593]]],
   [[False, 0],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 65]]],
  ['regression: scenario 26',
   [40000,
    [[False, 62137],
     [True, 62189],
     [True, 62205],
     [True, 3058],
     [True, 3093],
     [True, 3203],
     [True, 3254],
     [False, 3435],
     [False, 3460],
     [True, 3482],
     [True, 3516],
     [True, 3537],
     [False, 3676],
     [True, 22059]]],
   [[False, 0],
    [False, 0],
    [False, 16],
    [False, 6405],
    [False, 6440],
    [False, 6550],
    [False, 6601],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 34],
    [False, 55],
    [False, 0],
    [False, 0]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [65535,
    [[False, 3784],
     [False, 8211],
     [False, 33966],
     [True, 50163],
     [True, 63009],
     [False, 63184],
     [True, 63243],
     [True, 63325]]],
   [[False, 0], [False, 0], [False, 0], [False, 0], [False, 12846], [False, 0], [False, 0], [False, 82]]],
  ['control: scenario 2',
   [1000,
    [[False, 46148],
     [True, 57365],
     [False, 57416],
     [True, 57439],
     [True, 57613],
     [True, 57776],
     [True, 61872],
     [True, 62038],
     [True, 9532],
     [True, 32841],
     [True, 32973]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 174],
    [False, 337],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]]],
 [['regression: scenario 13',
   [65535,
    [[True, 49642],
     [True, 49736],
     [True, 12136],
     [False, 12149],
     [False, 22343],
     [True, 34105],
     [True, 34175],
     [True, 49582],
     [False, 8498],
     [True, 10010],
     [True, 10081],
     [True, 10163],
     [True, 38620],
     [True, 62085]]],
   [[False, 0],
    [False, 94],
    [False, 28030],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 70],
    [False, 15477],
    [False, 0],
    [False, 0],
    [False, 71],
    [False, 153],
    [False, 28610],
    [False, 52075]]],
  ['regression: scenario 28',
   [40000,
    [[True, 34331],
     [False, 34410],
     [False, 34523],
     [True, 34686],
     [True, 34828],
     [True, 35005],
     [True, 43248],
     [True, 221]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 142],
    [False, 319],
    [False, 8562],
    [False, 31071]]],
  ['regression: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [40000,
    [[True, 14860],
     [True, 43167],
     [True, 43310],
     [True, 43470],
     [False, 65246],
     [False, 2333],
     [True, 20092],
     [True, 45967],
     [False, 64834],
     [True, 20225],
     [False, 20250],
     [True, 21773],
     [True, 26780]]],
   [[False, 0],
    [False, 28307],
    [False, 28450],
    [False, 28610],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 25875],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 5007]]],
  ['control: scenario 2',
   [1000,
    [[True, 51184],
     [True, 56535],
     [True, 13279],
     [True, 24517],
     [True, 24685],
     [True, 32146],
     [True, 59255],
     [False, 21739],
     [True, 21822],
     [True, 43196]]],
   [[False, 0],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000]]]]]
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 delay that spans the 65535-to-0 rollover reports negative elapsed time and never finishes.

Delay timer built on a 16-bit free-running clock register (ticks wrap from 65535 to 0). samples is a list of [enable, clock] read each scan. The first enabled scan captures the start tick; elapsed is (clock - start) modulo 65536. Done latches once elapsed >= preset and stays set while enabled even if the elapsed value later wraps. A disabled scan clears start and done. Return [done, elapsed capped at preset once done] per scan, [False, 0] when disabled.

split: open-access


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

N = 1
observations = []
def solve(preset, samples):
    start = None
    done = False
    out = []
    for enable, clock in samples:
        if not enable:
            start = None
            done = False
            out.append([False, 0])
            continue
        if start is None:
            start = clock
        elapsed = (clock - start) & 0xFFFF
        done = elapsed >= preset
        out.append([done, preset if done else elapsed])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[True, 53593],
     [True, 53635],
     [True, 10212],
     [False, 10250],
     [True, 24553],
     [True, 35364],
     [True, 35501],
     [True, 35591],
     [True, 65279],
     [True, 65379],
     [True, 65509]]],
   [[False, 0],
    [False, 42],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 2',
   [100,
    [[True, 17304],
     [True, 20531],
     [True, 27559],
     [False, 57396],
     [True, 19489],
     [True, 46000],
     [True, 46035],
     [True, 46209],
     [True, 5526]]],
   [[False, 0],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 3',
   [40000,
    [[True, 42783],
     [False, 4625],
     [True, 4670],
     [True, 8857],
     [False, 15422],
     [False, 15500],
     [True, 15560],
     [True, 27335],
     [True, 27471]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 4187],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 11775],
    [False, 11911]]],
  ['control: scenario 4',
   [100,
    [[True, 2607],
     [True, 18576],
     [True, 18609],
     [True, 18619],
     [True, 45272],
     [True, 45282],
     [True, 55824],
     [False, 61503]]],
   [[False, 0], [True, 100], [True, 100], [True, 100], [True, 100], [True, 100], [True, 100], [False, 0]]]],
 [['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [1000,
    [[False, 39404],
     [False, 39599],
     [True, 39752],
     [True, 39914],
     [False, 49270],
     [True, 53547],
     [True, 53700],
     [True, 4426]]],
   [[False, 0], [False, 0], [False, 0], [False, 162], [False, 0], [False, 0], [False, 153], [True, 1000]]],
  ['control: scenario 2',
   [5,
    [[True, 40525],
     [True, 40666],
     [True, 40725],
     [True, 58227],
     [True, 18319],
     [False, 25775],
     [True, 25797],
     [True, 25799]]],
   [[False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [False, 0], [False, 0], [False, 2]]],
  ['control: scenario 3',
   [5,
    [[False, 30258],
     [True, 30296],
     [True, 45510],
     [True, 2343],
     [True, 12538],
     [True, 12596],
     [False, 12635],
     [True, 37410],
     [True, 53676],
     [True, 10497],
     [True, 10628],
     [False, 10824],
     [True, 27527],
     [True, 55148]]],
   [[False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5]]],
  ['control: scenario 4',
   [65535,
    [[True, 43066],
     [True, 60153],
     [False, 2292],
     [True, 2392],
     [True, 12076],
     [False, 28626],
     [False, 28693],
     [False, 45850],
     [True, 5636]]],
   [[False, 0],
    [False, 17087],
    [False, 0],
    [False, 0],
    [False, 9684],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0]]]],
 [['regression: scenario 2',
   [40000,
    [[True, 54821],
     [True, 18035],
     [True, 32212],
     [True, 38340],
     [True, 38521],
     [True, 38565],
     [True, 38691],
     [True, 52834],
     [True, 6573],
     [False, 6717],
     [True, 13602]]],
   [[False, 0],
    [False, 28750],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [False, 0],
    [False, 0]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[False, 22859],
     [True, 23009],
     [True, 46893],
     [True, 47082],
     [True, 47173],
     [True, 47274],
     [False, 47358],
     [True, 47448],
     [True, 54303],
     [True, 54477],
     [False, 54574]]],
   [[False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [False, 0]]],
  ['control: scenario 3',
   [5,
    [[False, 23870],
     [True, 46782],
     [True, 46917],
     [True, 46976],
     [True, 56255],
     [True, 61627],
     [True, 1767],
     [True, 1874]]],
   [[False, 0], [False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5]]],
  ['control: scenario 4',
   [5,
    [[True, 25219],
     [True, 25303],
     [True, 25491],
     [True, 33180],
     [True, 33370],
     [True, 34085],
     [True, 35832],
     [True, 46392],
     [True, 48652],
     [True, 48709],
     [True, 6073],
     [True, 6100]]],
   [[False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5]]]],
 [['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [65535,
    [[False, 3784],
     [False, 8211],
     [False, 33966],
     [True, 50163],
     [True, 63009],
     [False, 63184],
     [True, 63243],
     [True, 63325]]],
   [[False, 0], [False, 0], [False, 0], [False, 0], [False, 12846], [False, 0], [False, 0], [False, 82]]],
  ['control: scenario 2',
   [1000,
    [[False, 46148],
     [True, 57365],
     [False, 57416],
     [True, 57439],
     [True, 57613],
     [True, 57776],
     [True, 61872],
     [True, 62038],
     [True, 9532],
     [True, 32841],
     [True, 32973]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 174],
    [False, 337],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]],
  ['control: scenario 3',
   [65535,
    [[False, 15447],
     [True, 18837],
     [False, 18898],
     [True, 19006],
     [False, 33164],
     [True, 33164],
     [True, 41175],
     [True, 53503],
     [True, 53600],
     [True, 6331],
     [True, 35575],
     [True, 35594],
     [True, 35643]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 8011],
    [False, 20339],
    [False, 20436],
    [False, 38703],
    [False, 2411],
    [False, 2430],
    [False, 2479]]],
  ['control: scenario 4',
   [40000,
    [[False, 63428],
     [False, 10454],
     [True, 36085],
     [False, 36231],
     [True, 36344],
     [True, 36357],
     [True, 36437],
     [True, 36476],
     [True, 59214],
     [False, 59324],
     [True, 23687],
     [True, 45223],
     [False, 61971]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 13],
    [False, 93],
    [False, 132],
    [False, 22870],
    [False, 0],
    [False, 0],
    [False, 21536],
    [False, 0]]]],
 [['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [40000,
    [[True, 14860],
     [True, 43167],
     [True, 43310],
     [True, 43470],
     [False, 65246],
     [False, 2333],
     [True, 20092],
     [True, 45967],
     [False, 64834],
     [True, 20225],
     [False, 20250],
     [True, 21773],
     [True, 26780]]],
   [[False, 0],
    [False, 28307],
    [False, 28450],
    [False, 28610],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 25875],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 5007]]],
  ['control: scenario 2',
   [1000,
    [[True, 51184],
     [True, 56535],
     [True, 13279],
     [True, 24517],
     [True, 24685],
     [True, 32146],
     [True, 59255],
     [False, 21739],
     [True, 21822],
     [True, 43196]]],
   [[False, 0],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000]]],
  ['control: scenario 3',
   [1000,
    [[True, 22897],
     [True, 22914],
     [True, 28312],
     [True, 28374],
     [True, 35057],
     [True, 50246],
     [True, 63704],
     [True, 65227],
     [True, 26677],
     [True, 39163]]],
   [[False, 0],
    [False, 17],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]],
  ['control: scenario 4',
   [1000,
    [[True, 38985],
     [True, 39119],
     [True, 46977],
     [True, 47168],
     [False, 6446],
     [True, 33057],
     [True, 33083],
     [True, 33130],
     [True, 49169],
     [True, 49195],
     [True, 49212],
     [True, 12968],
     [True, 13081]]],
   [[False, 0],
    [False, 134],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 26],
    [False, 73],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]]]]
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(preset, samples):
    start = None
    done = False
    out = []
    for enable, clock in samples:
        if not enable:
            start = None
            done = False
            out.append([False, 0])
            continue
        if start is None:
            start = clock
        elapsed = (clock - start) & 0xFFFF
        done = elapsed >= preset or (done and elapsed > 0)
        out.append([done, preset if done else elapsed])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[True, 53593],
     [True, 53635],
     [True, 10212],
     [False, 10250],
     [True, 24553],
     [True, 35364],
     [True, 35501],
     [True, 35591],
     [True, 65279],
     [True, 65379],
     [True, 65509]]],
   [[False, 0],
    [False, 42],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 2',
   [100,
    [[True, 17304],
     [True, 20531],
     [True, 27559],
     [False, 57396],
     [True, 19489],
     [True, 46000],
     [True, 46035],
     [True, 46209],
     [True, 5526]]],
   [[False, 0],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100]]],
  ['control: scenario 3',
   [40000,
    [[True, 42783],
     [False, 4625],
     [True, 4670],
     [True, 8857],
     [False, 15422],
     [False, 15500],
     [True, 15560],
     [True, 27335],
     [True, 27471]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 4187],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 11775],
    [False, 11911]]],
  ['control: scenario 4',
   [100,
    [[True, 2607],
     [True, 18576],
     [True, 18609],
     [True, 18619],
     [True, 45272],
     [True, 45282],
     [True, 55824],
     [False, 61503]]],
   [[False, 0], [True, 100], [True, 100], [True, 100], [True, 100], [True, 100], [True, 100], [False, 0]]]],
 [['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [1000,
    [[False, 39404],
     [False, 39599],
     [True, 39752],
     [True, 39914],
     [False, 49270],
     [True, 53547],
     [True, 53700],
     [True, 4426]]],
   [[False, 0], [False, 0], [False, 0], [False, 162], [False, 0], [False, 0], [False, 153], [True, 1000]]],
  ['control: scenario 2',
   [5,
    [[True, 40525],
     [True, 40666],
     [True, 40725],
     [True, 58227],
     [True, 18319],
     [False, 25775],
     [True, 25797],
     [True, 25799]]],
   [[False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [False, 0], [False, 0], [False, 2]]],
  ['control: scenario 3',
   [5,
    [[False, 30258],
     [True, 30296],
     [True, 45510],
     [True, 2343],
     [True, 12538],
     [True, 12596],
     [False, 12635],
     [True, 37410],
     [True, 53676],
     [True, 10497],
     [True, 10628],
     [False, 10824],
     [True, 27527],
     [True, 55148]]],
   [[False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [False, 0],
    [False, 0],
    [True, 5]]],
  ['control: scenario 4',
   [65535,
    [[True, 43066],
     [True, 60153],
     [False, 2292],
     [True, 2392],
     [True, 12076],
     [False, 28626],
     [False, 28693],
     [False, 45850],
     [True, 5636]]],
   [[False, 0],
    [False, 17087],
    [False, 0],
    [False, 0],
    [False, 9684],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0]]]],
 [['regression: scenario 2',
   [40000,
    [[True, 54821],
     [True, 18035],
     [True, 32212],
     [True, 38340],
     [True, 38521],
     [True, 38565],
     [True, 38691],
     [True, 52834],
     [True, 6573],
     [False, 6717],
     [True, 13602]]],
   [[False, 0],
    [False, 28750],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [True, 40000],
    [False, 0],
    [False, 0]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [100,
    [[False, 22859],
     [True, 23009],
     [True, 46893],
     [True, 47082],
     [True, 47173],
     [True, 47274],
     [False, 47358],
     [True, 47448],
     [True, 54303],
     [True, 54477],
     [False, 54574]]],
   [[False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [True, 100],
    [True, 100],
    [False, 0],
    [False, 0],
    [True, 100],
    [True, 100],
    [False, 0]]],
  ['control: scenario 3',
   [5,
    [[False, 23870],
     [True, 46782],
     [True, 46917],
     [True, 46976],
     [True, 56255],
     [True, 61627],
     [True, 1767],
     [True, 1874]]],
   [[False, 0], [False, 0], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5], [True, 5]]],
  ['control: scenario 4',
   [5,
    [[True, 25219],
     [True, 25303],
     [True, 25491],
     [True, 33180],
     [True, 33370],
     [True, 34085],
     [True, 35832],
     [True, 46392],
     [True, 48652],
     [True, 48709],
     [True, 6073],
     [True, 6100]]],
   [[False, 0],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5],
    [True, 5]]]],
 [['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [65535,
    [[False, 3784],
     [False, 8211],
     [False, 33966],
     [True, 50163],
     [True, 63009],
     [False, 63184],
     [True, 63243],
     [True, 63325]]],
   [[False, 0], [False, 0], [False, 0], [False, 0], [False, 12846], [False, 0], [False, 0], [False, 82]]],
  ['control: scenario 2',
   [1000,
    [[False, 46148],
     [True, 57365],
     [False, 57416],
     [True, 57439],
     [True, 57613],
     [True, 57776],
     [True, 61872],
     [True, 62038],
     [True, 9532],
     [True, 32841],
     [True, 32973]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 174],
    [False, 337],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]],
  ['control: scenario 3',
   [65535,
    [[False, 15447],
     [True, 18837],
     [False, 18898],
     [True, 19006],
     [False, 33164],
     [True, 33164],
     [True, 41175],
     [True, 53503],
     [True, 53600],
     [True, 6331],
     [True, 35575],
     [True, 35594],
     [True, 35643]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 8011],
    [False, 20339],
    [False, 20436],
    [False, 38703],
    [False, 2411],
    [False, 2430],
    [False, 2479]]],
  ['control: scenario 4',
   [40000,
    [[False, 63428],
     [False, 10454],
     [True, 36085],
     [False, 36231],
     [True, 36344],
     [True, 36357],
     [True, 36437],
     [True, 36476],
     [True, 59214],
     [False, 59324],
     [True, 23687],
     [True, 45223],
     [False, 61971]]],
   [[False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 13],
    [False, 93],
    [False, 132],
    [False, 22870],
    [False, 0],
    [False, 0],
    [False, 21536],
    [False, 0]]]],
 [['regression: long enable past a full wrap',
   [1000, [[True, 100], [True, 30100], [True, 60100], [True, 24564], [True, 700]]],
   [[False, 0], [True, 1000], [True, 1000], [True, 1000], [True, 1000]]],
  ['regression: elapsed returns to zero',
   [5, [[True, 10], [True, 20], [True, 10], [True, 12]]],
   [[False, 0], [True, 5], [True, 5], [True, 5]]],
  ['control: clock wrap',
   [100, [[True, 65500], [True, 65530], [True, 40], [True, 64], [False, 70]]],
   [[False, 0], [False, 30], [False, 76], [True, 100], [False, 0]]],
  ['control: enable after idle',
   [50, [[False, 0], [False, 400], [True, 900], [True, 930], [True, 960]]],
   [[False, 0], [False, 0], [False, 0], [False, 30], [True, 50]]],
  ['control: scenario 1',
   [40000,
    [[True, 14860],
     [True, 43167],
     [True, 43310],
     [True, 43470],
     [False, 65246],
     [False, 2333],
     [True, 20092],
     [True, 45967],
     [False, 64834],
     [True, 20225],
     [False, 20250],
     [True, 21773],
     [True, 26780]]],
   [[False, 0],
    [False, 28307],
    [False, 28450],
    [False, 28610],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 25875],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 0],
    [False, 5007]]],
  ['control: scenario 2',
   [1000,
    [[True, 51184],
     [True, 56535],
     [True, 13279],
     [True, 24517],
     [True, 24685],
     [True, 32146],
     [True, 59255],
     [False, 21739],
     [True, 21822],
     [True, 43196]]],
   [[False, 0],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [True, 1000]]],
  ['control: scenario 3',
   [1000,
    [[True, 22897],
     [True, 22914],
     [True, 28312],
     [True, 28374],
     [True, 35057],
     [True, 50246],
     [True, 63704],
     [True, 65227],
     [True, 26677],
     [True, 39163]]],
   [[False, 0],
    [False, 17],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]],
  ['control: scenario 4',
   [1000,
    [[True, 38985],
     [True, 39119],
     [True, 46977],
     [True, 47168],
     [False, 6446],
     [True, 33057],
     [True, 33083],
     [True, 33130],
     [True, 49169],
     [True, 49195],
     [True, 49212],
     [True, 12968],
     [True, 13081]]],
   [[False, 0],
    [False, 134],
    [True, 1000],
    [True, 1000],
    [False, 0],
    [False, 0],
    [False, 26],
    [False, 73],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000],
    [True, 1000]]]]]
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 timer that finished long ago drops its done bit when the clock has gone all the way round.

Delay timer built on a 16-bit free-running clock register (ticks wrap from 65535 to 0). samples is a list of [enable, clock] read each scan. The first enabled scan captures the start tick; elapsed is (clock - start) modulo 65536. Done latches once elapsed >= preset and stays set while enabled even if the elapsed value later wraps. A disabled scan clears start and done. Return [done, elapsed capped at preset once done] per scan, [False, 0] when disabled.

split: open-access