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

N = 1
observations = []
def solve(x):
    end = x['period_days'] if x['cancel'] is None else min(x['cancel'], x['period_days'])
    active = max(0, end - x['from'])
    flat = (x['flat'] * active * 2 + x['period_days']) // (2 * x['period_days'])
    usage = sum(q for d, q in x['events'] if x['from'] <= d <= end) * x['unit']
    return [flat, usage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'flat': 2900, 'period_days': 30, 'from': 8, 'cancel': 18, 'unit': 1, 'events': [[11, 351], [18, 145]]}, [967, 351]), ('regression', {'flat': 9900, 'period_days': 30, 'from': 7, 'cancel': None, 'unit': 5, 'events': [[19, 263], [24, 229], [30, 88]]}, [7590, 2460]), ('partial-repair probe', {'flat': 6972, 'period_days': 31, 'from': 29, 'cancel': 18, 'unit': 12, 'events': [[29, 170]]}, [0, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 2, 'cancel': 7, 'unit': 12, 'events': [[8, 9], [1, 189]]}, [1597, 0]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 15, 'cancel': None, 'unit': 5, 'events': [[26, 260], [12, 213]]}, [1450, 1300]), ('normal control', {'flat': 8044, 'period_days': 31, 'from': 14, 'cancel': None, 'unit': 5, 'events': []}, [4411, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 23, 'cancel': None, 'unit': 12, 'events': [[13, 491]]}, [748, 0]), ('normal control', {'flat': 12170, 'period_days': 30, 'from': 3, 'cancel': None, 'unit': 12, 'events': [[23, 155], [28, 348], [21, 236]]}, [10953, 8868])], [('regression', {'flat': 9900, 'period_days': 30, 'from': 1, 'cancel': 9, 'unit': 12, 'events': [[9, 406], [6, 191], [15, 110], [21, 170]]}, [2640, 2292]), ('regression', {'flat': 9900, 'period_days': 31, 'from': 28, 'cancel': None, 'unit': 1, 'events': [[5, 255], [31, 301], [34, 232], [32, 348], [31, 344]]}, [958, 0]), ('partial-repair probe', {'flat': 6064, 'period_days': 30, 'from': 12, 'cancel': 13, 'unit': 12, 'events': [[26, 133], [7, 193]]}, [202, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 20, 'cancel': 12, 'unit': 12, 'events': [[6, 157], [20, 102]]}, [0, 0]), ('normal control', {'flat': 7431, 'period_days': 31, 'from': 30, 'cancel': None, 'unit': 12, 'events': [[6, 380], [30, 5], [32, 257], [4, 247]]}, [240, 60]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 7, 'cancel': None, 'unit': 5, 'events': [[19, 421], [6, 32], [33, 481]]}, [2245, 2105]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 22, 'cancel': None, 'unit': 12, 'events': [[18, 186], [30, 275], [20, 173], [26, 168]]}, [2874, 5316]), ('normal control', {'flat': 11245, 'period_days': 30, 'from': 4, 'cancel': None, 'unit': 5, 'events': [[15, 26], [32, 318], [2, 320], [5, 358]]}, [9746, 1920])], [('regression', {'flat': 2900, 'period_days': 30, 'from': 9, 'cancel': 11, 'unit': 5, 'events': [[17, 146], [29, 419], [11, 274], [28, 178]]}, [193, 0]), ('regression', {'flat': 2900, 'period_days': 30, 'from': 17, 'cancel': None, 'unit': 1, 'events': [[30, 166], [13, 369]]}, [1257, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 4, 'cancel': 9, 'unit': 5, 'events': [[8, 43], [13, 477], [20, 415], [5, 98]]}, [1597, 705]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 3, 'cancel': 9, 'unit': 1, 'events': [[0, 290], [26, 36], [2, 484], [34, 261], [29, 328]]}, [1916, 0]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 26, 'cancel': None, 'unit': 5, 'events': [[15, 372], [6, 377], [28, 0]]}, [387, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 0, 'cancel': None, 'unit': 5, 'events': [[10, 43], [0, 320]]}, [2900, 1815]), ('normal control', {'flat': 9900, 'period_days': 30, 'from': 15, 'cancel': None, 'unit': 12, 'events': [[15, 259], [0, 271]]}, [4950, 3108]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 10, 'cancel': None, 'unit': 5, 'events': []}, [1933, 0])], [('regression', {'flat': 17089, 'period_days': 30, 'from': 29, 'cancel': 29, 'unit': 1, 'events': [[29, 410], [0, 480]]}, [0, 0]), ('regression', {'flat': 9900, 'period_days': 31, 'from': 15, 'cancel': None, 'unit': 1, 'events': [[31, 257], [10, 174]]}, [5110, 0]), ('partial-repair probe', {'flat': 8642, 'period_days': 31, 'from': 18, 'cancel': 7, 'unit': 1, 'events': [[29, 202], [34, 89], [6, 171], [22, 438]]}, [0, 0]), ('partial-repair probe', {'flat': 19412, 'period_days': 31, 'from': 20, 'cancel': 5, 'unit': 1, 'events': [[24, 31], [33, 70], [10, 181], [33, 416], [15, 11]]}, [0, 0]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 23, 'cancel': None, 'unit': 1, 'events': [[6, 153]]}, [2555, 0]), ('normal control', {'flat': 4788, 'period_days': 31, 'from': 25, 'cancel': None, 'unit': 1, 'events': [[15, 413]]}, [927, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 2, 'cancel': None, 'unit': 1, 'events': [[1, 283], [5, 461], [7, 359], [22, 264], [5, 31]]}, [2713, 1115]), ('normal control', {'flat': 7417, 'period_days': 30, 'from': 29, 'cancel': None, 'unit': 12, 'events': [[3, 477], [17, 75]]}, [247, 0])], [('regression', {'flat': 2900, 'period_days': 30, 'from': 8, 'cancel': 18, 'unit': 1, 'events': [[11, 351], [18, 145]]}, [967, 351]), ('regression', {'flat': 9900, 'period_days': 30, 'from': 26, 'cancel': None, 'unit': 12, 'events': [[2, 455], [30, 158], [31, 273], [22, 144], [5, 161]]}, [1320, 0]), ('partial-repair probe', {'flat': 11559, 'period_days': 31, 'from': 6, 'cancel': 11, 'unit': 12, 'events': [[8, 414], [26, 37], [7, 254], [0, 293], [32, 417]]}, [1864, 8016]), ('partial-repair probe', {'flat': 8700, 'period_days': 31, 'from': 23, 'cancel': 15, 'unit': 12, 'events': [[30, 500], [2, 445]]}, [0, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 14, 'cancel': None, 'unit': 12, 'events': [[17, 142], [9, 377]]}, [1590, 1704]), ('normal control', {'flat': 5810, 'period_days': 31, 'from': 30, 'cancel': None, 'unit': 12, 'events': [[34, 461], [26, 338], [10, 165], [21, 409], [28, 482]]}, [187, 0]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 6, 'cancel': None, 'unit': 1, 'events': [[16, 479], [10, 21], [5, 38], [25, 297], [6, 311]]}, [7984, 1108]), ('normal control', {'flat': 9900, 'period_days': 30, 'from': 13, 'cancel': None, 'unit': 5, 'events': [[10, 56]]}, [5610, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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(x):
    end = x['period_days'] if x['cancel'] is None else min(x['cancel'], x['period_days'])
    active = max(0, end - x['from'])
    flat = (x['flat'] * active * 2 + x['period_days']) // (2 * x['period_days'])
    usage = sum(q for d, q in x['events'] if x['from'] <= d < x['period_days']) * x['unit']
    return [flat, usage]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'flat': 2900, 'period_days': 30, 'from': 8, 'cancel': 18, 'unit': 1, 'events': [[11, 351], [18, 145]]}, [967, 351]), ('regression', {'flat': 9900, 'period_days': 30, 'from': 7, 'cancel': None, 'unit': 5, 'events': [[19, 263], [24, 229], [30, 88]]}, [7590, 2460]), ('partial-repair probe', {'flat': 6972, 'period_days': 31, 'from': 29, 'cancel': 18, 'unit': 12, 'events': [[29, 170]]}, [0, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 2, 'cancel': 7, 'unit': 12, 'events': [[8, 9], [1, 189]]}, [1597, 0]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 15, 'cancel': None, 'unit': 5, 'events': [[26, 260], [12, 213]]}, [1450, 1300]), ('normal control', {'flat': 8044, 'period_days': 31, 'from': 14, 'cancel': None, 'unit': 5, 'events': []}, [4411, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 23, 'cancel': None, 'unit': 12, 'events': [[13, 491]]}, [748, 0]), ('normal control', {'flat': 12170, 'period_days': 30, 'from': 3, 'cancel': None, 'unit': 12, 'events': [[23, 155], [28, 348], [21, 236]]}, [10953, 8868])], [('regression', {'flat': 9900, 'period_days': 30, 'from': 1, 'cancel': 9, 'unit': 12, 'events': [[9, 406], [6, 191], [15, 110], [21, 170]]}, [2640, 2292]), ('regression', {'flat': 9900, 'period_days': 31, 'from': 28, 'cancel': None, 'unit': 1, 'events': [[5, 255], [31, 301], [34, 232], [32, 348], [31, 344]]}, [958, 0]), ('partial-repair probe', {'flat': 6064, 'period_days': 30, 'from': 12, 'cancel': 13, 'unit': 12, 'events': [[26, 133], [7, 193]]}, [202, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 20, 'cancel': 12, 'unit': 12, 'events': [[6, 157], [20, 102]]}, [0, 0]), ('normal control', {'flat': 7431, 'period_days': 31, 'from': 30, 'cancel': None, 'unit': 12, 'events': [[6, 380], [30, 5], [32, 257], [4, 247]]}, [240, 60]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 7, 'cancel': None, 'unit': 5, 'events': [[19, 421], [6, 32], [33, 481]]}, [2245, 2105]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 22, 'cancel': None, 'unit': 12, 'events': [[18, 186], [30, 275], [20, 173], [26, 168]]}, [2874, 5316]), ('normal control', {'flat': 11245, 'period_days': 30, 'from': 4, 'cancel': None, 'unit': 5, 'events': [[15, 26], [32, 318], [2, 320], [5, 358]]}, [9746, 1920])], [('regression', {'flat': 2900, 'period_days': 30, 'from': 9, 'cancel': 11, 'unit': 5, 'events': [[17, 146], [29, 419], [11, 274], [28, 178]]}, [193, 0]), ('regression', {'flat': 2900, 'period_days': 30, 'from': 17, 'cancel': None, 'unit': 1, 'events': [[30, 166], [13, 369]]}, [1257, 0]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 4, 'cancel': 9, 'unit': 5, 'events': [[8, 43], [13, 477], [20, 415], [5, 98]]}, [1597, 705]), ('partial-repair probe', {'flat': 9900, 'period_days': 31, 'from': 3, 'cancel': 9, 'unit': 1, 'events': [[0, 290], [26, 36], [2, 484], [34, 261], [29, 328]]}, [1916, 0]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 26, 'cancel': None, 'unit': 5, 'events': [[15, 372], [6, 377], [28, 0]]}, [387, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 0, 'cancel': None, 'unit': 5, 'events': [[10, 43], [0, 320]]}, [2900, 1815]), ('normal control', {'flat': 9900, 'period_days': 30, 'from': 15, 'cancel': None, 'unit': 12, 'events': [[15, 259], [0, 271]]}, [4950, 3108]), ('normal control', {'flat': 2900, 'period_days': 30, 'from': 10, 'cancel': None, 'unit': 5, 'events': []}, [1933, 0])], [('regression', {'flat': 17089, 'period_days': 30, 'from': 29, 'cancel': 29, 'unit': 1, 'events': [[29, 410], [0, 480]]}, [0, 0]), ('regression', {'flat': 9900, 'period_days': 31, 'from': 15, 'cancel': None, 'unit': 1, 'events': [[31, 257], [10, 174]]}, [5110, 0]), ('partial-repair probe', {'flat': 8642, 'period_days': 31, 'from': 18, 'cancel': 7, 'unit': 1, 'events': [[29, 202], [34, 89], [6, 171], [22, 438]]}, [0, 0]), ('partial-repair probe', {'flat': 19412, 'period_days': 31, 'from': 20, 'cancel': 5, 'unit': 1, 'events': [[24, 31], [33, 70], [10, 181], [33, 416], [15, 11]]}, [0, 0]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 23, 'cancel': None, 'unit': 1, 'events': [[6, 153]]}, [2555, 0]), ('normal control', {'flat': 4788, 'period_days': 31, 'from': 25, 'cancel': None, 'unit': 1, 'events': [[15, 413]]}, [927, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 2, 'cancel': None, 'unit': 1, 'events': [[1, 283], [5, 461], [7, 359], [22, 264], [5, 31]]}, [2713, 1115]), ('normal control', {'flat': 7417, 'period_days': 30, 'from': 29, 'cancel': None, 'unit': 12, 'events': [[3, 477], [17, 75]]}, [247, 0])], [('regression', {'flat': 2900, 'period_days': 30, 'from': 8, 'cancel': 18, 'unit': 1, 'events': [[11, 351], [18, 145]]}, [967, 351]), ('regression', {'flat': 9900, 'period_days': 30, 'from': 26, 'cancel': None, 'unit': 12, 'events': [[2, 455], [30, 158], [31, 273], [22, 144], [5, 161]]}, [1320, 0]), ('partial-repair probe', {'flat': 11559, 'period_days': 31, 'from': 6, 'cancel': 11, 'unit': 12, 'events': [[8, 414], [26, 37], [7, 254], [0, 293], [32, 417]]}, [1864, 8016]), ('partial-repair probe', {'flat': 8700, 'period_days': 31, 'from': 23, 'cancel': 15, 'unit': 12, 'events': [[30, 500], [2, 445]]}, [0, 0]), ('normal control', {'flat': 2900, 'period_days': 31, 'from': 14, 'cancel': None, 'unit': 12, 'events': [[17, 142], [9, 377]]}, [1590, 1704]), ('normal control', {'flat': 5810, 'period_days': 31, 'from': 30, 'cancel': None, 'unit': 12, 'events': [[34, 461], [26, 338], [10, 165], [21, 409], [28, 482]]}, [187, 0]), ('normal control', {'flat': 9900, 'period_days': 31, 'from': 6, 'cancel': None, 'unit': 1, 'events': [[16, 479], [10, 21], [5, 38], [25, 297], [6, 311]]}, [7984, 1108]), ('normal control', {'flat': 9900, 'period_days': 30, 'from': 13, 'cancel': None, 'unit': 5, 'events': [[10, 56]]}, [5610, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Usage recorded on the cancellation day is billed after cancellation.

Input {flat, period_days, from, cancel|None, unit, events: [[day, qty]]}. Active window is [from, end) with end = min(cancel, period_days) or period_days. The flat fee is prorated by active days half-up; usage is not prorated: every event inside the window is billed qty*unit. Return [flat_charge, usage_charge].

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Cancellations scheduled after period end over-charge the flat fee beyond one period.

Input {flat, period_days, from, cancel|None, unit, events: [[day, qty]]}. Active window is [from, end) with end = min(cancel, period_days) or period_days. The flat fee is prorated by active days half-up; usage is not prorated: every event inside the window is billed qty*unit. Return [flat_charge, usage_charge].

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['new'] > x['cur']:
        ch = ((x['new'] - x['cur']) * x['left'] * 2 + x['period']) // (2 * x['period'])
        return [ch, x['new'], x['pending']]
    if x['new'] < x['cur']:
        return [0, x['cur'], x['new']]
    return [0, x['cur'], None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('normal control', {'cur': 5000, 'new': 7500, 'left': 20, 'period': 30, 'pending': None}, [1667, 7500, None]), ('normal control', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 28, 'period': 31, 'pending': 500}, [0, 5000, 1000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 16, 'period': 31, 'pending': 2000}, [2065, 5000, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 21, 'period': 31, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 220, 'period': 365, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 26, 'period': 31, 'pending': 1000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None])], [('regression', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 231, 'period': 365, 'pending': 2000}, [633, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 41, 'period': 365, 'pending': 2000}, [730, 7500, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 13, 'period': 30, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 14, 'period': 30, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 16, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 1, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 1000, 'new': 5000, 'left': 16, 'period': 31, 'pending': 2000}, [2065, 5000, None]), ('regression', {'cur': 1000, 'new': 5000, 'left': 29, 'period': 30, 'pending': 1000}, [3867, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 0, 'period': 30, 'pending': 2000}, [0, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 282, 'period': 365, 'pending': 2000}, [5022, 7500, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 30, 'period': 30, 'pending': 1000}, [0, 5000, 2000]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 139, 'period': 365, 'pending': None}, [1142, 5000, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 15, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 231, 'period': 365, 'pending': 2000}, [633, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 339, 'period': 365, 'pending': 2000}, [929, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 181, 'period': 365, 'pending': 2000}, [3223, 7500, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 252, 'period': 365, 'pending': 500}, [0, 2000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 20, 'period': 31, 'pending': 2000}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 24, 'period': 31, 'pending': None}, [0, 5000, None])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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(x):
    if x['new'] > x['cur']:
        ch = ((x['new'] - x['cur']) * x['left'] * 2 + x['period']) // (2 * x['period'])
        return [ch, x['new'], x['pending'] if x['pending'] and x['pending'] > x['cur'] else None]
    if x['new'] < x['cur']:
        return [0, x['cur'], x['new']]
    return [0, x['cur'], None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('normal control', {'cur': 5000, 'new': 7500, 'left': 20, 'period': 30, 'pending': None}, [1667, 7500, None]), ('normal control', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 28, 'period': 31, 'pending': 500}, [0, 5000, 1000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 16, 'period': 31, 'pending': 2000}, [2065, 5000, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 21, 'period': 31, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 220, 'period': 365, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 26, 'period': 31, 'pending': 1000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None])], [('regression', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 231, 'period': 365, 'pending': 2000}, [633, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 41, 'period': 365, 'pending': 2000}, [730, 7500, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 13, 'period': 30, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 14, 'period': 30, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 16, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 1, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 1000, 'new': 5000, 'left': 16, 'period': 31, 'pending': 2000}, [2065, 5000, None]), ('regression', {'cur': 1000, 'new': 5000, 'left': 29, 'period': 30, 'pending': 1000}, [3867, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 0, 'period': 30, 'pending': 2000}, [0, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 282, 'period': 365, 'pending': 2000}, [5022, 7500, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 30, 'period': 30, 'pending': 1000}, [0, 5000, 2000]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 5000, 'left': 139, 'period': 365, 'pending': None}, [1142, 5000, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 15, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 231, 'period': 365, 'pending': 2000}, [633, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 339, 'period': 365, 'pending': 2000}, [929, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 7500, 'left': 181, 'period': 365, 'pending': 2000}, [3223, 7500, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 252, 'period': 365, 'pending': 500}, [0, 2000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 20, 'period': 31, 'pending': 2000}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 24, 'period': 31, 'pending': None}, [0, 5000, None])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Customers who upgrade are later silently downgraded by an old scheduled change.

Input {cur, new, left, period, pending scheduled price|None}. Upgrade (new > cur): charge (new-cur)*left/period half-up now, switch immediately and clear any scheduled change. Downgrade: no charge, keep cur, schedule new (replacing any pending). Same price: no charge and clear the schedule. Return [charge, active_price, scheduled].

split: open-access


prompt:
Downgrades take effect immediately without credit, cutting service mid-period.

Input {cur, new, left, period, pending scheduled price|None}. Upgrade (new > cur): charge (new-cur)*left/period half-up now, switch immediately and clear any scheduled change. Downgrade: no charge, keep cur, schedule new (replacing any pending). Same price: no charge and clear the schedule. Return [charge, active_price, scheduled].

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['new'] > x['cur']:
        ch = (x['new'] * x['left'] * 2 + x['period']) // (2 * x['period'])
        return [ch, x['new'], None]
    if x['new'] < x['cur']:
        return [0, x['cur'], x['new']]
    return [0, x['cur'], None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'cur': 5000, 'new': 7500, 'left': 20, 'period': 30, 'pending': None}, [1667, 7500, None]), ('regression', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 28, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 21, 'period': 31, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 220, 'period': 365, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 26, 'period': 31, 'pending': 1000}, [0, 5000, None])], [('regression', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('regression', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 13, 'period': 30, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 14, 'period': 30, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 16, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 1, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('regression', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 30, 'period': 30, 'pending': 1000}, [0, 5000, 2000]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 15, 'period': 31, 'pending': 1000}, [0, 2000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 252, 'period': 365, 'pending': 500}, [0, 2000, 1000])], [('regression', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 29, 'period': 30, 'pending': 1000}, [3867, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 20, 'period': 31, 'pending': 2000}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 24, 'period': 31, 'pending': None}, [0, 5000, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 11, 'period': 31, 'pending': 500}, [0, 5000, 2000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 139, 'period': 365, 'pending': None}, [1142, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 21, 'period': 30, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 24, 'period': 30, 'pending': 1000}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 328, 'period': 365, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 201, 'period': 365, 'pending': None}, [0, 1000, None])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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(x):
    if x['new'] > x['cur']:
        ch = ((x['new'] - x['cur']) * (x['period'] - x['left']) * 2 + x['period']) // (2 * x['period'])
        return [ch, x['new'], None]
    if x['new'] < x['cur']:
        return [0, x['cur'], x['new']]
    return [0, x['cur'], None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'cur': 5000, 'new': 7500, 'left': 20, 'period': 30, 'pending': None}, [1667, 7500, None]), ('regression', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 28, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 21, 'period': 31, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 220, 'period': 365, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 26, 'period': 31, 'pending': 1000}, [0, 5000, None])], [('regression', {'cur': 5000, 'new': 7500, 'left': 5, 'period': 30, 'pending': None}, [417, 7500, None]), ('regression', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 13, 'period': 30, 'pending': None}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 14, 'period': 30, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 16, 'period': 31, 'pending': 500}, [0, 5000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 1, 'period': 31, 'pending': 1000}, [0, 2000, 1000])], [('regression', {'cur': 2000, 'new': 5000, 'left': 21, 'period': 30, 'pending': None}, [2100, 5000, None]), ('regression', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 30, 'period': 30, 'pending': 1000}, [0, 5000, 2000]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, None]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 15, 'period': 31, 'pending': 1000}, [0, 2000, 1000]), ('normal control', {'cur': 2000, 'new': 1000, 'left': 252, 'period': 365, 'pending': 500}, [0, 2000, 1000])], [('regression', {'cur': 2000, 'new': 5000, 'left': 24, 'period': 30, 'pending': None}, [2400, 5000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 1, 'period': 30, 'pending': 2000}, [33, 2000, None]), ('partial-repair probe', {'cur': 1000, 'new': 5000, 'left': 29, 'period': 30, 'pending': 1000}, [3867, 5000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 25, 'period': 31, 'pending': 2000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 20, 'period': 31, 'pending': 2000}, [0, 1000, None]), ('normal control', {'cur': 5000, 'new': 5000, 'left': 24, 'period': 31, 'pending': None}, [0, 5000, None]), ('normal control', {'cur': 5000, 'new': 2000, 'left': 11, 'period': 31, 'pending': 500}, [0, 5000, 2000])], [('regression', {'cur': 1000, 'new': 2000, 'left': 17, 'period': 30, 'pending': 2000}, [567, 2000, None]), ('regression', {'cur': 1000, 'new': 2000, 'left': 272, 'period': 365, 'pending': 500}, [745, 2000, None]), ('partial-repair probe', {'cur': 2000, 'new': 5000, 'left': 139, 'period': 365, 'pending': None}, [1142, 5000, None]), ('partial-repair probe', {'cur': 1000, 'new': 2000, 'left': 39, 'period': 365, 'pending': 2000}, [107, 2000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 21, 'period': 30, 'pending': None}, [0, 2000, None]), ('normal control', {'cur': 2000, 'new': 2000, 'left': 24, 'period': 30, 'pending': 1000}, [0, 2000, None]), ('normal control', {'cur': 5000, 'new': 1000, 'left': 328, 'period': 365, 'pending': 1000}, [0, 5000, 1000]), ('normal control', {'cur': 1000, 'new': 1000, 'left': 201, 'period': 365, 'pending': None}, [0, 1000, None])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Upgrades charge the full new price for remaining days with no credit for the old plan.

Input {cur, new, left, period, pending scheduled price|None}. Upgrade (new > cur): charge (new-cur)*left/period half-up now, switch immediately and clear any scheduled change. Downgrade: no charge, keep cur, schedule new (replacing any pending). Same price: no charge and clear the schedule. Return [charge, active_price, scheduled].

split: open-access


prompt:
Customers adding seats across a tier boundary keep the old tier's discount.

Input {unit, old, new quantities, tiers: ascending [[min_qty, pct_off]], left, period}. A quantity's discount is the pct of the last tier with qty >= min_qty and applies to all units: total(q) = q*unit*(100-pct) in cent-percent. Proration of q = total(q)*left/(100*period) half-up. Return [-proration(old), proration(new)].

split: open-access


prompt:
Buying exactly the tier minimum does not unlock the discount.

Input {unit, old, new quantities, tiers: ascending [[min_qty, pct_off]], left, period}. A quantity's discount is the pct of the last tier with qty >= min_qty and applies to all units: total(q) = q*unit*(100-pct) in cent-percent. Proration of q = total(q)*left/(100*period) half-up. Return [-proration(old), proration(new)].

split: open-access


prompt:
Discounted prorations drift by cents proportional to the quantity.

Input {unit, old, new quantities, tiers: ascending [[min_qty, pct_off]], left, period}. A quantity's discount is the pct of the last tier with qty >= min_qty and applies to all units: total(q) = q*unit*(100-pct) in cent-percent. Proration of q = total(q)*left/(100*period) half-up. Return [-proration(old), proration(new)].

split: open-access


prompt:
Periods with a phase change are charged for both phases on the overlapping days.

Input {ps, pe (exclusive), phases: [[start_day, price per full period]]}. Phases are ordered by start; each lasts until the next phase starts (the last until pe). The period charge is sum(price * overlap days with [ps, pe)) / (pe - ps), rounded half-up once. Return cents.

split: open-access


prompt:
Phases that started before the period charge for days in the previous period.

Input {ps, pe (exclusive), phases: [[start_day, price per full period]]}. Phases are ordered by start; each lasts until the next phase starts (the last until pe). The period charge is sum(price * overlap days with [ps, pe)) / (pe - ps), rounded half-up once. Return cents.

split: open-access


prompt:
Schedules entered out of order produce wrong phase boundaries.

Input {ps, pe (exclusive), phases: [[start_day, price per full period]]}. Phases are ordered by start; each lasts until the next phase starts (the last until pe). The period charge is sum(price * overlap days with [ps, pe)) / (pe - ps), rounded half-up once. Return cents.

split: open-access


prompt:
Multi-phase periods are a cent off the exact prorated total.

Input {ps, pe (exclusive), phases: [[start_day, price per full period]]}. Phases are ordered by start; each lasts until the next phase starts (the last until pe). The period charge is sum(price * overlap days with [ps, pe)) / (pe - ps), rounded half-up once. Return cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * x['count'] * k)
        months = k * x['count'] * (12 if x['interval'] == 'year' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k + 1) < t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('partial-repair probe', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('partial-repair probe', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('additional oracle', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])], [('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('partial-repair probe', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19']), ('partial-repair probe', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29'])], [('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('partial-repair probe', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('partial-repair probe', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29'])], [('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('regression', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('partial-repair probe', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31'])], [('regression', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('regression', {'anchor': [2020, 7, 31], 'interval': 'month', 'count': 1, 'at': [2023, 5, 31]}, ['2023-05-31', '2023-06-30']), ('partial-repair probe', {'anchor': [2023, 12, 31], 'interval': 'month', 'count': 1, 'at': [2024, 7, 11]}, ['2024-06-30', '2024-07-31']), ('partial-repair probe', {'anchor': [2020, 2, 20], 'interval': 'month', 'count': 1, 'at': [2022, 12, 10]}, ['2022-11-20', '2022-12-20']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('additional oracle', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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 datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * x['count'] * k)
        months = k * x['count'] * (12 if x['interval'] == 'year' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k) < t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('partial-repair probe', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('partial-repair probe', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('additional oracle', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])], [('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('partial-repair probe', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19']), ('partial-repair probe', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29'])], [('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('partial-repair probe', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('partial-repair probe', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29'])], [('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('regression', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('partial-repair probe', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31'])], [('regression', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('regression', {'anchor': [2020, 7, 31], 'interval': 'month', 'count': 1, 'at': [2023, 5, 31]}, ['2023-05-31', '2023-06-30']), ('partial-repair probe', {'anchor': [2023, 12, 31], 'interval': 'month', 'count': 1, 'at': [2024, 7, 11]}, ['2024-06-30', '2024-07-31']), ('partial-repair probe', {'anchor': [2020, 2, 20], 'interval': 'month', 'count': 1, 'at': [2022, 12, 10]}, ['2022-11-20', '2022-12-20']), ('normal control', {'anchor': [2020, 1, 1], 'interval': 'week', 'count': 2, 'at': [2020, 1, 1]}, ['2020-01-01', '2020-01-15']), ('additional oracle', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('additional oracle', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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 change on a renewal date is prorated against the period that just ended.

Input {anchor, interval week|month|year, count, at >= anchor}. Period k starts at anchor + k*count intervals (weeks as 7 days; months/years by calendar month with the anchor day clamped to month length). Return [start ISO, end ISO] of the period with start <= at < end.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * x['count'] * k)
        months = k * x['count'] * (12 if x['interval'] == 'month' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k + 1) <= t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('regression (boundary)', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('partial-repair probe', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('normal control', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('normal control', {'anchor': [2021, 8, 15], 'interval': 'week', 'count': 1, 'at': [2024, 10, 23]}, ['2024-10-20', '2024-10-27']), ('normal control', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16'])], [('regression', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('regression', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('partial-repair probe', {'anchor': [2023, 3, 31], 'interval': 'year', 'count': 3, 'at': [2024, 8, 8]}, ['2023-03-31', '2026-03-31']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2021, 5, 20], 'interval': 'week', 'count': 1, 'at': [2022, 8, 31]}, ['2022-08-25', '2022-09-01']), ('normal control', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('normal control', {'anchor': [2020, 4, 24], 'interval': 'week', 'count': 1, 'at': [2021, 1, 14]}, ['2021-01-08', '2021-01-15']), ('normal control', {'anchor': [2020, 4, 15], 'interval': 'week', 'count': 1, 'at': [2022, 5, 12]}, ['2022-05-11', '2022-05-18'])], [('regression', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('regression', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('partial-repair probe', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 3, 'at': [2021, 12, 24]}, ['2021-09-30', '2024-09-30']), ('partial-repair probe', {'anchor': [2021, 6, 30], 'interval': 'year', 'count': 3, 'at': [2022, 7, 26]}, ['2021-06-30', '2024-06-30']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2021, 3, 2], 'interval': 'week', 'count': 1, 'at': [2023, 4, 10]}, ['2023-04-04', '2023-04-11']), ('normal control', {'anchor': [2023, 4, 28], 'interval': 'week', 'count': 1, 'at': [2024, 7, 31]}, ['2024-07-26', '2024-08-02']), ('normal control', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('normal control', {'anchor': [2020, 2, 8], 'interval': 'week', 'count': 1, 'at': [2021, 4, 15]}, ['2021-04-10', '2021-04-17'])], [('regression', {'anchor': [2023, 3, 31], 'interval': 'year', 'count': 3, 'at': [2024, 8, 8]}, ['2023-03-31', '2026-03-31']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('partial-repair probe', {'anchor': [2023, 12, 31], 'interval': 'year', 'count': 3, 'at': [2026, 4, 8]}, ['2023-12-31', '2026-12-31']), ('partial-repair probe', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 2, 'at': [2023, 8, 3]}, ['2021-09-30', '2023-09-30']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('normal control', {'anchor': [2022, 2, 27], 'interval': 'week', 'count': 1, 'at': [2023, 11, 19]}, ['2023-11-19', '2023-11-26']), ('normal control', {'anchor': [2021, 8, 13], 'interval': 'week', 'count': 1, 'at': [2023, 3, 26]}, ['2023-03-24', '2023-03-31']), ('normal control', {'anchor': [2021, 1, 2], 'interval': 'week', 'count': 2, 'at': [2021, 7, 13]}, ['2021-07-03', '2021-07-17'])], [('regression', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 3, 'at': [2021, 12, 24]}, ['2021-09-30', '2024-09-30']), ('regression', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19']), ('partial-repair probe', {'anchor': [2022, 9, 30], 'interval': 'year', 'count': 3, 'at': [2023, 10, 5]}, ['2022-09-30', '2025-09-30']), ('partial-repair probe', {'anchor': [2022, 4, 19], 'interval': 'year', 'count': 3, 'at': [2023, 9, 9]}, ['2022-04-19', '2025-04-19']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 12, 19], 'interval': 'week', 'count': 1, 'at': [2024, 3, 2]}, ['2024-03-02', '2024-03-09']), ('normal control', {'anchor': [2023, 11, 16], 'interval': 'week', 'count': 1, 'at': [2024, 1, 17]}, ['2024-01-11', '2024-01-18']), ('normal control', {'anchor': [2021, 2, 1], 'interval': 'week', 'count': 2, 'at': [2022, 4, 22]}, ['2022-04-11', '2022-04-25']), ('normal control', {'anchor': [2020, 4, 6], 'interval': 'week', 'count': 1, 'at': [2023, 1, 27]}, ['2023-01-23', '2023-01-30'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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 datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * x['count'] * k)
        months = k * x['count'] * (12 * x['count'] if x['interval'] == 'year' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k + 1) <= t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('regression (boundary)', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('partial-repair probe', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('normal control', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('normal control', {'anchor': [2021, 8, 15], 'interval': 'week', 'count': 1, 'at': [2024, 10, 23]}, ['2024-10-20', '2024-10-27']), ('normal control', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16'])], [('regression', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('regression', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('partial-repair probe', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('partial-repair probe', {'anchor': [2023, 3, 31], 'interval': 'year', 'count': 3, 'at': [2024, 8, 8]}, ['2023-03-31', '2026-03-31']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2021, 5, 20], 'interval': 'week', 'count': 1, 'at': [2022, 8, 31]}, ['2022-08-25', '2022-09-01']), ('normal control', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('normal control', {'anchor': [2020, 4, 24], 'interval': 'week', 'count': 1, 'at': [2021, 1, 14]}, ['2021-01-08', '2021-01-15']), ('normal control', {'anchor': [2020, 4, 15], 'interval': 'week', 'count': 1, 'at': [2022, 5, 12]}, ['2022-05-11', '2022-05-18'])], [('regression', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('regression', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('partial-repair probe', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 3, 'at': [2021, 12, 24]}, ['2021-09-30', '2024-09-30']), ('partial-repair probe', {'anchor': [2021, 6, 30], 'interval': 'year', 'count': 3, 'at': [2022, 7, 26]}, ['2021-06-30', '2024-06-30']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2021, 3, 2], 'interval': 'week', 'count': 1, 'at': [2023, 4, 10]}, ['2023-04-04', '2023-04-11']), ('normal control', {'anchor': [2023, 4, 28], 'interval': 'week', 'count': 1, 'at': [2024, 7, 31]}, ['2024-07-26', '2024-08-02']), ('normal control', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('normal control', {'anchor': [2020, 2, 8], 'interval': 'week', 'count': 1, 'at': [2021, 4, 15]}, ['2021-04-10', '2021-04-17'])], [('regression', {'anchor': [2023, 3, 31], 'interval': 'year', 'count': 3, 'at': [2024, 8, 8]}, ['2023-03-31', '2026-03-31']), ('regression', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('partial-repair probe', {'anchor': [2023, 12, 31], 'interval': 'year', 'count': 3, 'at': [2026, 4, 8]}, ['2023-12-31', '2026-12-31']), ('partial-repair probe', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 2, 'at': [2023, 8, 3]}, ['2021-09-30', '2023-09-30']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('normal control', {'anchor': [2022, 2, 27], 'interval': 'week', 'count': 1, 'at': [2023, 11, 19]}, ['2023-11-19', '2023-11-26']), ('normal control', {'anchor': [2021, 8, 13], 'interval': 'week', 'count': 1, 'at': [2023, 3, 26]}, ['2023-03-24', '2023-03-31']), ('normal control', {'anchor': [2021, 1, 2], 'interval': 'week', 'count': 2, 'at': [2021, 7, 13]}, ['2021-07-03', '2021-07-17'])], [('regression', {'anchor': [2021, 9, 30], 'interval': 'year', 'count': 3, 'at': [2021, 12, 24]}, ['2021-09-30', '2024-09-30']), ('regression', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19']), ('partial-repair probe', {'anchor': [2022, 9, 30], 'interval': 'year', 'count': 3, 'at': [2023, 10, 5]}, ['2022-09-30', '2025-09-30']), ('partial-repair probe', {'anchor': [2022, 4, 19], 'interval': 'year', 'count': 3, 'at': [2023, 9, 9]}, ['2022-04-19', '2025-04-19']), ('boundary control', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('normal control', {'anchor': [2020, 12, 19], 'interval': 'week', 'count': 1, 'at': [2024, 3, 2]}, ['2024-03-02', '2024-03-09']), ('normal control', {'anchor': [2023, 11, 16], 'interval': 'week', 'count': 1, 'at': [2024, 1, 17]}, ['2024-01-11', '2024-01-18']), ('normal control', {'anchor': [2021, 2, 1], 'interval': 'week', 'count': 2, 'at': [2022, 4, 22]}, ['2022-04-11', '2022-04-25']), ('normal control', {'anchor': [2020, 4, 6], 'interval': 'week', 'count': 1, 'at': [2023, 1, 27]}, ['2023-01-23', '2023-01-30'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Yearly plans roll over monthly and monthly plans yearly.

Input {anchor, interval week|month|year, count, at >= anchor}. Period k starts at anchor + k*count intervals (weeks as 7 days; months/years by calendar month with the anchor day clamped to month length). Return [start ISO, end ISO] of the period with start <= at < end.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * k)
        months = k * x['count'] * (12 if x['interval'] == 'year' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k + 1) <= t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('regression', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('partial-repair probe', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('partial-repair probe', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('normal control', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('normal control', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('normal control', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])], [('regression', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('regression', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('partial-repair probe', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('partial-repair probe', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('normal control', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('normal control', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('normal control', {'anchor': [2023, 12, 31], 'interval': 'month', 'count': 1, 'at': [2024, 7, 11]}, ['2024-06-30', '2024-07-31'])], [('regression', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('regression', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('partial-repair probe', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('partial-repair probe', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2020, 2, 20], 'interval': 'month', 'count': 1, 'at': [2022, 12, 10]}, ['2022-11-20', '2022-12-20']), ('normal control', {'anchor': [2021, 8, 15], 'interval': 'week', 'count': 1, 'at': [2024, 10, 23]}, ['2024-10-20', '2024-10-27']), ('normal control', {'anchor': [2023, 3, 14], 'interval': 'month', 'count': 3, 'at': [2026, 4, 3]}, ['2026-03-14', '2026-06-14']), ('normal control', {'anchor': [2021, 8, 31], 'interval': 'year', 'count': 1, 'at': [2022, 7, 27]}, ['2021-08-31', '2022-08-31'])], [('regression', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('regression', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('partial-repair probe', {'anchor': [2021, 1, 2], 'interval': 'week', 'count': 2, 'at': [2021, 7, 13]}, ['2021-07-03', '2021-07-17']), ('partial-repair probe', {'anchor': [2021, 2, 1], 'interval': 'week', 'count': 2, 'at': [2022, 4, 22]}, ['2022-04-11', '2022-04-25']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('normal control', {'anchor': [2021, 5, 20], 'interval': 'week', 'count': 1, 'at': [2022, 8, 31]}, ['2022-08-25', '2022-09-01']), ('normal control', {'anchor': [2022, 6, 30], 'interval': 'month', 'count': 1, 'at': [2023, 6, 1]}, ['2023-05-30', '2023-06-30']), ('normal control', {'anchor': [2022, 12, 6], 'interval': 'month', 'count': 1, 'at': [2025, 6, 30]}, ['2025-06-06', '2025-07-06'])], [('regression', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('regression', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('partial-repair probe', {'anchor': [2020, 12, 28], 'interval': 'week', 'count': 2, 'at': [2021, 6, 22]}, ['2021-06-14', '2021-06-28']), ('partial-repair probe', {'anchor': [2023, 12, 20], 'interval': 'week', 'count': 3, 'at': [2026, 5, 31]}, ['2026-05-20', '2026-06-10']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('normal control', {'anchor': [2021, 4, 30], 'interval': 'month', 'count': 1, 'at': [2023, 4, 25]}, ['2023-03-30', '2023-04-30']), ('normal control', {'anchor': [2020, 4, 24], 'interval': 'week', 'count': 1, 'at': [2021, 1, 14]}, ['2021-01-08', '2021-01-15']), ('normal control', {'anchor': [2021, 7, 13], 'interval': 'year', 'count': 1, 'at': [2021, 11, 5]}, ['2021-07-13', '2022-07-13'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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 datetime
import calendar
N = 1
observations = []
def solve(x):
    a = datetime.date(*x['anchor'])
    t = datetime.date(*x['at'])
    def shift(k):
        if x['interval'] == 'week':
            return a + datetime.timedelta(days=7 * (x['count'] + k - 1))
        months = k * x['count'] * (12 if x['interval'] == 'year' else 1)
        tot = a.month - 1 + months
        y, m = a.year + tot // 12, tot % 12 + 1
        return datetime.date(y, m, min(a.day, calendar.monthrange(y, m)[1]))
    k = 0
    while shift(k + 1) <= t:
        k += 1
    return [shift(k).isoformat(), shift(k + 1).isoformat()]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2024, 1, 10], 'interval': 'week', 'count': 2, 'at': [2024, 1, 24]}, ['2024-01-24', '2024-02-07']), ('regression', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('partial-repair probe', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('partial-repair probe', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2020, 10, 31], 'interval': 'year', 'count': 1, 'at': [2022, 2, 15]}, ['2021-10-31', '2022-10-31']), ('normal control', {'anchor': [2023, 10, 31], 'interval': 'month', 'count': 2, 'at': [2024, 2, 3]}, ['2023-12-31', '2024-02-29']), ('normal control', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 2, 'at': [2023, 6, 30]}, ['2023-06-30', '2023-08-31']), ('normal control', {'anchor': [2023, 5, 19], 'interval': 'year', 'count': 1, 'at': [2025, 8, 18]}, ['2025-05-19', '2026-05-19'])], [('regression', {'anchor': [2020, 8, 2], 'interval': 'week', 'count': 3, 'at': [2020, 9, 4]}, ['2020-08-23', '2020-09-13']), ('regression', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('partial-repair probe', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('partial-repair probe', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2021, 11, 24], 'interval': 'year', 'count': 3, 'at': [2022, 4, 18]}, ['2021-11-24', '2024-11-24']), ('normal control', {'anchor': [2021, 2, 28], 'interval': 'year', 'count': 2, 'at': [2021, 8, 29]}, ['2021-02-28', '2023-02-28']), ('normal control', {'anchor': [2020, 11, 28], 'interval': 'year', 'count': 2, 'at': [2023, 9, 6]}, ['2022-11-28', '2024-11-28']), ('normal control', {'anchor': [2023, 12, 31], 'interval': 'month', 'count': 1, 'at': [2024, 7, 11]}, ['2024-06-30', '2024-07-31'])], [('regression', {'anchor': [2020, 8, 7], 'interval': 'week', 'count': 2, 'at': [2023, 10, 30]}, ['2023-10-27', '2023-11-10']), ('regression', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('partial-repair probe', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('partial-repair probe', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2020, 2, 20], 'interval': 'month', 'count': 1, 'at': [2022, 12, 10]}, ['2022-11-20', '2022-12-20']), ('normal control', {'anchor': [2021, 8, 15], 'interval': 'week', 'count': 1, 'at': [2024, 10, 23]}, ['2024-10-20', '2024-10-27']), ('normal control', {'anchor': [2023, 3, 14], 'interval': 'month', 'count': 3, 'at': [2026, 4, 3]}, ['2026-03-14', '2026-06-14']), ('normal control', {'anchor': [2021, 8, 31], 'interval': 'year', 'count': 1, 'at': [2022, 7, 27]}, ['2021-08-31', '2022-08-31'])], [('regression', {'anchor': [2020, 11, 21], 'interval': 'week', 'count': 2, 'at': [2022, 7, 12]}, ['2022-07-02', '2022-07-16']), ('regression', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('partial-repair probe', {'anchor': [2021, 1, 2], 'interval': 'week', 'count': 2, 'at': [2021, 7, 13]}, ['2021-07-03', '2021-07-17']), ('partial-repair probe', {'anchor': [2021, 2, 1], 'interval': 'week', 'count': 2, 'at': [2022, 4, 22]}, ['2022-04-11', '2022-04-25']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2022, 10, 31], 'interval': 'month', 'count': 1, 'at': [2023, 11, 30]}, ['2023-11-30', '2023-12-31']), ('normal control', {'anchor': [2021, 5, 20], 'interval': 'week', 'count': 1, 'at': [2022, 8, 31]}, ['2022-08-25', '2022-09-01']), ('normal control', {'anchor': [2022, 6, 30], 'interval': 'month', 'count': 1, 'at': [2023, 6, 1]}, ['2023-05-30', '2023-06-30']), ('normal control', {'anchor': [2022, 12, 6], 'interval': 'month', 'count': 1, 'at': [2025, 6, 30]}, ['2025-06-06', '2025-07-06'])], [('regression', {'anchor': [2020, 1, 18], 'interval': 'week', 'count': 3, 'at': [2021, 11, 30]}, ['2021-11-20', '2021-12-11']), ('regression', {'anchor': [2020, 7, 6], 'interval': 'week', 'count': 2, 'at': [2023, 9, 7]}, ['2023-08-28', '2023-09-11']), ('partial-repair probe', {'anchor': [2020, 12, 28], 'interval': 'week', 'count': 2, 'at': [2021, 6, 22]}, ['2021-06-14', '2021-06-28']), ('partial-repair probe', {'anchor': [2023, 12, 20], 'interval': 'week', 'count': 3, 'at': [2026, 5, 31]}, ['2026-05-20', '2026-06-10']), ('boundary control', {'anchor': [2024, 1, 31], 'interval': 'month', 'count': 1, 'at': [2024, 2, 29]}, ['2024-02-29', '2024-03-31']), ('normal control', {'anchor': [2022, 8, 21], 'interval': 'week', 'count': 1, 'at': [2025, 1, 26]}, ['2025-01-26', '2025-02-02']), ('normal control', {'anchor': [2021, 4, 30], 'interval': 'month', 'count': 1, 'at': [2023, 4, 25]}, ['2023-03-30', '2023-04-30']), ('normal control', {'anchor': [2020, 4, 24], 'interval': 'week', 'count': 1, 'at': [2021, 1, 14]}, ['2021-01-08', '2021-01-15']), ('normal control', {'anchor': [2021, 7, 13], 'interval': 'year', 'count': 1, 'at': [2021, 11, 5]}, ['2021-07-13', '2022-07-13'])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Biweekly plans are treated as weekly.

Input {anchor, interval week|month|year, count, at >= anchor}. Period k starts at anchor + k*count intervals (weeks as 7 days; months/years by calendar month with the anchor day clamped to month length). Return [start ISO, end ISO] of the period with start <= at < end.

split: open-access


prompt:
Usage recorded on the change day is billed at both prices.

Input {events: [[day, qty]], change day, old_unit, new_unit, agg sum|max|last}. Events are ordered by day (stable). Events before the change day are aggregated and priced at old_unit; events on or after it at new_unit. Empty segments aggregate to 0; last means the chronologically last quantity. Return [old_charge, new_charge].

split: open-access


prompt:
Last-value meters report whichever event arrived last rather than the latest reading.

Input {events: [[day, qty]], change day, old_unit, new_unit, agg sum|max|last}. Events are ordered by day (stable). Events before the change day are aggregated and priced at old_unit; events on or after it at new_unit. Empty segments aggregate to 0; last means the chronologically last quantity. Return [old_charge, new_charge].

split: open-access


prompt:
Peak meters bill the whole-period peak in both segments.

Input {events: [[day, qty]], change day, old_unit, new_unit, agg sum|max|last}. Events are ordered by day (stable). Events before the change day are aggregated and priced at old_unit; events on or after it at new_unit. Empty segments aggregate to 0; last means the chronologically last quantity. Return [old_charge, new_charge].

split: open-access


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

N = 1
observations = []
def solve(x):
    ev = sorted(x['events'], key=lambda e: e[0])
    before = [q for t, q in ev if t < x['change']]
    after = [q for t, q in ev if t >= x['change']]
    def agg(v):
        if not v:
            return 0
        if x['agg'] == 'sum':
            return sum(v)
        if x['agg'] == 'max':
            return max(v)
        return v[-1]
    return [agg(before) * x['new_unit'], agg(after) * x['new_unit']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[7, 80], [27, 92], [3, 28], [21, 43], [0, 29]], 'change': 3, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [725, 1380]), ('regression', {'events': [[27, 13], [19, 6], [5, 44], [27, 90], [30, 96]], 'change': 30, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1440]), ('partial-repair probe', {'events': [[15, 86], [15, 88]], 'change': 15, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 3520]), ('partial-repair probe', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('normal control', {'events': [], 'change': 27, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 6, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 1, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 1, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[27, 13], [19, 6], [5, 44], [27, 90], [30, 96]], 'change': 30, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1440]), ('regression', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('partial-repair probe', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('partial-repair probe', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('normal control', {'events': [], 'change': 13, 'old_unit': 10, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 8, 'old_unit': 25, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 26, 'old_unit': 25, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 5, 'old_unit': 25, 'new_unit': 40, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('regression', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('partial-repair probe', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('partial-repair probe', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('normal control', {'events': [], 'change': 27, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 20, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 17, 'old_unit': 10, 'new_unit': 15, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('regression', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('partial-repair probe', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('partial-repair probe', {'events': [[21, 57], [28, 66], [4, 55], [23, 20], [14, 65], [14, 74]], 'change': 4, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 2640]), ('normal control', {'events': [], 'change': 19, 'old_unit': 10, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 21, 'old_unit': 10, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 9, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0])], [('regression', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('regression', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('partial-repair probe', {'events': [[30, 18], [0, 63], [28, 43]], 'change': 28, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1575, 1720]), ('partial-repair probe', {'events': [[19, 13], [29, 81], [12, 31], [12, 74]], 'change': 12, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 3240]), ('normal control', {'events': [], 'change': 20, 'old_unit': 25, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 2, 'old_unit': 25, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 23, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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(x):
    ev = sorted(x['events'], key=lambda e: e[0])
    before = [q for t, q in ev if t < x['change']]
    after = [q for t, q in ev if t >= x['change']]
    def agg(v):
        if not v:
            return 0
        if x['agg'] == 'sum':
            return sum(v)
        if x['agg'] == 'max':
            return max(v)
        return v[-1]
    return [agg(before) * x['new_unit'], agg(after) * x['old_unit']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[7, 80], [27, 92], [3, 28], [21, 43], [0, 29]], 'change': 3, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [725, 1380]), ('regression', {'events': [[27, 13], [19, 6], [5, 44], [27, 90], [30, 96]], 'change': 30, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1440]), ('partial-repair probe', {'events': [[15, 86], [15, 88]], 'change': 15, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 3520]), ('partial-repair probe', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('normal control', {'events': [], 'change': 27, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 6, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 1, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 1, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[27, 13], [19, 6], [5, 44], [27, 90], [30, 96]], 'change': 30, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1440]), ('regression', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('partial-repair probe', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('partial-repair probe', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('normal control', {'events': [], 'change': 13, 'old_unit': 10, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 8, 'old_unit': 25, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 26, 'old_unit': 25, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 5, 'old_unit': 25, 'new_unit': 40, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[14, 21], [12, 35], [4, 90], [22, 95], [25, 43], [7, 60]], 'change': 12, 'old_unit': 10, 'new_unit': 15, 'agg': 'max'}, [900, 1425]), ('regression', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('partial-repair probe', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('partial-repair probe', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('normal control', {'events': [], 'change': 27, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 15, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 20, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 17, 'old_unit': 10, 'new_unit': 15, 'agg': 'last'}, [0, 0])], [('regression', {'events': [[21, 53], [25, 86], [26, 43], [1, 19], [13, 55]], 'change': 13, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [475, 3440]), ('regression', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('partial-repair probe', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('partial-repair probe', {'events': [[21, 57], [28, 66], [4, 55], [23, 20], [14, 65], [14, 74]], 'change': 4, 'old_unit': 10, 'new_unit': 40, 'agg': 'last'}, [0, 2640]), ('normal control', {'events': [], 'change': 19, 'old_unit': 10, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 0]), ('normal control', {'events': [], 'change': 21, 'old_unit': 10, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 9, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0])], [('regression', {'events': [[10, 54], [8, 78]], 'change': 23, 'old_unit': 10, 'new_unit': 40, 'agg': 'max'}, [780, 0]), ('regression', {'events': [[19, 78], [29, 77], [0, 53]], 'change': 29, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1950, 3080]), ('partial-repair probe', {'events': [[30, 18], [0, 63], [28, 43]], 'change': 28, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [1575, 1720]), ('partial-repair probe', {'events': [[19, 13], [29, 81], [12, 31], [12, 74]], 'change': 12, 'old_unit': 25, 'new_unit': 40, 'agg': 'max'}, [0, 3240]), ('normal control', {'events': [], 'change': 20, 'old_unit': 25, 'new_unit': 15, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 2, 'old_unit': 25, 'new_unit': 15, 'agg': 'last'}, [0, 0]), ('normal control', {'events': [], 'change': 23, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0]), ('normal control', {'events': [], 'change': 16, 'old_unit': 25, 'new_unit': 40, 'agg': 'sum'}, [0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Usage before an upgrade is billed at the new price.

Input {events: [[day, qty]], change day, old_unit, new_unit, agg sum|max|last}. Events are ordered by day (stable). Events before the change day are aggregated and priced at old_unit; events on or after it at new_unit. Empty segments aggregate to 0; last means the chronologically last quantity. Return [old_charge, new_charge].

split: open-access


prompt:
Credits are consumed on their expiry day.

Input {grants: [[amount, expires_day, granted_day]], day, amount}. A grant is usable when granted_day <= day < expires_day. Usable grants are consumed soonest-expiring first (ties by earlier grant day, then input order). Return [applied, remaining_due, [[left, expires] for partially used or untouched usable grants]].

split: open-access


prompt:
Long-lived credits are consumed while short-lived ones expire unused.

Input {grants: [[amount, expires_day, granted_day]], day, amount}. A grant is usable when granted_day <= day < expires_day. Usable grants are consumed soonest-expiring first (ties by earlier grant day, then input order). Return [applied, remaining_due, [[left, expires] for partially used or untouched usable grants]].

split: open-access


prompt:
Partially used credits reappear at full value.

Input {grants: [[amount, expires_day, granted_day]], day, amount}. A grant is usable when granted_day <= day < expires_day. Usable grants are consumed soonest-expiring first (ties by earlier grant day, then input order). Return [applied, remaining_due, [[left, expires] for partially used or untouched usable grants]].

split: open-access


prompt:
Credits scheduled for next month pay this month's invoice.

Input {grants: [[amount, expires_day, granted_day]], day, amount}. A grant is usable when granted_day <= day < expires_day. Usable grants are consumed soonest-expiring first (ties by earlier grant day, then input order). Return [applied, remaining_due, [[left, expires] for partially used or untouched usable grants]].

split: open-access


prompt:
Monthly schedule parts do not add up to the invoiced amount.

Input {amount, start, end (exclusive)}. The amount is spread by days across calendar months. The cumulative amount through each month is floor(amount*cumulative_days/total_days), and each month gets the increase, so the parts sum exactly to amount. Return [["YYYY-MM", cents]] for each month touched.

split: open-access