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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = sum(l[2] for l in lots if l[0] < day)
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in lots):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            lots = [l for l in lots if l[2] > 0]
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = sum(l[2] for l in lots if l[0] < day)
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in live if l[0] > day):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            lots = [l for l in lots if l[2] > 0]
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A redemption is accepted against expired points and then only partly filled.

Events ["earn",day,pts,ttl] create a lot expiring at day+ttl (usable through that day); ["redeem",day,pts] draws only unexpired lots, soonest expiry first (ties by earn day), rejecting with "insufficient" when unexpired points are short; ["sweep",day] removes lots whose expiry is before day and reports the points removed. Emptied lots are dropped. Return {results, lots:[[expiry, earn_day, pts]]}.

split: open-access


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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = len([l for l in lots if l[0] < day])
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in live):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            lots = [l for l in lots if l[2] > 0]
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = sum(l[2] for l in lots if l[0] >= day)
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in live):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            lots = [l for l in lots if l[2] > 0]
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The expiry notice says "2 points expired" when two lots holding hundreds of points expired.

Events ["earn",day,pts,ttl] create a lot expiring at day+ttl (usable through that day); ["redeem",day,pts] draws only unexpired lots, soonest expiry first (ties by earn day), rejecting with "insufficient" when unexpired points are short; ["sweep",day] removes lots whose expiry is before day and reports the points removed. Emptied lots are dropped. Return {results, lots:[[expiry, earn_day, pts]]}.

split: open-access


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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = sum(l[2] for l in lots if l[0] < day)
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in live):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    lots = []
    out = []
    for ev in x['events']:
        kind, day = ev[0], ev[1]
        if kind == 'earn':
            exp = day + ev[3]
            lots.append([exp, day, ev[2]])
            out.append(exp)
        elif kind == 'sweep':
            gone = sum(l[2] for l in lots if l[0] < day)
            lots = [l for l in lots if l[0] >= day]
            out.append(gone)
        else:
            need = ev[2]
            live = sorted([l for l in lots if l[0] >= day], key=lambda l: (l[0], l[1]))
            if need > sum(l[2] for l in live):
                out.append('insufficient')
                continue
            used = []
            for l in live:
                t = min(need, l[2])
                if t > 0:
                    l[2] -= t
                    need -= t
                    used.append([l[0], t])
            lots = [l for l in lots if l[2] >= 0]
            out.append(used)
    return {'results': out, 'lots': lots}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 31], ['redeem', 20, 400]]}, {'results': [366, 41, [[41, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 151]]}, {'results': [30, [[30, 151]]], 'lots': [[30, 0, 49]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 101]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 81, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 201], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 11], ['sweep', 11], ['sweep', 12]]}, {'results': [11, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 31]]}, {'results': [50, 61, [[50, 100]], [[61, 31]]], 'lots': [[61, 1, 69]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 151], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 51]]}, {'results': [25, 25, [[25, 40], [25, 11]]], 'lots': [[25, 5, 29]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 32], ['redeem', 20, 400]]}, {'results': [366, 42, [[42, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 152]]}, {'results': [30, [[30, 152]]], 'lots': [[30, 0, 48]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 102]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 82, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 202], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 12], ['sweep', 12], ['sweep', 13]]}, {'results': [12, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 32]]}, {'results': [50, 61, [[50, 100]], [[61, 32]]], 'lots': [[61, 1, 68]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 152], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 52]]}, {'results': [25, 25, [[25, 40], [25, 12]]], 'lots': [[25, 5, 28]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 33], ['redeem', 20, 400]]}, {'results': [366, 43, [[43, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 153]]}, {'results': [30, [[30, 153]]], 'lots': [[30, 0, 47]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 103]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 83, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 203], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 13], ['sweep', 13], ['sweep', 14]]}, {'results': [13, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 33]]}, {'results': [50, 61, [[50, 100]], [[61, 33]]], 'lots': [[61, 1, 67]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 153], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 53]]}, {'results': [25, 25, [[25, 40], [25, 13]]], 'lots': [[25, 5, 27]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 34], ['redeem', 20, 400]]}, {'results': [366, 44, [[44, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 154]]}, {'results': [30, [[30, 154]]], 'lots': [[30, 0, 46]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 104]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 84, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 204], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 14], ['sweep', 14], ['sweep', 15]]}, {'results': [14, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 34]]}, {'results': [50, 61, [[50, 100]], [[61, 34]]], 'lots': [[61, 1, 66]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 154], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 54]]}, {'results': [25, 25, [[25, 40], [25, 14]]], 'lots': [[25, 5, 26]]}]], [['soonest expiry first', {'events': [['earn', 1, 500, 365], ['earn', 10, 300, 35], ['redeem', 20, 400]]}, {'results': [366, 45, [[45, 300], [366, 100]]], 'lots': [[366, 1, 400]]}], ['use on expiry day', {'events': [['earn', 0, 200, 30], ['redeem', 30, 155]]}, {'results': [30, [[30, 155]]], 'lots': [[30, 0, 45]]}], ['expired unusable', {'events': [['earn', 0, 200, 30], ['earn', 5, 50, 90], ['redeem', 31, 105]]}, {'results': [30, 95, 'insufficient'], 'lots': [[30, 0, 200], [95, 5, 50]]}], ['sweep reports points', {'events': [['earn', 0, 120, 10], ['earn', 0, 85, 10], ['earn', 3, 60, 100], ['sweep', 11]]}, {'results': [10, 10, 103, 205], 'lots': [[103, 3, 60]]}], ['sweep boundary', {'events': [['earn', 0, 70, 15], ['sweep', 15], ['sweep', 16]]}, {'results': [15, 0, 70], 'lots': []}], ['partial lot cleanup', {'events': [['earn', 0, 100, 50], ['earn', 1, 100, 60], ['redeem', 2, 100], ['redeem', 3, 35]]}, {'results': [50, 61, [[50, 100]], [[61, 35]]], 'lots': [[61, 1, 65]]}], ['insufficient', {'events': [['earn', 0, 100, 50], ['redeem', 1, 155], ['redeem', 2, 100]]}, {'results': [50, 'insufficient', [[50, 100]]], 'lots': []}], ['ties by earn day', {'events': [['earn', 5, 40, 20], ['earn', 1, 40, 24], ['redeem', 6, 55]]}, {'results': [25, 25, [[25, 40], [25, 15]]], 'lots': [[25, 5, 25]]}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Statements list zero-point lots left over from redemptions.

Events ["earn",day,pts,ttl] create a lot expiring at day+ttl (usable through that day); ["redeem",day,pts] draws only unexpired lots, soonest expiry first (ties by earn day), rejecting with "insufficient" when unexpired points are short; ["sweep",day] removes lots whose expiry is before day and reports the points removed. Emptied lots are dropped. Return {results, lots:[[expiry, earn_day, pts]]}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if bal <= 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min(x['request_pts'] // blk * blk, bal // blk * blk, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}], ['small balance big request', {'balance': 451, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}], ['small balance big request', {'balance': 452, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 453, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 454, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 455, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if x['request_pts'] < 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min(x['request_pts'] // blk * blk, bal // blk * blk, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}], ['small balance big request', {'balance': 451, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}], ['small balance big request', {'balance': 452, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 453, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 454, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}], ['small balance big request', {'balance': 455, 'order_cents': 9000, 'request_pts': 600, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A member with exactly the 500-point minimum cannot redeem.

Input {balance, order_cents, request_pts, max_pct, cpp (cents per point)}. Balance below 500 returns {"error":"below minimum"}. Points are used in blocks of 100: used = min(request floored to a block, balance floored to a block, cap) where cap = floor(order*max_pct/100 / cpp) floored to a block. Cash due = order - used*cpp. Return {points_used, cash_due}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if bal < 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min(-(-x['request_pts'] // blk) * blk, bal // blk * blk, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if bal < 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min((x['request_pts'] + blk // 2) // blk * blk, bal // blk * blk, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Members are charged more points than they asked for.

Input {balance, order_cents, request_pts, max_pct, cpp (cents per point)}. Balance below 500 returns {"error":"below minimum"}. Points are used in blocks of 100: used = min(request floored to a block, balance floored to a block, cap) where cap = floor(order*max_pct/100 / cpp) floored to a block. Cash due = order - used*cpp. Return {points_used, cash_due}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if bal < 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min(x['request_pts'] // blk * blk, bal, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    bal = x['balance']
    order = x['order_cents']
    if bal < 500:
        return {'error': 'below minimum'}
    blk = 100
    cap_cents = order * x['max_pct'] // 100
    cap = cap_cents // x['cpp'] // blk * blk
    use = min(x['request_pts'] // blk * blk, (bal + blk // 2) // blk * blk, cap)
    return {'points_used': use, 'cash_due': order - use * x['cpp']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['normal', {'balance': 2750, 'order_cents': 4001, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2201}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5001, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1291, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 51, 'cpp': 2}, {'points_used': 1200, 'cash_due': 2600}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1285, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4002, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2202}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5002, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1292, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 52, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1295, 'max_pct': 90, 'cpp': 1}, {'points_used': 1200, 'cash_due': 8800}]], [['normal', {'balance': 2750, 'order_cents': 4003, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2203}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5003, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1293, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 53, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1305, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4004, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2204}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5004, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 2}, {'points_used': 500, 'cash_due': 8999}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1294, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 54, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1315, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]], [['normal', {'balance': 2750, 'order_cents': 4005, 'request_pts': 1850, 'max_pct': 50, 'cpp': 1}, {'points_used': 1800, 'cash_due': 2205}], ['cap binds', {'balance': 9000, 'order_cents': 3000, 'request_pts': 5005, 'max_pct': 40, 'cpp': 1}, {'points_used': 1200, 'cash_due': 1800}], ['minimum balance edge', {'balance': 500, 'order_cents': 9999, 'request_pts': 500, 'max_pct': 100, 'cpp': 3}, {'points_used': 500, 'cash_due': 8499}], ['below minimum', {'balance': 499, 'order_cents': 9999, 'request_pts': 400, 'max_pct': 100, 'cpp': 1}, {'error': 'below minimum'}], ['balance binds', {'balance': 1295, 'order_cents': 50000, 'request_pts': 3000, 'max_pct': 60, 'cpp': 1}, {'points_used': 1200, 'cash_due': 48800}], ['two cents per point', {'balance': 5000, 'order_cents': 5000, 'request_pts': 4000, 'max_pct': 55, 'cpp': 2}, {'points_used': 1300, 'cash_due': 2400}], ['odd request', {'balance': 3000, 'order_cents': 10000, 'request_pts': 1325, 'max_pct': 90, 'cpp': 1}, {'points_used': 1300, 'cash_due': 8700}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A redemption uses an odd number of points that is not a whole block.

Input {balance, order_cents, request_pts, max_pct, cpp (cents per point)}. Balance below 500 returns {"error":"below minimum"}. Points are used in blocks of 100: used = min(request floored to a block, balance floored to a block, cap) where cap = floor(order*max_pct/100 / cpp) floored to a block. Cash due = order - used*cpp. Return {points_used, cash_due}.

split: open-access