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

N = 1
observations = []
def solve(rungs, scans):
    bits = {}
    first = True
    out = []
    for scan in scans:
        if scan.get('power_cycle'):
            for instr, bit, cond in rungs:
                if instr == 'OTE':
                    bits[bit] = False
            first = True
            out.append(sorted(b for b, v in bits.items() if v))
            continue
        for instr, bit, cond in reversed(rungs):
            rung = first if cond == 'S:FS' else bool(scan.get(cond, False))
            if instr == 'OTE':
                bits[bit] = rung
            elif rung and instr == 'OTL':
                bits[bit] = True
            elif rung and instr == 'OTU':
                bits[bit] = False
        first = False
        out.append(sorted(b for b, v in bits.items() if v))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: scenario 6',
   [[['OTU', 'B:2', 'I:0'],
     ['OTU', 'B:0', 'I:1'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTL', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:2']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[], ['B:2'], ['B:2'], ['B:2'], ['B:0', 'B:2'], ['B:0', 'B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTE', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:0'], [], ['B:2', 'B:3'], ['B:3'], ['B:3'], ['B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:2', 'I:1'], ['OTL', 'B:1', 'I:1'], ['OTL', 'B:1', 'I:2'], ['OTL', 'B:0', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True}]],
   [['B:0'],
    ['B:0'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: scenario 3',
   [[['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 4',
   [[['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:0', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:1'],
    ['B:1'],
    ['B:1'],
    ['B:1']]],
  ['regression: scenario 5',
   [[['OTE', 'B:2', 'I:2'],
     ['OTE', 'B:0', 'I:0'],
     ['OTE', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:2'], [], [], ['B:0', 'B:2'], [], []]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTE', 'B:3', 'S:FS'], ['OTL', 'B:0', 'S:FS'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [['B:0', 'B:3'], [], [], [], [], []]],
  ['control: scenario 2',
   [[['OTL', 'B:2', 'I:1'], ['OTL', 'B:3', 'I:2'], ['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:0', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:3', 'I:0']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[], [], [], [], ['B:0', 'B:3'], ['B:0']]],
  ['regression: scenario 7',
   [[['OTU', 'B:3', 'I:2'],
     ['OTU', 'B:0', 'I:1'],
     ['OTL', 'B:0', 'I:2'],
     ['OTU', 'B:2', 'I:0'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True}]],
   [['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'I:2'], ['OTE', 'B:1', 'I:0'], ['OTL', 'B:1', 'I:0']],
    [{'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], [], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['regression: scenario 2',
   [[['OTL', 'B:0', 'I:2'], ['OTL', 'B:2', 'S:FS'], ['OTU', 'B:0', 'I:2'], ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:2'], ['B:2'], ['B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:3', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTE', 'B:1', 'S:FS'],
     ['OTU', 'B:2', 'S:FS'],
     ['OTL', 'B:2', 'I:1'],
     ['OTU', 'B:1', 'S:FS']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:2'], [], []]],
  ['regression: scenario 15',
   [[['OTU', 'B:2', 'I:1'], ['OTU', 'B:3', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [[], ['B:1'], [], ['B:3'], [], ['B:3'], [], []]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:1'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTE', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:3'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:3'], ['B:0', 'B:3']]],
  ['regression: scenario 2',
   [[['OTE', 'B:1', 'I:1'],
     ['OTU', 'B:3', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1', 'B:3'], ['B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3']]]],
 [['regression: scenario 9',
   [[['OTU', 'B:0', 'I:1'],
     ['OTE', 'B:3', 'S:FS'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:0', 'B:3'], ['B:0'], ['B:0'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:2'], ['B:0', 'B:2']]],
  ['regression: scenario 36',
   [[['OTL', 'B:1', 'S:FS'], ['OTU', 'B:2', 'I:1'], ['OTL', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:1']],
    [{'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:0', 'I:2'], ['OTE', 'B:2', 'I:0'], ['OTL', 'B:1', 'I:2']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:1', 'B:2'], ['B:1', 'B:2'], ['B:1'], ['B:1']]]]]
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(rungs, scans):
    bits = {}
    first = True
    out = []
    for scan in scans:
        if scan.get('power_cycle'):
            for instr, bit, cond in rungs:
                if instr == 'OTE':
                    bits[bit] = False
            first = True
            out.append(sorted(b for b, v in bits.items() if v))
            continue
        for instr, bit, cond in sorted(rungs, key=lambda r: r[0] == 'OTU'):
            rung = first if cond == 'S:FS' else bool(scan.get(cond, False))
            if instr == 'OTE':
                bits[bit] = rung
            elif rung and instr == 'OTL':
                bits[bit] = True
            elif rung and instr == 'OTU':
                bits[bit] = False
        first = False
        out.append(sorted(b for b, v in bits.items() if v))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: scenario 6',
   [[['OTU', 'B:2', 'I:0'],
     ['OTU', 'B:0', 'I:1'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTL', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:2']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[], ['B:2'], ['B:2'], ['B:2'], ['B:0', 'B:2'], ['B:0', 'B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTE', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:0'], [], ['B:2', 'B:3'], ['B:3'], ['B:3'], ['B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:2', 'I:1'], ['OTL', 'B:1', 'I:1'], ['OTL', 'B:1', 'I:2'], ['OTL', 'B:0', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True}]],
   [['B:0'],
    ['B:0'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: scenario 3',
   [[['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 4',
   [[['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:0', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:1'],
    ['B:1'],
    ['B:1'],
    ['B:1']]],
  ['regression: scenario 5',
   [[['OTE', 'B:2', 'I:2'],
     ['OTE', 'B:0', 'I:0'],
     ['OTE', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:2'], [], [], ['B:0', 'B:2'], [], []]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTE', 'B:3', 'S:FS'], ['OTL', 'B:0', 'S:FS'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [['B:0', 'B:3'], [], [], [], [], []]],
  ['control: scenario 2',
   [[['OTL', 'B:2', 'I:1'], ['OTL', 'B:3', 'I:2'], ['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:0', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:3', 'I:0']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[], [], [], [], ['B:0', 'B:3'], ['B:0']]],
  ['regression: scenario 7',
   [[['OTU', 'B:3', 'I:2'],
     ['OTU', 'B:0', 'I:1'],
     ['OTL', 'B:0', 'I:2'],
     ['OTU', 'B:2', 'I:0'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True}]],
   [['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'I:2'], ['OTE', 'B:1', 'I:0'], ['OTL', 'B:1', 'I:0']],
    [{'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], [], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['regression: scenario 2',
   [[['OTL', 'B:0', 'I:2'], ['OTL', 'B:2', 'S:FS'], ['OTU', 'B:0', 'I:2'], ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:2'], ['B:2'], ['B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:3', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTE', 'B:1', 'S:FS'],
     ['OTU', 'B:2', 'S:FS'],
     ['OTL', 'B:2', 'I:1'],
     ['OTU', 'B:1', 'S:FS']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:2'], [], []]],
  ['regression: scenario 15',
   [[['OTU', 'B:2', 'I:1'], ['OTU', 'B:3', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [[], ['B:1'], [], ['B:3'], [], ['B:3'], [], []]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:1'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTE', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:3'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:3'], ['B:0', 'B:3']]],
  ['regression: scenario 2',
   [[['OTE', 'B:1', 'I:1'],
     ['OTU', 'B:3', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1', 'B:3'], ['B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3']]]],
 [['regression: scenario 9',
   [[['OTU', 'B:0', 'I:1'],
     ['OTE', 'B:3', 'S:FS'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:0', 'B:3'], ['B:0'], ['B:0'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:2'], ['B:0', 'B:2']]],
  ['regression: scenario 36',
   [[['OTL', 'B:1', 'S:FS'], ['OTU', 'B:2', 'I:1'], ['OTL', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['regression: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:1']],
    [{'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:0', 'I:2'], ['OTE', 'B:2', 'I:0'], ['OTL', 'B:1', 'I:2']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:1', 'B:2'], ['B:1', 'B:2'], ['B:1'], ['B:1']]]]]
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:
When latch and unlatch conditions are true together the opposite rung wins from what the program order dictates.

Latch (OTL), unlatch (OTU) and non-retentive output (OTE) rungs executed in program order each scan. rungs is a list of [instr, bit, condition_tag]; the rung is true when the condition input is true, or, for condition S:FS, on the first scan after power-up. A scan item {"power_cycle": true} models a power cycle: prescan clears only OTE destination bits, OTL/OTU bits are retentive, and the next scan is a first scan; it also reports the post-prescan state. OTL sets and OTU clears its bit only when its rung is true; the later rung wins. Return the sorted true bits after each item.

split: open-access


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

N = 1
observations = []
def solve(rungs, scans):
    bits = {}
    first = True
    out = []
    for scan in scans:
        if scan.get('power_cycle'):
            for instr, bit, cond in rungs:
                pass
            first = True
            out.append(sorted(b for b, v in bits.items() if v))
            continue
        for instr, bit, cond in rungs:
            rung = first if cond == 'S:FS' else bool(scan.get(cond, False))
            if instr == 'OTE':
                bits[bit] = rung
            elif rung and instr == 'OTL':
                bits[bit] = True
            elif rung and instr == 'OTU':
                bits[bit] = False
        first = False
        out.append(sorted(b for b, v in bits.items() if v))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['regression: scenario 19',
   [[['OTL', 'B:3', 'I:1'], ['OTU', 'B:3', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:2'], [], ['B:2'], [], [], [], ['B:2', 'B:3'], [], [], ['B:2', 'B:3']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTE', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:0'], [], ['B:2', 'B:3'], ['B:3'], ['B:3'], ['B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:2', 'I:1'], ['OTL', 'B:1', 'I:1'], ['OTL', 'B:1', 'I:2'], ['OTL', 'B:0', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True}]],
   [['B:0'],
    ['B:0'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: scenario 3',
   [[['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 5',
   [[['OTE', 'B:2', 'I:2'],
     ['OTE', 'B:0', 'I:0'],
     ['OTE', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:2'], [], [], ['B:0', 'B:2'], [], []]],
  ['regression: scenario 7',
   [[['OTU', 'B:2', 'I:0'], ['OTL', 'B:3', 'S:FS'], ['OTE', 'B:1', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:3'],
    ['B:3'],
    ['B:3'],
    ['B:3'],
    ['B:1', 'B:3'],
    ['B:3'],
    ['B:3'],
    ['B:3'],
    ['B:1', 'B:3'],
    ['B:3']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTE', 'B:3', 'S:FS'], ['OTL', 'B:0', 'S:FS'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [['B:0', 'B:3'], [], [], [], [], []]],
  ['control: scenario 2',
   [[['OTL', 'B:2', 'I:1'], ['OTL', 'B:3', 'I:2'], ['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:0', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:3', 'I:0']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[], [], [], [], ['B:0', 'B:3'], ['B:0']]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:2'], ['OTE', 'B:1', 'I:0'], ['OTL', 'B:1', 'I:0']],
    [{'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], [], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTL', 'B:0', 'I:2'], ['OTL', 'B:2', 'S:FS'], ['OTU', 'B:0', 'I:2'], ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:2'], ['B:2'], ['B:2'], ['B:2'], ['B:2']]],
  ['control: scenario 4',
   [[['OTU', 'B:3', 'I:1'], ['OTU', 'B:0', 'S:FS'], ['OTE', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], ['B:3'], [], [], []]]],
 [['regression: scenario 11',
   [[['OTL', 'B:1', 'I:2'], ['OTU', 'B:3', 'I:1'], ['OTE', 'B:0', 'I:2'], ['OTL', 'B:1', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1'], ['B:1'], ['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 53',
   [[['OTE', 'B:1', 'S:FS'],
     ['OTU', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:2'],
     ['OTU', 'B:0', 'I:1']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[],
    ['B:1', 'B:2'],
    ['B:2'],
    ['B:2'],
    ['B:2'],
    ['B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:1'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTE', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:3'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:3'], ['B:0', 'B:3']]],
  ['control: scenario 2',
   [[['OTE', 'B:1', 'I:1'],
     ['OTU', 'B:3', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1', 'B:3'], ['B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3']]]],
 [['regression: scenario 17',
   [[['OTL', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:2'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['regression: scenario 37',
   [[['OTU', 'B:2', 'I:2'], ['OTL', 'B:1', 'S:FS'], ['OTU', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:0', 'B:1'], ['B:1']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:1']],
    [{'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3']]],
  ['regression: scenario 2',
   [[['OTU', 'B:0', 'I:2'], ['OTE', 'B:2', 'I:0'], ['OTL', 'B:1', 'I:2']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:1', 'B:2'], ['B:1', 'B:2'], ['B:1'], ['B:1']]]]]
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(rungs, scans):
    bits = {}
    first = True
    out = []
    for scan in scans:
        if scan.get('power_cycle'):
            for instr, bit, cond in rungs:
                if instr == 'OTE' and cond != 'S:FS':
                    bits[bit] = False
            first = True
            out.append(sorted(b for b, v in bits.items() if v))
            continue
        for instr, bit, cond in rungs:
            rung = first if cond == 'S:FS' else bool(scan.get(cond, False))
            if instr == 'OTE':
                bits[bit] = rung
            elif rung and instr == 'OTL':
                bits[bit] = True
            elif rung and instr == 'OTU':
                bits[bit] = False
        first = False
        out.append(sorted(b for b, v in bits.items() if v))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['regression: scenario 19',
   [[['OTL', 'B:3', 'I:1'], ['OTU', 'B:3', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:2'], [], ['B:2'], [], [], [], ['B:2', 'B:3'], [], [], ['B:2', 'B:3']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:0', 'I:0'],
     ['OTE', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTE', 'B:2', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True}]],
   [['B:0'], [], ['B:2', 'B:3'], ['B:3'], ['B:3'], ['B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTU', 'B:2', 'I:1'], ['OTL', 'B:1', 'I:1'], ['OTL', 'B:1', 'I:2'], ['OTL', 'B:0', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True}]],
   [['B:0'],
    ['B:0'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1'],
    ['B:0', 'B:1']]],
  ['control: scenario 3',
   [[['OTE', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'I:0'],
     ['OTL', 'B:2', 'I:2'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:2'], ['B:2'], ['B:2']]]],
 [['regression: scenario 5',
   [[['OTE', 'B:2', 'I:2'],
     ['OTE', 'B:0', 'I:0'],
     ['OTE', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:2'], [], [], ['B:0', 'B:2'], [], []]],
  ['regression: scenario 7',
   [[['OTU', 'B:2', 'I:0'], ['OTL', 'B:3', 'S:FS'], ['OTE', 'B:1', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True}]],
   [['B:1', 'B:3'],
    ['B:3'],
    ['B:3'],
    ['B:3'],
    ['B:1', 'B:3'],
    ['B:3'],
    ['B:3'],
    ['B:3'],
    ['B:1', 'B:3'],
    ['B:3']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTE', 'B:3', 'S:FS'], ['OTL', 'B:0', 'S:FS'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [['B:0', 'B:3'], [], [], [], [], []]],
  ['control: scenario 2',
   [[['OTL', 'B:2', 'I:1'], ['OTL', 'B:3', 'I:2'], ['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [['B:0', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3'],
    ['B:0', 'B:2', 'B:3']]]],
 [['regression: scenario 3',
   [[['OTU', 'B:0', 'I:0'], ['OTL', 'B:0', 'I:0'], ['OTE', 'B:3', 'I:0']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[], [], [], [], ['B:0', 'B:3'], ['B:0']]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:2'], ['OTE', 'B:1', 'I:0'], ['OTL', 'B:1', 'I:0']],
    [{'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], [], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['control: scenario 2',
   [[['OTL', 'B:0', 'I:2'], ['OTL', 'B:2', 'S:FS'], ['OTU', 'B:0', 'I:2'], ['OTU', 'B:3', 'I:2']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [['B:2'], ['B:2'], ['B:2'], ['B:2'], ['B:2']]],
  ['control: scenario 4',
   [[['OTU', 'B:3', 'I:1'], ['OTU', 'B:0', 'S:FS'], ['OTE', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True}]],
   [[], ['B:3'], [], [], []]]],
 [['regression: scenario 11',
   [[['OTL', 'B:1', 'I:2'], ['OTU', 'B:3', 'I:1'], ['OTE', 'B:0', 'I:2'], ['OTL', 'B:1', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1'], ['B:1'], ['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 53',
   [[['OTE', 'B:1', 'S:FS'],
     ['OTU', 'B:0', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:2'],
     ['OTU', 'B:0', 'I:1']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True}]],
   [[],
    ['B:1', 'B:2'],
    ['B:2'],
    ['B:2'],
    ['B:2'],
    ['B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:1', 'B:2'],
    ['B:2']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['regression: scenario 1',
   [[['OTL', 'B:3', 'I:1'],
     ['OTL', 'B:1', 'S:FS'],
     ['OTU', 'B:1', 'S:FS'],
     ['OTL', 'B:0', 'S:FS'],
     ['OTE', 'B:2', 'I:0']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:0', 'B:2'], ['B:0', 'B:3'], ['B:0', 'B:2', 'B:3'], ['B:0', 'B:3'], ['B:0', 'B:3']]],
  ['control: scenario 2',
   [[['OTE', 'B:1', 'I:1'],
     ['OTU', 'B:3', 'I:2'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:3', 'I:2'],
     ['OTL', 'B:3', 'I:1']],
    [{'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False}]],
   [['B:1', 'B:3'], ['B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3'], ['B:1', 'B:3']]]],
 [['regression: scenario 17',
   [[['OTL', 'B:2', 'I:2'],
     ['OTU', 'B:2', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:3', 'I:2'],
     ['OTE', 'B:1', 'I:1']],
    [{'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True}]],
   [['B:2'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:2', 'B:3'], ['B:1', 'B:3'], ['B:3'], ['B:3']]],
  ['regression: scenario 37',
   [[['OTU', 'B:2', 'I:2'], ['OTL', 'B:1', 'S:FS'], ['OTU', 'B:0', 'I:0'], ['OTE', 'B:0', 'S:FS']],
    [{'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'power_cycle': True},
     {'power_cycle': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:1'], ['B:0', 'B:1'], ['B:1']]],
  ['control: latched through power cycle',
   [[['OTL', 'B:0', 'I:0'], ['OTU', 'B:0', 'I:1'], ['OTE', 'B:1', 'I:0'], ['OTE', 'B:2', 'S:FS']],
    [{'I:0': True}, {}, {'power_cycle': True}, {}, {'I:1': True}]],
   [['B:0', 'B:1', 'B:2'], ['B:0'], ['B:0'], ['B:0', 'B:2'], []]],
  ['control: unlatch listed before latch',
   [[['OTU', 'B:3', 'I:1'], ['OTL', 'B:3', 'I:0']], [{'I:0': True, 'I:1': True}, {}, {'I:1': True}]],
   [['B:3'], ['B:3'], []]],
  ['regression: first-scan output then power cycle',
   [[['OTE', 'B:2', 'S:FS'], ['OTL', 'B:0', 'S:FS']], [{}, {'power_cycle': True}, {}, {}]],
   [['B:0', 'B:2'], ['B:0'], ['B:0', 'B:2'], ['B:0']]],
  ['control: latch then idle',
   [[['OTL', 'B:1', 'I:2'], ['OTE', 'B:0', 'I:2']], [{'I:2': True}, {}, {'power_cycle': True}, {}]],
   [['B:0', 'B:1'], ['B:1'], ['B:1'], ['B:1']]],
  ['control: scenario 1',
   [[['OTL', 'B:3', 'S:FS'],
     ['OTL', 'B:1', 'I:1'],
     ['OTL', 'B:2', 'S:FS'],
     ['OTL', 'B:1', 'I:0'],
     ['OTL', 'B:1', 'I:1']],
    [{'power_cycle': True},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': False, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': False, 'I:1': False, 'I:2': False}]],
   [[],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3'],
    ['B:1', 'B:2', 'B:3']]],
  ['regression: scenario 2',
   [[['OTU', 'B:0', 'I:2'], ['OTE', 'B:2', 'I:0'], ['OTL', 'B:1', 'I:2']],
    [{'power_cycle': True},
     {'I:0': False, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': False},
     {'I:0': True, 'I:1': False, 'I:2': True},
     {'I:0': True, 'I:1': True, 'I:2': False},
     {'power_cycle': True},
     {'I:0': False, 'I:1': True, 'I:2': False}]],
   [[], [], ['B:2'], ['B:2'], ['B:2'], ['B:1', 'B:2'], ['B:1', 'B:2'], ['B:1'], ['B:1']]]]]
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 output coil that was on before the power loss is reported on after prescan, before its rung has been solved.

Latch (OTL), unlatch (OTU) and non-retentive output (OTE) rungs executed in program order each scan. rungs is a list of [instr, bit, condition_tag]; the rung is true when the condition input is true, or, for condition S:FS, on the first scan after power-up. A scan item {"power_cycle": true} models a power cycle: prescan clears only OTE destination bits, OTL/OTU bits are retentive, and the next scan is a first scan; it also reports the post-prescan state. OTL sets and OTU clears its bit only when its rung is true; the later rung wins. Return the sorted true bits after each item.

split: open-access


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

N = 1
observations = []
def solve(period, watchdog, exec_times):
    t_free = 0
    starts = []
    overlaps = 0
    fault = None
    for k, ex in enumerate(exec_times):
        trig = k * period
        if trig <= t_free:
            overlaps += 1
            continue
        starts.append(trig)
        if ex > watchdog:
            fault = trig + watchdog
            break
        t_free = trig + ex
    return [starts, overlaps, fault]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: scenario 1', [50, 100, [100, 100, 100, 100, 50, 25]], [[0, 100, 200, 250], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2', [20, 100, [100, 100, 60, 39, 20, 40, 54, 40]], [[0, 100, 140], 5, None]],
  ['regression: scenario 3', [50, 40, [50, 100, 50, 100, 100, 40]], [[0], 0, 40]]],
 [['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: scenario 1', [20, 60, [60, 20, 36, 40, 20]], [[0, 60], 3, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2',
   [10, 100, [10, 10, 10, 10, 10, 20, 100, 3, 20, 10, 100]],
   [[0, 10, 20, 30, 40, 50, 70, 80, 100], 2, None]],
  ['regression: scenario 3', [20, 100, [40, 40, 51, 40, 100]], [[0, 40], 3, None]]],
 [['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: scenario 3',
   [20, 30, [20, 30, 6, 30, 40, 39, 61, 36, 40, 40, 30, 20]],
   [[0, 20, 60, 100], 2, 130]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [20, 100, [100, 20, 60, 100, 40, 20, 30, 12]], [[0, 100, 120], 5, None]],
  ['regression: scenario 2', [10, 40, [50, 40, 10, 40, 10, 61, 60, 40, 20, 20, 10, 10]], [[0], 0, 40]]],
 [['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: scenario 3',
   [10, 40, [20, 20, 20, 20, 10, 61, 55, 66, 20, 37, 40, 40]],
   [[0, 20, 40, 50], 2, 90]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1',
   [20, 30, [21, 20, 20, 20, 40, 30, 20, 30, 40, 30, 40]],
   [[0, 40, 60, 80], 1, 110]],
  ['regression: scenario 2',
   [50, 100, [100, 100, 100, 50, 100, 50, 100, 50, 100, 15, 100, 50]],
   [[0, 100, 200, 300, 400, 500], 6, None]]],
 [['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 10',
   [10, 40, [40, 40, 40, 20, 10, 40, 14, 21, 20, 40, 41, 10]],
   [[0, 40, 50, 90], 8, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: scenario 1', [25, 60, [70, 25, 60, 35, 25, 15, 60, 60, 25, 50, 25, 4]], [[0], 0, 60]],
  ['regression: scenario 2', [20, 30, [40, 33, 50, 20, 40, 30, 30, 29, 30, 68, 20]], [[0], 0, 30]]]]
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(period, watchdog, exec_times):
    t_free = 0
    starts = []
    overlaps = 0
    fault = None
    for k, ex in enumerate(exec_times):
        trig = k * period
        if k and trig <= t_free:
            overlaps += 1
            continue
        starts.append(trig)
        if ex > watchdog:
            fault = trig + watchdog
            break
        t_free = trig + ex
    return [starts, overlaps, fault]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: scenario 1', [50, 100, [100, 100, 100, 100, 50, 25]], [[0, 100, 200, 250], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2', [20, 100, [100, 100, 60, 39, 20, 40, 54, 40]], [[0, 100, 140], 5, None]],
  ['regression: scenario 3', [50, 40, [50, 100, 50, 100, 100, 40]], [[0], 0, 40]]],
 [['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: scenario 1', [20, 60, [60, 20, 36, 40, 20]], [[0, 60], 3, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2',
   [10, 100, [10, 10, 10, 10, 10, 20, 100, 3, 20, 10, 100]],
   [[0, 10, 20, 30, 40, 50, 70, 80, 100], 2, None]],
  ['regression: scenario 3', [20, 100, [40, 40, 51, 40, 100]], [[0, 40], 3, None]]],
 [['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: scenario 3',
   [20, 30, [20, 30, 6, 30, 40, 39, 61, 36, 40, 40, 30, 20]],
   [[0, 20, 60, 100], 2, 130]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [20, 100, [100, 20, 60, 100, 40, 20, 30, 12]], [[0, 100, 120], 5, None]],
  ['regression: scenario 2', [10, 40, [50, 40, 10, 40, 10, 61, 60, 40, 20, 20, 10, 10]], [[0], 0, 40]]],
 [['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: scenario 3',
   [10, 40, [20, 20, 20, 20, 10, 61, 55, 66, 20, 37, 40, 40]],
   [[0, 20, 40, 50], 2, 90]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1',
   [20, 30, [21, 20, 20, 20, 40, 30, 20, 30, 40, 30, 40]],
   [[0, 40, 60, 80], 1, 110]],
  ['regression: scenario 2',
   [50, 100, [100, 100, 100, 50, 100, 50, 100, 50, 100, 15, 100, 50]],
   [[0, 100, 200, 300, 400, 500], 6, None]]],
 [['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 10',
   [10, 40, [40, 40, 40, 20, 10, 40, 14, 21, 20, 40, 41, 10]],
   [[0, 40, 50, 90], 8, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: scenario 1', [25, 60, [70, 25, 60, 35, 25, 15, 60, 60, 25, 50, 25, 4]], [[0], 0, 60]],
  ['regression: scenario 2', [20, 30, [40, 33, 50, 20, 40, 30, 30, 29, 30, 68, 20]], [[0], 0, 30]]]]
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:
Periodic tasks whose execution equals the period are skipped every other cycle and the overlap counter climbs.

Periodic task triggered every period ms from t=0; exec_times[k] is how long the k-th triggered execution would take. A trigger arriving while the previous execution is still running (trigger time < completion time) is an overlap: it is counted and skipped, not queued; a trigger exactly at completion starts normally. An execution longer than watchdog raises a major fault at start + watchdog and scheduling stops. Return [start_times, overlap_count, fault_time or None].

split: open-access


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

N = 1
observations = []
def solve(period, watchdog, exec_times):
    t_free = 0
    starts = []
    overlaps = 0
    fault = None
    for k, ex in enumerate(exec_times):
        trig = k * period
        if trig < t_free:
            overlaps += 1
            t_free += ex
            continue
        starts.append(trig)
        if ex > watchdog:
            fault = trig + watchdog
            break
        t_free = trig + ex
    return [starts, overlaps, fault]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['regression: scenario 1', [50, 100, [100, 100, 100, 100, 50, 25]], [[0, 100, 200, 250], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['control: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2', [20, 100, [100, 100, 60, 39, 20, 40, 54, 40]], [[0, 100, 140], 5, None]],
  ['control: scenario 3', [50, 40, [50, 100, 50, 100, 100, 40]], [[0], 0, 40]]],
 [['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: scenario 2',
   [10, 100, [10, 10, 10, 10, 10, 20, 100, 3, 20, 10, 100]],
   [[0, 10, 20, 30, 40, 50, 70, 80, 100], 2, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['control: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [20, 60, [60, 20, 36, 40, 20]], [[0, 60], 3, None]],
  ['regression: scenario 3', [20, 100, [40, 40, 51, 40, 100]], [[0, 40], 3, None]]],
 [['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 4', [25, 30, [30, 30, 6, 16, 50, 30]], [[0, 50, 75, 100], 1, 130]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['control: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: scenario 1', [20, 100, [100, 20, 60, 100, 40, 20, 30, 12]], [[0, 100, 120], 5, None]],
  ['control: scenario 2', [10, 40, [50, 40, 10, 40, 10, 61, 60, 40, 20, 20, 10, 10]], [[0], 0, 40]]],
 [['regression: scenario 1',
   [20, 30, [21, 20, 20, 20, 40, 30, 20, 30, 40, 30, 40]],
   [[0, 40, 60, 80], 1, 110]],
  ['regression: scenario 5', [10, 30, [30, 30, 30, 28, 10, 30]], [[0, 30], 4, None]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['control: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2',
   [50, 100, [100, 100, 100, 50, 100, 50, 100, 50, 100, 15, 100, 50]],
   [[0, 100, 200, 300, 400, 500], 6, None]]],
 [['regression: scenario 5', [25, 40, [25, 40, 40, 40, 24, 25, 50, 40, 50]], [[0, 25, 75, 125, 150], 2, 190]],
  ['regression: scenario 14',
   [20, 60, [40, 60, 40, 20, 60, 60, 43, 20, 12, 68, 20, 20]],
   [[0, 40, 80, 140, 160, 180], 4, 240]],
  ['regression: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['control: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['regression: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['control: scenario 1', [25, 60, [70, 25, 60, 35, 25, 15, 60, 60, 25, 50, 25, 4]], [[0], 0, 60]]]]
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:
Start times drift off the period grid after an overrun because missed triggers run late.

Periodic task triggered every period ms from t=0; exec_times[k] is how long the k-th triggered execution would take. A trigger arriving while the previous execution is still running (trigger time < completion time) is an overlap: it is counted and skipped, not queued; a trigger exactly at completion starts normally. An execution longer than watchdog raises a major fault at start + watchdog and scheduling stops. Return [start_times, overlap_count, fault_time or None].

split: open-access


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

N = 1
observations = []
def solve(period, watchdog, exec_times):
    t_free = 0
    starts = []
    overlaps = 0
    fault = None
    for k, ex in enumerate(exec_times):
        trig = k * period
        if trig < t_free:
            overlaps += 1
            continue
        starts.append(trig)
        if ex >= watchdog:
            fault = trig + watchdog
            break
        t_free = trig + ex
    return [starts, overlaps, fault]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [50, 100, [100, 100, 100, 100, 50, 25]], [[0, 100, 200, 250], 2, None]],
  ['regression: scenario 2', [20, 100, [100, 100, 60, 39, 20, 40, 54, 40]], [[0, 100, 140], 5, None]],
  ['regression: scenario 3', [50, 40, [50, 100, 50, 100, 100, 40]], [[0], 0, 40]]],
 [['regression: scenario 1', [20, 60, [60, 20, 36, 40, 20]], [[0, 60], 3, None]],
  ['regression: scenario 5', [25, 40, [53, 25, 25, 50, 50, 25, 25, 50]], [[0], 0, 40]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2',
   [10, 100, [10, 10, 10, 10, 10, 20, 100, 3, 20, 10, 100]],
   [[0, 10, 20, 30, 40, 50, 70, 80, 100], 2, None]]],
 [['regression: scenario 3',
   [20, 30, [20, 30, 6, 30, 40, 39, 61, 36, 40, 40, 30, 20]],
   [[0, 20, 60, 100], 2, 130]],
  ['regression: scenario 9', [50, 30, [50, 29, 42, 100, 100, 41, 5, 30, 100, 12]], [[0], 0, 30]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [20, 100, [100, 20, 60, 100, 40, 20, 30, 12]], [[0, 100, 120], 5, None]]],
 [['regression: scenario 5', [10, 30, [30, 30, 30, 28, 10, 30]], [[0, 30], 4, None]],
  ['regression: scenario 15', [50, 60, [100, 60, 60, 33, 50, 24, 100, 60, 60]], [[0], 0, 60]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['control: scenario 1', [20, 30, [21, 20, 20, 20, 40, 30, 20, 30, 40, 30, 40]], [[0, 40, 60, 80], 1, 110]]],
 [['regression: scenario 10',
   [10, 40, [40, 40, 40, 20, 10, 40, 14, 21, 20, 40, 41, 10]],
   [[0, 40, 50, 90], 8, None]],
  ['regression: scenario 7', [50, 40, [44, 9, 44, 100, 40, 68, 54, 100, 5, 40, 50]], [[0], 0, 40]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [25, 60, [70, 25, 60, 35, 25, 15, 60, 60, 25, 50, 25, 4]], [[0], 0, 60]]]]
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(period, watchdog, exec_times):
    t_free = 0
    starts = []
    overlaps = 0
    fault = None
    for k, ex in enumerate(exec_times):
        trig = k * period
        if trig < t_free:
            overlaps += 1
            continue
        starts.append(trig)
        if ex > watchdog and k > 0:
            fault = trig + watchdog
            break
        t_free = trig + ex
    return [starts, overlaps, fault]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [50, 100, [100, 100, 100, 100, 50, 25]], [[0, 100, 200, 250], 2, None]],
  ['regression: scenario 2', [20, 100, [100, 100, 60, 39, 20, 40, 54, 40]], [[0, 100, 140], 5, None]],
  ['regression: scenario 3', [50, 40, [50, 100, 50, 100, 100, 40]], [[0], 0, 40]]],
 [['regression: scenario 1', [20, 60, [60, 20, 36, 40, 20]], [[0, 60], 3, None]],
  ['regression: scenario 5', [25, 40, [53, 25, 25, 50, 50, 25, 25, 50]], [[0], 0, 40]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 2',
   [10, 100, [10, 10, 10, 10, 10, 20, 100, 3, 20, 10, 100]],
   [[0, 10, 20, 30, 40, 50, 70, 80, 100], 2, None]]],
 [['regression: scenario 3',
   [20, 30, [20, 30, 6, 30, 40, 39, 61, 36, 40, 40, 30, 20]],
   [[0, 20, 60, 100], 2, 130]],
  ['regression: scenario 9', [50, 30, [50, 29, 42, 100, 100, 41, 5, 30, 100, 12]], [[0], 0, 30]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [20, 100, [100, 20, 60, 100, 40, 20, 30, 12]], [[0, 100, 120], 5, None]]],
 [['regression: scenario 5', [10, 30, [30, 30, 30, 28, 10, 30]], [[0, 30], 4, None]],
  ['regression: scenario 15', [50, 60, [100, 60, 60, 33, 50, 24, 100, 60, 60]], [[0], 0, 60]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['control: scenario 1', [20, 30, [21, 20, 20, 20, 40, 30, 20, 30, 40, 30, 40]], [[0, 40, 60, 80], 1, 110]]],
 [['regression: scenario 10',
   [10, 40, [40, 40, 40, 20, 10, 40, 14, 21, 20, 40, 41, 10]],
   [[0, 40, 50, 90], 8, None]],
  ['regression: scenario 7', [50, 40, [44, 9, 44, 100, 40, 68, 54, 100, 5, 40, 50]], [[0], 0, 40]],
  ['control: mixed overlaps', [10, 50, [5, 15, 3, 10, 12, 4]], [[0, 10, 30, 40], 2, None]],
  ['control: watchdog exceeded', [10, 12, [5, 13, 4]], [[0, 10], 0, 22]],
  ['regression: exact watchdog', [20, 30, [30, 5, 5, 5]], [[0, 40, 60], 1, None]],
  ['regression: first execution overruns', [10, 25, [30, 5]], [[0], 0, 25]],
  ['control: skip then drift', [10, 100, [25, 1, 1, 1, 1, 1]], [[0, 30, 40, 50], 2, None]],
  ['regression: scenario 1', [25, 60, [70, 25, 60, 35, 25, 15, 60, 60, 25, 50, 25, 4]], [[0], 0, 60]]]]
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 task that finishes precisely at the watchdog time causes a major fault.

Periodic task triggered every period ms from t=0; exec_times[k] is how long the k-th triggered execution would take. A trigger arriving while the previous execution is still running (trigger time < completion time) is an overlap: it is counted and skipped, not queued; a trigger exactly at completion starts normally. An execution longer than watchdog raises a major fault at start + watchdog and scheduling stops. Return [start_times, overlap_count, fault_time or None].

split: open-access


prompt:
The major fault is logged later than it occurred, after the watchdog should already have stopped the task.

Periodic task triggered every period ms from t=0; exec_times[k] is how long the k-th triggered execution would take. A trigger arriving while the previous execution is still running (trigger time < completion time) is an overlap: it is counted and skipped, not queued; a trigger exactly at completion starts normally. An execution longer than watchdog raises a major fault at start + watchdog and scheduling stops. Return [start_times, overlap_count, fault_time or None].

split: open-access