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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]],
  ['control 3', [[[0, 'ev_resume'], [10, 'plug'], [70, 'stop'], [100, 'stop']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]],
  ['control 3', [[[61, 'auth'], [66, 'unplug'], [127, 'plug'], [132, 'ev_resume']], 60],
   ['Preparing', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]],
  ['control 3', [[[5, 'auth'], [65, 'unplug'], [75, 'plug'], [75, 'unplug']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]],
  ['control 3', [[[30, 'auth'], [60, 'ev_pause'], [120, 'auth'], [125, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]],
  ['control 3',
   [[[30, 'plug'], [330, 'ev_resume'], [340, 'unplug'], [340, 'ev_pause'], [350, 'plug'],
     [650, 'unplug'], [650, 'plug'], [680, 'plug']],
    90],
   ['Preparing', 0, 2, 0]]]]
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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = plug_t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]],
  ['control 3', [[[0, 'ev_resume'], [10, 'plug'], [70, 'stop'], [100, 'stop']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]],
  ['control 3', [[[61, 'auth'], [66, 'unplug'], [127, 'plug'], [132, 'ev_resume']], 60],
   ['Preparing', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]],
  ['control 3', [[[5, 'auth'], [65, 'unplug'], [75, 'plug'], [75, 'unplug']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]],
  ['control 3', [[[30, 'auth'], [60, 'ev_pause'], [120, 'auth'], [125, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: resume restarts interval',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]],
  ['control 3',
   [[[30, 'plug'], [330, 'ev_resume'], [340, 'unplug'], [340, 'ev_pause'], [350, 'plug'],
     [650, 'unplug'], [650, 'plug'], [680, 'plug']],
    90],
   ['Preparing', 0, 2, 0]]]]
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:
Charging time after a resume includes the paused period.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p < threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[20, 12, 10, 20, 0, 20, 15, 5, -2, 10, 30, 12, 0, 30, 12], 10, 3, 4], [[4, 7, 8, 9], True]],
  ['regression: threshold inclusivity (partial repair)',
   [[0, 30, 5, 0, 20, 12, 0, 5, -2, 5, -2, 30, 30, 20, 8, 5], 12, 1, 4], [[0, 2, 3, 5], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[-2, 10, 5, 8, 8, 0, 20, 12, 8, 12, -2, 15, -2, 8, 0, 0], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity', [[5, 15, 8, 12, 15, 20, 10, 15, 30, 15], 10, 1, 3],
   [[0, 2, 6], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[5, 0, -2, 5, 30, 0, 30, -2, 8, 10, 5, 8, 20, 5], 8, 2, 4], [[0, 1, 2, 3], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[10, 8, 8, 8, 15, 12, 30, -2, 15, -2, 8, 12, 5, 15], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[12, 20, 10, 15, 8, 12, 8, 5, 0, -2, 10, 15, 8, 15, 20], 0, 1, 1], [[8], False]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[10, 12, 8, 12, -2, 8, 12, 12, 30, 8, 12, 0, 0, 15, -2, 15], 12, 2, 7],
   [[0, 1, 2, 3, 4, 5, 6], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[30, 0, -2, 12, 5, 0, 0, -2, 10, 5, 30, 15, 15], 8, 2, 1], [[1], False]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold and p > 0:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[20, 12, 10, 20, 0, 20, 15, 5, -2, 10, 30, 12, 0, 30, 12], 10, 3, 4], [[4, 7, 8, 9], True]],
  ['regression: threshold inclusivity (partial repair)',
   [[0, 30, 5, 0, 20, 12, 0, 5, -2, 5, -2, 30, 30, 20, 8, 5], 12, 1, 4], [[0, 2, 3, 5], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[-2, 10, 5, 8, 8, 0, 20, 12, 8, 12, -2, 15, -2, 8, 0, 0], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity', [[5, 15, 8, 12, 15, 20, 10, 15, 30, 15], 10, 1, 3],
   [[0, 2, 6], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[5, 0, -2, 5, 30, 0, 30, -2, 8, 10, 5, 8, 20, 5], 8, 2, 4], [[0, 1, 2, 3], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[10, 8, 8, 8, 15, 12, 30, -2, 15, -2, 8, 12, 5, 15], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[12, 20, 10, 15, 8, 12, 8, 5, 0, -2, 10, 15, 8, 15, 20], 0, 1, 1], [[8], False]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: threshold inclusivity',
   [[10, 12, 8, 12, -2, 8, 12, 12, 30, 8, 12, 0, 0, 15, -2, 15], 12, 2, 7],
   [[0, 1, 2, 3, 4, 5, 6], False]],
  ['regression: threshold inclusivity (partial repair)',
   [[30, 0, -2, 12, 5, 0, 0, -2, 10, 5, 30, 15, 15], 8, 2, 1], [[1], False]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Slots priced exactly at the threshold are not treated as cheap.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[8, 0, 12, 15, 10, 12, 12, 20, 10, 10, 8, 10, 8, 0], 10, 2, 3],
   [[0, 1, 8], False]],
  ['regression: final run flush (partial repair)', [[12, 15, 30, 5, 5, 5, 15, 10, 5, -2], 12, 3, 5],
   [[3, 4, 5, 7, 8], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: final run flush (partial repair)',
   [[-2, 30, 15, -2, 30, 30, 8, 5, 5, 8, 10, 0, -2], 0, 2, 2], [[11, 12], False]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[20, 30, 5, 5, 5], 10, 2, 3], [[2, 3, 4], False]],
  ['regression: final run flush (partial repair)',
   [[-2, 30, 15, -2, 30, 30, 8, 5, 5, 8, 10, 0, -2], 0, 2, 2], [[11, 12], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[10, 20, -2, 10, 10, 30, 12, 0], 12, 1, 5],
   [[0, 2, 3, 4, 6], False]],
  ['regression: final run flush (partial repair)',
   [[0, 15, 15, 0, 8, 30, 20, 10, 8, 5, 10, 15, 30, 20, 0, 0], 10, 2, 7],
   [[3, 4, 7, 8, 9, 10, 14], False]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[8, 5, 20, 0, 0, 0, -2, -2, -2, -2, -2, 0, -2], 10, 3, 8],
   [[3, 4, 5, 6, 7, 8, 9, 10], False]],
  ['regression: final run flush (partial repair)', [[12, 15, 30, 5, 5, 5, 15, 10, 5, -2], 12, 3, 5],
   [[3, 4, 5, 7, 8], False]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if len(cur) > min_len:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[8, 0, 12, 15, 10, 12, 12, 20, 10, 10, 8, 10, 8, 0], 10, 2, 3],
   [[0, 1, 8], False]],
  ['regression: final run flush (partial repair)', [[12, 15, 30, 5, 5, 5, 15, 10, 5, -2], 12, 3, 5],
   [[3, 4, 5, 7, 8], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: final run flush (partial repair)',
   [[-2, 30, 15, -2, 30, 30, 8, 5, 5, 8, 10, 0, -2], 0, 2, 2], [[11, 12], False]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[20, 30, 5, 5, 5], 10, 2, 3], [[2, 3, 4], False]],
  ['regression: final run flush (partial repair)',
   [[-2, 30, 15, -2, 30, 30, 8, 5, 5, 8, 10, 0, -2], 0, 2, 2], [[11, 12], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[10, 20, -2, 10, 10, 30, 12, 0], 12, 1, 5],
   [[0, 2, 3, 4, 6], False]],
  ['regression: final run flush (partial repair)',
   [[0, 15, 15, 0, 8, 30, 20, 10, 8, 5, 10, 15, 30, 20, 0, 0], 10, 2, 7],
   [[3, 4, 7, 8, 9, 10, 14], False]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: final run flush', [[8, 5, 20, 0, 0, 0, -2, -2, -2, -2, -2, 0, -2], 10, 3, 8],
   [[3, 4, 5, 6, 7, 8, 9, 10], False]],
  ['regression: final run flush (partial repair)', [[12, 15, 30, 5, 5, 5, 15, 10, 5, -2], 12, 3, 5],
   [[3, 4, 5, 7, 8], False]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A cheap run that lasts until the end of the horizon is never used.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) > min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length',
   [[20, 12, 10, 20, 0, 20, 15, 5, -2, 10, 30, 12, 0, 30, 12], 10, 3, 4], [[4, 7, 8, 9], True]],
  ['regression: minimum run length (partial repair)',
   [[0, 12, 8, 15, 10, 30, 5, 5, 5, 5, 8, 20, 15, 12, 8, 8], 8, 2, 3], [[6, 7, 8], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[5, 8, 0, -2, 15, 8, 5], 10, 4, 1], [[0], False]],
  ['regression: minimum run length (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[5, 15, 8, 12, 15, 20, 10, 15, 30, 15], 10, 1, 3],
   [[0, 2, 6], False]],
  ['regression: minimum run length (partial repair)',
   [[30, 10, 12, 0, 0, 5, 5, 30, 15, 0, 10], 10, 2, 4], [[3, 4, 5, 6], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length',
   [[10, 8, 8, 8, 15, 12, 30, -2, 15, -2, 8, 12, 5, 15], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: minimum run length (partial repair)',
   [[10, 30, 5, 20, 0, 8, 20, 10, 30, 30, 20, 30, 8, 30, 10], 12, 3, 2], [[2, 4], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[30, 0, -2, 12, 5, 0, 0, -2, 10, 5, 30, 15, 15], 8, 2, 1],
   [[1], False]],
  ['regression: minimum run length (partial repair)',
   [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7], [[0, 4, 5, 6, 8, 10, 11], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len - 1:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length',
   [[20, 12, 10, 20, 0, 20, 15, 5, -2, 10, 30, 12, 0, 30, 12], 10, 3, 4], [[4, 7, 8, 9], True]],
  ['regression: minimum run length (partial repair)',
   [[0, 12, 8, 15, 10, 30, 5, 5, 5, 5, 8, 20, 15, 12, 8, 8], 8, 2, 3], [[6, 7, 8], False]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[5, 8, 0, -2, 15, 8, 5], 10, 4, 1], [[0], False]],
  ['regression: minimum run length (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[5, 15, 8, 12, 15, 20, 10, 15, 30, 15], 10, 1, 3],
   [[0, 2, 6], False]],
  ['regression: minimum run length (partial repair)',
   [[30, 10, 12, 0, 0, 5, 5, 30, 15, 0, 10], 10, 2, 4], [[3, 4, 5, 6], False]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length',
   [[10, 8, 8, 8, 15, 12, 30, -2, 15, -2, 8, 12, 5, 15], 10, 4, 3], [[0, 1, 2], False]],
  ['regression: minimum run length (partial repair)',
   [[10, 30, 5, 20, 0, 8, 20, 10, 30, 30, 20, 30, 8, 30, 10], 12, 3, 2], [[2, 4], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: minimum run length', [[30, 0, -2, 12, 5, 0, 0, -2, 10, 5, 30, 15, 15], 8, 2, 1],
   [[1], False]],
  ['regression: minimum run length (partial repair)',
   [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7], [[0, 4, 5, 6, 8, 10, 11], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Runs exactly min_len long are ignored.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[0, 12, 8, 15, 10, 30, 5, 5, 5, 5, 8, 20, 15, 12, 8, 8], 8, 2, 3], [[6, 7, 8], False]],
  ['regression: run accumulator reset (partial repair)',
   [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7], [[0, 1, 4, 5, 6, 9, 10], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: run accumulator reset (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset', [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2],
   [[6, 10], True]],
  ['regression: run accumulator reset (partial repair)', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5],
   [[1, 2, 5, 6, 7], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[10, 30, 5, 20, 0, 8, 20, 10, 30, 30, 20, 30, 8, 30, 10], 12, 3, 2], [[2, 4], True]],
  ['regression: run accumulator reset (partial repair)',
   [[-2, -2, 15, -2, 5, 10, 5, 20, -2, 30, 20, 5, 10], 0, 4, 2], [[0, 1], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset', [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7],
   [[0, 4, 5, 6, 8, 10, 11], True]],
  ['regression: run accumulator reset (partial repair)',
   [[8, -2, 30, 12, 12, 0, -2, 12, 20, 15, 5, 12, 0, 15, -2], 0, 1, 8],
   [[0, 1, 3, 5, 6, 10, 12, 14], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(list(cur))
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[0, 12, 8, 15, 10, 30, 5, 5, 5, 5, 8, 20, 15, 12, 8, 8], 8, 2, 3], [[6, 7, 8], False]],
  ['regression: run accumulator reset (partial repair)',
   [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7], [[0, 1, 4, 5, 6, 9, 10], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: run accumulator reset (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset', [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2],
   [[6, 10], True]],
  ['regression: run accumulator reset (partial repair)', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5],
   [[1, 2, 5, 6, 7], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset',
   [[10, 30, 5, 20, 0, 8, 20, 10, 30, 30, 20, 30, 8, 30, 10], 12, 3, 2], [[2, 4], True]],
  ['regression: run accumulator reset (partial repair)',
   [[-2, -2, 15, -2, 5, 10, 5, 20, -2, 30, 20, 5, 10], 0, 4, 2], [[0, 1], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: run accumulator reset', [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7],
   [[0, 4, 5, 6, 8, 10, 11], True]],
  ['regression: run accumulator reset (partial repair)',
   [[8, -2, 30, 12, 12, 0, -2, 12, 20, 15, 5, 12, 0, 15, -2], 0, 1, 8],
   [[0, 1, 3, 5, 6, 10, 12, 14], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Separate cheap periods are merged into one long run that includes expensive gaps.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices))
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7], [[0, 1, 4, 5, 6, 9, 10], True]],
  ['regression: fallback excludes chosen slots (partial repair)', [[30, 12, 0, 20, 12, 0], 8, 3, 6],
   [[0, 1, 2, 3, 4, 5], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5],
   [[1, 2, 5, 6, 7], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2], [[6, 10], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots', [[12, 15, 20, 30, 10, 0, 8], 8, 1, 4],
   [[0, 4, 5, 6], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[12, 20, -2, 30, 0, 20], 10, 3, 5], [[0, 1, 2, 4, 5], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[8, -2, 30, 12, 12, 0, -2, 12, 20, 15, 5, 12, 0, 15, -2], 0, 1, 8],
   [[0, 1, 3, 5, 6, 10, 12, 14], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7], [[0, 4, 5, 6, 8, 10, 11], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if p > threshold)
        for p, i in rest[:need_slots - len(chosen)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7], [[0, 1, 4, 5, 6, 9, 10], True]],
  ['regression: fallback excludes chosen slots (partial repair)', [[30, 12, 0, 20, 12, 0], 8, 3, 6],
   [[0, 1, 2, 3, 4, 5], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1], [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5],
   [[1, 2, 5, 6, 7], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2], [[6, 10], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots', [[12, 15, 20, 30, 10, 0, 8], 8, 1, 4],
   [[0, 4, 5, 6], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[12, 20, -2, 30, 0, 20], 10, 3, 5], [[0, 1, 2, 4, 5], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback excludes chosen slots',
   [[8, -2, 30, 12, 12, 0, -2, 12, 20, 15, 5, 12, 0, 15, -2], 0, 1, 8],
   [[0, 1, 3, 5, 6, 10, 12, 14], True]],
  ['regression: fallback excludes chosen slots (partial repair)',
   [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7], [[0, 4, 5, 6, 8, 10, 11], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The fallback picks a slot that was already chosen, returning duplicates.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7],
   [[0, 1, 4, 5, 6, 9, 10], True]],
  ['regression: fallback count (partial repair)', [[30, 12, 0, 20, 12, 0], 8, 3, 6],
   [[0, 1, 2, 3, 4, 5], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: fallback count (partial repair)', [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1],
   [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5], [[1, 2, 5, 6, 7], True]],
  ['regression: fallback count (partial repair)',
   [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2], [[6, 10], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[12, 15, 20, 30, 10, 0, 8], 8, 1, 4], [[0, 4, 5, 6], True]],
  ['regression: fallback count (partial repair)', [[12, 20, -2, 30, 0, 20], 10, 3, 5],
   [[0, 1, 2, 4, 5], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7],
   [[0, 4, 5, 6, 8, 10, 11], True]],
  ['regression: fallback count (partial repair)',
   [[0, 12, 15, 20, 5, 20, 10, -2, 15, 20, 12, 10, 12, 20, 15], 0, 3, 1], [[7], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(prices, threshold, min_len, need_slots):
    runs = []
    cur = []
    for i, p in enumerate(prices):
        if p <= threshold:
            cur.append(i)
        else:
            if cur:
                runs.append(cur)
            cur = []
    if cur:
        runs.append(cur)
    chosen = []
    for run in runs:
        if len(run) >= min_len:
            for i in run:
                if len(chosen) < need_slots:
                    chosen.append(i)
    fallback = False
    if len(chosen) < need_slots:
        fallback = True
        rest = sorted((p, i) for i, p in enumerate(prices) if i not in chosen)
        for p, i in rest[:need_slots - len(runs)]:
            chosen.append(i)
    return [sorted(chosen), fallback]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[-2, -2, 10, 8, 0, 5, -2, 8, 20, -2, -2], 0, 1, 7],
   [[0, 1, 4, 5, 6, 9, 10], True]],
  ['regression: fallback count (partial repair)', [[30, 12, 0, 20, 12, 0], 8, 3, 6],
   [[0, 1, 2, 3, 4, 5], True]],
  ['control 1', [[5, 20, 15, 10, -2], 10, 3, 5], [[0, 1, 2, 3, 4], True]],
  ['control 2', [[30, 30, 0, -2, 20, 8, 5, 20, 0, 20], 0, 4, 1], [[3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count',
   [[20, 5, 15, 12, 15, 30, 5, 20, 0, 20, 10, 0, 5, -2, 10], 12, 4, 6],
   [[8, 10, 11, 12, 13, 14], True]],
  ['regression: fallback count (partial repair)', [[20, 8, 10, 30, -2, 0, 12, 20, 8, 8], 12, 4, 1],
   [[4], True]],
  ['control 1', [[30, -2, 5, 12, 8, 20, 20, 20], 12, 1, 7], [[1, 2, 3, 4, 5, 6, 7], True]],
  ['control 2', [[30, 8, 15, 0, 15], 8, 2, 2], [[1, 3], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[30, 8, 12, 30, 30, 5, 5, 12], 8, 1, 5], [[1, 2, 5, 6, 7], True]],
  ['regression: fallback count (partial repair)',
   [[20, 15, 10, 30, 12, 30, -2, 10, 15, 30, 5, 20], 12, 4, 2], [[6, 10], True]],
  ['control 1', [[20, -2, 10, 8, 15, 10, 0, 8, 12, 5, 8, 0, 8], 0, 1, 1], [[1], False]],
  ['control 2', [[-2, 8, 8, 12, -2, -2, -2, 10, 12, 15], 0, 2, 7], [[0, 1, 2, 4, 5, 6, 7], True]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[12, 15, 20, 30, 10, 0, 8], 8, 1, 4], [[0, 4, 5, 6], True]],
  ['regression: fallback count (partial repair)', [[12, 20, -2, 30, 0, 20], 10, 3, 5],
   [[0, 1, 2, 4, 5], True]],
  ['control 1', [[-2, 12, 30, 10, 10, 10, 15, 0, 15, 10, -2, 20, 0], 12, 4, 5],
   [[0, 3, 7, 10, 12], True]],
  ['control 2', [[10, 30, 15, 20, -2, 20, 10, 20, -2, 8, 5, 0, 20], 8, 3, 1], [[8], False]]],
 [['boundary: run ending at horizon', [[20, 20, 5, 5], 8, 2, 2], [[2, 3], False]],
  ['boundary: run exactly min_len', [[5, 5, 20, 5], 8, 2, 2], [[0, 1], False]],
  ['boundary: nothing needed', [[5, 5, 5], 8, 1, 0], [[], False]],
  ['regression: fallback count', [[-2, 10, 30, 12, 8, 0, 8, 30, -2, 12, -2, 0, 12], 8, 2, 7],
   [[0, 4, 5, 6, 8, 10, 11], True]],
  ['regression: fallback count (partial repair)',
   [[0, 12, 15, 20, 5, 20, 10, -2, 15, 20, 12, 10, 12, 20, 15], 0, 3, 1], [[7], True]],
  ['control 1', [[20, 15, 8, 8, -2, 8, -2, 30, 12, 30, 10], 10, 2, 1], [[2], False]],
  ['control 2', [[5, 12, 20, 0, 15, -2], 12, 4, 6], [[0, 1, 2, 3, 4, 5], True]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Fallback adds more slots than were needed.

Slots with price <= threshold form runs of consecutive slots; runs shorter than min_len are ignored to avoid contactor cycling. Slots of qualifying runs are taken chronologically until need_slots are chosen. If still short, the remaining cheapest unchosen slots (ties: earlier) are added regardless of runs and fallback is True. Return [sorted slots, fallback].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(chargers, vehicle, now):
    need, depart, max_ac, dc_ok = vehicle
    opts = []
    for cid, kw, free_at in chargers:
        if kw >= 22:
            if not dc_ok:
                continue
            pw = kw
        else:
            pw = min(kw, max_ac)
        start = max(now, free_at)
        finish = start + math.ceil(need * 60 / pw)
        opts.append([pw, finish, cid])
    if not opts:
        return None
    ok = [o for o in opts if o[1] <= depart]
    if ok:
        pw, finish, cid = min(ok)
        return [cid, finish, 'ok']
    pw, finish, cid = min(opts, key=lambda o: (o[1], o[2]))
    return [cid, finish, 'late']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 150, 10], [2, 22, 120], [3, 150, 30], [4, 3.7, 120]], [20, 111, 3.7, False], 6],
   [2, 445, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 0]], [45, 372, 7.4, False], 56], None],
  ['control 1', [[[1, 22, 60]], [5, 244, 11, False], 8], [1, 88, 'ok']],
  ['control 2', [[[1, 50, 0], [2, 50, 0]], [5, 160, 11, False], 39], None]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary', [[[1, 22, 120]], [20, 345, 3.7, True], 47],
   [1, 445, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 150, 0], [2, 7.4, 120], [3, 50, 0]], [20, 67, 11, True], 8], [3, 32, 'ok']],
  ['control 1', [[[1, 50, 0]], [45, 63, 7.4, True], 12], [1, 66, 'late']],
  ['control 2',
   [[[1, 7.4, 60], [2, 7.4, 10], [3, 22, 10], [4, 11, 120], [5, 50, 120]], [45, 353, 7.4, True],
    45],
   [5, 174, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 22, 10], [2, 3.7, 30]], [5, 408, 3.7, False], 55], [1, 137, 'ok']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 10]], [10, 99, 3.7, True], 41], [1, 53, 'ok']],
  ['control 1', [[[1, 7.4, 10], [2, 7.4, 0]], [45, 88, 7.4, True], 40], [1, 405, 'late']],
  ['control 2', [[[1, 3.7, 10], [2, 3.7, 120], [3, 11, 10], [4, 50, 0]], [5, 42, 7.4, True], 27],
   [4, 33, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 50, 0], [2, 7.4, 0], [3, 7.4, 120], [4, 22, 10]], [45, 278, 3.7, True], 26],
   [1, 80, 'ok']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 1', [[[1, 7.4, 60]], [30, 240, 3.7, True], 21], [1, 547, 'late']],
  ['control 2', [[[1, 3.7, 60], [2, 3.7, 120], [3, 150, 30], [4, 150, 0]], [45, 67, 11, False], 57],
   [1, 790, 'late']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 22, 0], [2, 3.7, 10], [3, 50, 30]], [20, 64, 3.7, False], 19], [1, 344, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 0], [2, 50, 30]], [10, 89, 7.4, True], 45], [1, 57, 'ok']],
  ['control 1', [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 2', [[[1, 150, 0], [2, 7.4, 10]], [10, 89, 3.7, True], 57], [1, 61, 'ok']]]]
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
import math
N = 1
observations = []
def solve(chargers, vehicle, now):
    need, depart, max_ac, dc_ok = vehicle
    opts = []
    for cid, kw, free_at in chargers:
        if kw > 50:
            if not dc_ok:
                continue
            pw = kw
        else:
            pw = min(kw, max_ac)
        start = max(now, free_at)
        finish = start + math.ceil(need * 60 / pw)
        opts.append([pw, finish, cid])
    if not opts:
        return None
    ok = [o for o in opts if o[1] <= depart]
    if ok:
        pw, finish, cid = min(ok)
        return [cid, finish, 'ok']
    pw, finish, cid = min(opts, key=lambda o: (o[1], o[2]))
    return [cid, finish, 'late']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 150, 10], [2, 22, 120], [3, 150, 30], [4, 3.7, 120]], [20, 111, 3.7, False], 6],
   [2, 445, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 0]], [45, 372, 7.4, False], 56], None],
  ['control 1', [[[1, 22, 60]], [5, 244, 11, False], 8], [1, 88, 'ok']],
  ['control 2', [[[1, 50, 0], [2, 50, 0]], [5, 160, 11, False], 39], None]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary', [[[1, 22, 120]], [20, 345, 3.7, True], 47],
   [1, 445, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 150, 0], [2, 7.4, 120], [3, 50, 0]], [20, 67, 11, True], 8], [3, 32, 'ok']],
  ['control 1', [[[1, 50, 0]], [45, 63, 7.4, True], 12], [1, 66, 'late']],
  ['control 2',
   [[[1, 7.4, 60], [2, 7.4, 10], [3, 22, 10], [4, 11, 120], [5, 50, 120]], [45, 353, 7.4, True],
    45],
   [5, 174, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 22, 10], [2, 3.7, 30]], [5, 408, 3.7, False], 55], [1, 137, 'ok']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 10]], [10, 99, 3.7, True], 41], [1, 53, 'ok']],
  ['control 1', [[[1, 7.4, 10], [2, 7.4, 0]], [45, 88, 7.4, True], 40], [1, 405, 'late']],
  ['control 2', [[[1, 3.7, 10], [2, 3.7, 120], [3, 11, 10], [4, 50, 0]], [5, 42, 7.4, True], 27],
   [4, 33, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 50, 0], [2, 7.4, 0], [3, 7.4, 120], [4, 22, 10]], [45, 278, 3.7, True], 26],
   [1, 80, 'ok']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 1', [[[1, 7.4, 60]], [30, 240, 3.7, True], 21], [1, 547, 'late']],
  ['control 2', [[[1, 3.7, 60], [2, 3.7, 120], [3, 150, 30], [4, 150, 0]], [45, 67, 11, False], 57],
   [1, 790, 'late']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: AC/DC classification boundary',
   [[[1, 22, 0], [2, 3.7, 10], [3, 50, 30]], [20, 64, 3.7, False], 19], [1, 344, 'late']],
  ['regression: AC/DC classification boundary (partial repair)',
   [[[1, 50, 0], [2, 50, 30]], [10, 89, 7.4, True], 45], [1, 57, 'ok']],
  ['control 1', [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 2', [[[1, 150, 0], [2, 7.4, 10]], [10, 89, 3.7, True], 57], [1, 61, 'ok']]]]
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:
22 kW AC points are skipped for vehicles without DC support.

chargers are [id, kw, free_at]; kw > 22 is DC (usable only if dc_ok, full kw), otherwise AC limited to the vehicle onboard max_ac. vehicle is [need_kwh, depart, max_ac, dc_ok]. Finish = max(now, free_at) + ceil(need*60/power) minutes. Among chargers finishing by depart pick the lowest power, then earliest finish, then id; otherwise the earliest finish (then id) with status 'late'. Return [id, finish, status] or None when no charger is usable.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(chargers, vehicle, now):
    need, depart, max_ac, dc_ok = vehicle
    opts = []
    for cid, kw, free_at in chargers:
        if kw > 22:
            if not dc_ok:
                continue
            pw = kw
        else:
            pw = kw
        start = max(now, free_at)
        finish = start + math.ceil(need * 60 / pw)
        opts.append([pw, finish, cid])
    if not opts:
        return None
    ok = [o for o in opts if o[1] <= depart]
    if ok:
        pw, finish, cid = min(ok)
        return [cid, finish, 'ok']
    pw, finish, cid = min(opts, key=lambda o: (o[1], o[2]))
    return [cid, finish, 'late']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 150, 10], [2, 22, 120], [3, 150, 30], [4, 3.7, 120]], [20, 111, 3.7, False], 6],
   [2, 445, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 0], [2, 7.4, 10]], [45, 104, 7.4, True], 19], [1, 37, 'ok']],
  ['control 1', [[[1, 22, 60]], [5, 244, 11, False], 8], [1, 88, 'ok']],
  ['control 2', [[[1, 50, 0], [2, 50, 0]], [5, 160, 11, False], 39], None]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit', [[[1, 22, 120]], [20, 345, 3.7, True], 47],
   [1, 445, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 0], [2, 7.4, 120], [3, 50, 0]], [20, 67, 11, True], 8], [3, 32, 'ok']],
  ['control 1', [[[1, 50, 0]], [45, 63, 7.4, True], 12], [1, 66, 'late']],
  ['control 2',
   [[[1, 7.4, 60], [2, 7.4, 10], [3, 22, 10], [4, 11, 120], [5, 50, 120]], [45, 353, 7.4, True],
    45],
   [5, 174, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 11, 60], [2, 150, 30], [3, 7.4, 0], [4, 3.7, 0], [5, 7.4, 60]], [10, 35, 3.7, False], 25],
   [3, 188, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 30], [2, 7.4, 60], [3, 22, 0]], [45, 136, 11, True], 41], [1, 59, 'ok']],
  ['control 1', [[[1, 7.4, 10], [2, 7.4, 0]], [45, 88, 7.4, True], 40], [1, 405, 'late']],
  ['control 2', [[[1, 3.7, 10], [2, 3.7, 120], [3, 11, 10], [4, 50, 0]], [5, 42, 7.4, True], 27],
   [4, 33, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 50, 0], [2, 7.4, 0], [3, 7.4, 120], [4, 22, 10]], [45, 278, 3.7, True], 26],
   [1, 80, 'ok']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 1', [[[1, 7.4, 60]], [30, 240, 3.7, True], 21], [1, 547, 'late']],
  ['control 2', [[[1, 3.7, 60], [2, 3.7, 120], [3, 150, 30], [4, 150, 0]], [45, 67, 11, False], 57],
   [1, 790, 'late']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 22, 0], [2, 3.7, 10], [3, 50, 30]], [20, 64, 3.7, False], 19], [1, 344, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 50, 0], [2, 50, 30]], [10, 89, 7.4, True], 45], [1, 57, 'ok']],
  ['control 1', [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 2', [[[1, 150, 0], [2, 7.4, 10]], [10, 89, 3.7, True], 57], [1, 61, 'ok']]]]
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
import math
N = 1
observations = []
def solve(chargers, vehicle, now):
    need, depart, max_ac, dc_ok = vehicle
    opts = []
    for cid, kw, free_at in chargers:
        if kw > 22:
            if not dc_ok:
                continue
            pw = min(kw, max_ac)
        else:
            pw = min(kw, max_ac)
        start = max(now, free_at)
        finish = start + math.ceil(need * 60 / pw)
        opts.append([pw, finish, cid])
    if not opts:
        return None
    ok = [o for o in opts if o[1] <= depart]
    if ok:
        pw, finish, cid = min(ok)
        return [cid, finish, 'ok']
    pw, finish, cid = min(opts, key=lambda o: (o[1], o[2]))
    return [cid, finish, 'late']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 150, 10], [2, 22, 120], [3, 150, 30], [4, 3.7, 120]], [20, 111, 3.7, False], 6],
   [2, 445, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 0], [2, 7.4, 10]], [45, 104, 7.4, True], 19], [1, 37, 'ok']],
  ['control 1', [[[1, 22, 60]], [5, 244, 11, False], 8], [1, 88, 'ok']],
  ['control 2', [[[1, 50, 0], [2, 50, 0]], [5, 160, 11, False], 39], None]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit', [[[1, 22, 120]], [20, 345, 3.7, True], 47],
   [1, 445, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 0], [2, 7.4, 120], [3, 50, 0]], [20, 67, 11, True], 8], [3, 32, 'ok']],
  ['control 1', [[[1, 50, 0]], [45, 63, 7.4, True], 12], [1, 66, 'late']],
  ['control 2',
   [[[1, 7.4, 60], [2, 7.4, 10], [3, 22, 10], [4, 11, 120], [5, 50, 120]], [45, 353, 7.4, True],
    45],
   [5, 174, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 11, 60], [2, 150, 30], [3, 7.4, 0], [4, 3.7, 0], [5, 7.4, 60]], [10, 35, 3.7, False], 25],
   [3, 188, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 150, 30], [2, 7.4, 60], [3, 22, 0]], [45, 136, 11, True], 41], [1, 59, 'ok']],
  ['control 1', [[[1, 7.4, 10], [2, 7.4, 0]], [45, 88, 7.4, True], 40], [1, 405, 'late']],
  ['control 2', [[[1, 3.7, 10], [2, 3.7, 120], [3, 11, 10], [4, 50, 0]], [5, 42, 7.4, True], 27],
   [4, 33, 'ok']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 50, 0], [2, 7.4, 0], [3, 7.4, 120], [4, 22, 10]], [45, 278, 3.7, True], 26],
   [1, 80, 'ok']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 1', [[[1, 7.4, 60]], [30, 240, 3.7, True], 21], [1, 547, 'late']],
  ['control 2', [[[1, 3.7, 60], [2, 3.7, 120], [3, 150, 30], [4, 150, 0]], [45, 67, 11, False], 57],
   [1, 790, 'late']]],
 [['boundary: 22 kW AC charger', [[[1, 22, 0]], [11, 300, 11, False], 0], [1, 60, 'ok']],
  ['boundary: finish exactly at departure', [[[1, 7.4, 0]], [37, 300, 7.4, True], 0],
   [1, 300, 'ok']],
  ['boundary: only DC and no DC support', [[[1, 50, 0]], [10, 100, 11, False], 0], None],
  ['regression: onboard AC charger limit',
   [[[1, 22, 0], [2, 3.7, 10], [3, 50, 30]], [20, 64, 3.7, False], 19], [1, 344, 'late']],
  ['regression: onboard AC charger limit (partial repair)',
   [[[1, 50, 0], [2, 50, 30]], [10, 89, 7.4, True], 45], [1, 57, 'ok']],
  ['control 1', [[[1, 50, 60], [2, 50, 60]], [45, 130, 7.4, True], 48], [1, 114, 'ok']],
  ['control 2', [[[1, 150, 0], [2, 7.4, 10]], [10, 89, 3.7, True], 57], [1, 61, 'ok']]]]
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:
Finish times on 22 kW AC points assume the car can take all 22 kW.

chargers are [id, kw, free_at]; kw > 22 is DC (usable only if dc_ok, full kw), otherwise AC limited to the vehicle onboard max_ac. vehicle is [need_kwh, depart, max_ac, dc_ok]. Finish = max(now, free_at) + ceil(need*60/power) minutes. Among chargers finishing by depart pick the lowest power, then earliest finish, then id; otherwise the earliest finish (then id) with status 'late'. Return [id, finish, status] or None when no charger is usable.

split: open-access