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

N = 1
observations = []
def solve(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * (settings['max_pos'] - settings['min_pos'])
            target = (2 * num + span) // (2 * span)
        if target > pos:
            pos = min(target, pos + 10)
        else:
            pos = max(target, pos - 10)
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['control: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['control: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['control: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[634, True],
     [750, True],
     [806, True],
     [753, True],
     [817, False],
     [708, True],
     [649, True],
     [630, True],
     [579, True]]],
   [10, 20, 30, 40, 30, 36, 27, 25, 20]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['control: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]]],
 [['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 5',
   [{'min_pos': 10, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[515, True],
     [400, True],
     [400, True],
     [516, True],
     [637, True],
     [681, True],
     [818, True],
     [899, False],
     [844, True]]],
   [10, 10, 10, 10, 16, 24, 34, 24, 34]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]]],
 [['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[926, True],
     [1018, True],
     [890, True],
     [999, True],
     [942, True],
     [808, True],
     [889, True],
     [876, True],
     [853, True],
     [951, True],
     [843, True],
     [701, True]]],
   [10, 20, 30, 40, 43, 34, 39, 38, 37, 43, 36, 27]],
  ['regression: scenario 10',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1256, False],
     [1206, True],
     [1065, True],
     [1046, True],
     [1037, True],
     [1140, True],
     [1055, False],
     [1023, True],
     [930, True],
     [795, True],
     [685, False]]],
   [0, 10, 20, 30, 40, 50, 40, 44, 36, 26, 16]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['control: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]]]]
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(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * settings['max_pos']
            target = settings['min_pos'] + (2 * num + span) // (2 * span)
        if target > pos:
            pos = min(target, pos + 10)
        else:
            pos = max(target, pos - 10)
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['control: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['control: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['control: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[634, True],
     [750, True],
     [806, True],
     [753, True],
     [817, False],
     [708, True],
     [649, True],
     [630, True],
     [579, True]]],
   [10, 20, 30, 40, 30, 36, 27, 25, 20]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['control: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]]],
 [['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 5',
   [{'min_pos': 10, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[515, True],
     [400, True],
     [400, True],
     [516, True],
     [637, True],
     [681, True],
     [818, True],
     [899, False],
     [844, True]]],
   [10, 10, 10, 10, 16, 24, 34, 24, 34]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]]],
 [['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[926, True],
     [1018, True],
     [890, True],
     [999, True],
     [942, True],
     [808, True],
     [889, True],
     [876, True],
     [853, True],
     [951, True],
     [843, True],
     [701, True]]],
   [10, 20, 30, 40, 43, 34, 39, 38, 37, 43, 36, 27]],
  ['regression: scenario 10',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1256, False],
     [1206, True],
     [1065, True],
     [1046, True],
     [1037, True],
     [1140, True],
     [1055, False],
     [1023, True],
     [930, True],
     [795, True],
     [685, False]]],
   [0, 10, 20, 30, 40, 50, 40, 44, 36, 26, 16]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['control: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['control: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]]]]
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:
Moderate CO2 levels ventilate less than the minimum outdoor air position.

CO2 demand-controlled ventilation per sample; samples are [co2_ppm, occupied]. Unoccupied target is 0%. Occupied: min_pos at or below co2_low, max_pos at or above co2_high, and linear in between rounded half up to whole percent. The damper moves toward the target by at most 10 percentage points per sample in either direction. Return the damper position per sample.

split: open-access


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

N = 1
observations = []
def solve(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * (settings['max_pos'] - settings['min_pos'])
            target = settings['min_pos'] + (2 * num + span) // (2 * span)
        if target > pos:
            pos = target
        else:
            pos = max(target, pos - 10)
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['regression: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['regression: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 7',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[675, True],
     [553, False],
     [630, True],
     [746, True],
     [799, False],
     [713, True],
     [783, True],
     [718, True]]],
   [10, 0, 10, 20, 10, 17, 27, 18]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]]],
 [['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 6',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[1241, True],
     [1251, True],
     [1129, True],
     [1007, True],
     [865, True],
     [796, True],
     [856, True],
     [908, True],
     [822, True],
     [747, True],
     [773, True],
     [762, True],
     [674, True]]],
   [10, 20, 30, 40, 35, 30, 34, 38, 32, 26, 28, 27, 21]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]]],
 [['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['regression: scenario 10',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1256, False],
     [1206, True],
     [1065, True],
     [1046, True],
     [1037, True],
     [1140, True],
     [1055, False],
     [1023, True],
     [930, True],
     [795, True],
     [685, False]]],
   [0, 10, 20, 30, 40, 50, 40, 44, 36, 26, 16]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[1068, True],
     [969, True],
     [993, True],
     [1093, True],
     [1019, True],
     [1021, True],
     [1037, False],
     [990, True],
     [876, False],
     [997, True],
     [984, True],
     [903, False],
     [822, False]]],
   [10, 20, 30, 40, 50, 60, 50, 60, 50, 60, 70, 60, 50]]]]
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(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * (settings['max_pos'] - settings['min_pos'])
            target = settings['min_pos'] + (2 * num + span) // (2 * span)
        if target > pos:
            pos = pos + 10
        else:
            pos = max(target, pos - 10)
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['regression: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['regression: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 7',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[675, True],
     [553, False],
     [630, True],
     [746, True],
     [799, False],
     [713, True],
     [783, True],
     [718, True]]],
   [10, 0, 10, 20, 10, 17, 27, 18]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]]],
 [['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 6',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[1241, True],
     [1251, True],
     [1129, True],
     [1007, True],
     [865, True],
     [796, True],
     [856, True],
     [908, True],
     [822, True],
     [747, True],
     [773, True],
     [762, True],
     [674, True]]],
   [10, 20, 30, 40, 35, 30, 34, 38, 32, 26, 28, 27, 21]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]]],
 [['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['regression: scenario 10',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1256, False],
     [1206, True],
     [1065, True],
     [1046, True],
     [1037, True],
     [1140, True],
     [1055, False],
     [1023, True],
     [930, True],
     [795, True],
     [685, False]]],
   [0, 10, 20, 30, 40, 50, 40, 44, 36, 26, 16]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[1068, True],
     [969, True],
     [993, True],
     [1093, True],
     [1019, True],
     [1021, True],
     [1037, False],
     [990, True],
     [876, False],
     [997, True],
     [984, True],
     [903, False],
     [822, False]]],
   [10, 20, 30, 40, 50, 60, 50, 60, 50, 60, 70, 60, 50]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The damper slams open when a meeting room fills, upsetting mixed-air temperature.

CO2 demand-controlled ventilation per sample; samples are [co2_ppm, occupied]. Unoccupied target is 0%. Occupied: min_pos at or below co2_low, max_pos at or above co2_high, and linear in between rounded half up to whole percent. The damper moves toward the target by at most 10 percentage points per sample in either direction. Return the damper position per sample.

split: open-access


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

N = 1
observations = []
def solve(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * (settings['max_pos'] - settings['min_pos'])
            target = settings['min_pos'] + (2 * num + span) // (2 * span)
        if target > pos:
            pos = min(target, pos + 10)
        else:
            pos = max(0, pos - 10)
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['regression: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[675, True],
     [548, False],
     [502, True],
     [455, False],
     [400, True],
     [462, True],
     [400, True],
     [400, True],
     [400, True],
     [402, False],
     [447, True]]],
   [10, 0, 10, 0, 10, 10, 10, 10, 10, 0, 10]]],
 [['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[1187, True],
     [1190, True],
     [1257, True],
     [1112, True],
     [1113, True],
     [971, True],
     [928, False],
     [1003, True]]],
   [10, 20, 30, 40, 50, 60, 50, 60]]],
 [['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[926, True],
     [1018, True],
     [890, True],
     [999, True],
     [942, True],
     [808, True],
     [889, True],
     [876, True],
     [853, True],
     [951, True],
     [843, True],
     [701, True]]],
   [10, 20, 30, 40, 43, 34, 39, 38, 37, 43, 36, 27]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[1068, True],
     [969, True],
     [993, True],
     [1093, True],
     [1019, True],
     [1021, True],
     [1037, False],
     [990, True],
     [876, False],
     [997, True],
     [984, True],
     [903, False],
     [822, False]]],
   [10, 20, 30, 40, 50, 60, 50, 60, 50, 60, 70, 60, 50]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]]]]
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(settings, samples):
    pos = 0
    out = []
    for co2, occupied in samples:
        if not occupied:
            target = 0
        elif co2 <= settings['co2_low']:
            target = settings['min_pos']
        elif co2 >= settings['co2_high']:
            target = settings['max_pos']
        else:
            span = settings['co2_high'] - settings['co2_low']
            num = (co2 - settings['co2_low']) * (settings['max_pos'] - settings['min_pos'])
            target = settings['min_pos'] + (2 * num + span) // (2 * span)
        if target > pos:
            pos = min(target, pos + 10)
        else:
            pos = target
        out.append(pos)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['control: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1000},
    [[424, True], [551, True], [655, True], [713, True], [740, True], [769, True], [840, True], [858, True]]],
   [10, 20, 30, 40, 48, 54, 64, 72]],
  ['regression: scenario 2',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1150, True],
     [1009, True],
     [1044, True],
     [985, False],
     [1131, False],
     [982, True],
     [895, True],
     [828, False]]],
   [10, 20, 30, 20, 10, 20, 30, 20]],
  ['regression: scenario 3',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1000},
    [[1300, False],
     [1254, True],
     [1354, True],
     [1400, False],
     [1471, True],
     [1498, True],
     [1500, False],
     [1488, True],
     [1500, False],
     [1500, True],
     [1500, False],
     [1464, True]]],
   [0, 10, 20, 10, 20, 30, 20, 30, 20, 30, 20, 30]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[802, True],
     [856, True],
     [954, True],
     [853, True],
     [816, True],
     [847, False],
     [865, True],
     [741, True],
     [680, True],
     [592, True],
     [485, True]]],
   [10, 20, 30, 40, 45, 35, 45, 35, 25, 15, 10]]],
 [['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: scenario 1',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[631, True],
     [545, True],
     [465, True],
     [503, True],
     [568, True],
     [550, True],
     [450, False],
     [459, True],
     [434, True],
     [539, True],
     [480, True],
     [462, False],
     [400, True],
     [400, True]]],
   [10, 20, 20, 20, 20, 20, 10, 20, 20, 20, 20, 10, 20, 20]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[775, True],
     [743, True],
     [851, True],
     [853, True],
     [893, True],
     [872, True],
     [870, True],
     [781, False],
     [813, True],
     [851, True],
     [955, True]]],
   [10, 20, 30, 40, 50, 52, 52, 42, 39, 48, 58]],
  ['regression: scenario 3',
   [{'min_pos': 10, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1200},
    [[1109, True],
     [1033, False],
     [1170, False],
     [1235, True],
     [1208, True],
     [1230, True],
     [1178, True],
     [1182, True],
     [1206, False],
     [1261, True],
     [1328, True],
     [1474, True]]],
   [10, 0, 0, 10, 20, 30, 40, 50, 40, 50, 60, 70]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 600, 'co2_high': 1200},
    [[1028, True],
     [998, True],
     [1129, True],
     [1164, True],
     [1200, True],
     [1276, False],
     [1335, True],
     [1192, True],
     [1105, True],
     [1194, True],
     [1207, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 70, 79, 80]]],
 [['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[1018, True],
     [1052, True],
     [988, True],
     [1071, True],
     [1109, True],
     [1124, True],
     [1196, True],
     [1221, False],
     [1203, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1000},
    [[523, True],
     [506, True],
     [620, False],
     [668, True],
     [557, True],
     [453, True],
     [400, True],
     [400, True],
     [409, True],
     [455, False],
     [443, False],
     [561, True]]],
   [10, 10, 0, 10, 10, 10, 10, 10, 10, 0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[640, True],
     [668, False],
     [658, True],
     [602, False],
     [640, False],
     [525, False],
     [604, True],
     [456, True],
     [591, True],
     [611, True]]],
   [10, 0, 10, 0, 0, 0, 10, 20, 20, 21]],
  ['regression: scenario 4',
   [{'min_pos': 10, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[675, True],
     [548, False],
     [502, True],
     [455, False],
     [400, True],
     [462, True],
     [400, True],
     [400, True],
     [400, True],
     [402, False],
     [447, True]]],
   [10, 0, 10, 0, 10, 10, 10, 10, 10, 0, 10]]],
 [['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 60, 'co2_low': 700, 'co2_high': 1200},
    [[1121, True],
     [1144, True],
     [1172, True],
     [1223, True],
     [1138, True],
     [1273, True],
     [1319, True],
     [1227, False],
     [1253, True]]],
   [10, 20, 30, 40, 50, 60, 60, 50, 60]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1000},
    [[853, True],
     [828, True],
     [845, True],
     [890, False],
     [973, True],
     [895, True],
     [751, True],
     [855, True],
     [839, False],
     [909, True],
     [1031, True],
     [926, True],
     [1032, True]]],
   [10, 20, 30, 20, 30, 40, 35, 45, 35, 45, 55, 53, 60]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 2',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[570, True],
     [539, True],
     [432, True],
     [498, True],
     [536, True],
     [559, True],
     [607, True],
     [706, False],
     [703, False],
     [767, True],
     [618, False],
     [742, False],
     [796, True]]],
   [10, 20, 20, 20, 20, 20, 20, 10, 0, 10, 0, 0, 10]],
  ['regression: scenario 4',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1000},
    [[1187, True],
     [1190, True],
     [1257, True],
     [1112, True],
     [1113, True],
     [971, True],
     [928, False],
     [1003, True]]],
   [10, 20, 30, 40, 50, 60, 50, 60]]],
 [['regression: scenario 5',
   [{'min_pos': 20, 'max_pos': 60, 'co2_low': 600, 'co2_high': 1200},
    [[926, True],
     [1018, True],
     [890, True],
     [999, True],
     [942, True],
     [808, True],
     [889, True],
     [876, True],
     [853, True],
     [951, True],
     [843, True],
     [701, True]]],
   [10, 20, 30, 40, 43, 34, 39, 38, 37, 43, 36, 27]],
  ['regression: scenario 3',
   [{'min_pos': 20, 'max_pos': 100, 'co2_low': 600, 'co2_high': 1200},
    [[1068, True],
     [969, True],
     [993, True],
     [1093, True],
     [1019, True],
     [1021, True],
     [1037, False],
     [990, True],
     [876, False],
     [997, True],
     [984, True],
     [903, False],
     [822, False]]],
   [10, 20, 30, 40, 50, 60, 50, 60, 50, 60, 70, 60, 50]],
  ['regression: occupied day',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[650, True],
     [650, True],
     [900, True],
     [900, True],
     [900, True],
     [900, True],
     [1300, True],
     [1300, False]]],
   [10, 20, 30, 40, 50, 50, 60, 50]],
  ['regression: crowd arrives',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, True],
     [1500, False],
     [1500, False]]],
   [10, 20, 30, 40, 50, 60, 70, 80, 80, 70, 60]],
  ['regression: moderate co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[800, True], [800, True], [800, True], [800, True], [800, True], [750, True], [750, True]]],
   [10, 20, 30, 35, 35, 28, 28]],
  ['control: unoccupied high co2',
   [{'min_pos': 20, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1100},
    [[1200, False], [1200, False], [1200, True]]],
   [0, 0, 10]],
  ['regression: scenario 1',
   [{'min_pos': 15, 'max_pos': 80, 'co2_low': 700, 'co2_high': 1200},
    [[1383, True],
     [1500, True],
     [1500, True],
     [1483, True],
     [1492, True],
     [1500, False],
     [1500, True],
     [1500, True],
     [1500, False],
     [1465, True],
     [1443, False],
     [1458, False],
     [1430, True]]],
   [10, 20, 30, 40, 50, 40, 50, 60, 50, 60, 50, 40, 50]],
  ['regression: scenario 2',
   [{'min_pos': 15, 'max_pos': 100, 'co2_low': 700, 'co2_high': 1000},
    [[788, True],
     [835, True],
     [980, True],
     [906, False],
     [1052, True],
     [960, False],
     [1028, True],
     [1053, False],
     [1100, True],
     [1140, False]]],
   [10, 20, 30, 20, 30, 20, 30, 20, 30, 20]]]]
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 CO2 drops the damper keeps closing below the minimum ventilation position.

CO2 demand-controlled ventilation per sample; samples are [co2_ppm, occupied]. Unoccupied target is 0%. Occupied: min_pos at or below co2_low, max_pos at or above co2_high, and linear in between rounded half up to whole percent. The damper moves toward the target by at most 10 percentage points per sample in either direction. Return the damper position per sample.

split: open-access