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

N = 1
observations = []
def solve(x):
    r = x['redemption']
    if x['cancel_day'] - r['day'] >= x['max_age']:
        return {'error': 'too late'}
    lots = {}
    for exp, p in r['sources']:
        e = exp if exp >= x['cancel_day'] else x['cancel_day'] + x['grace']
        lots[e] = lots.get(e, 0) + p
    return {'lots': [[e, lots[e]] for e in sorted(lots)], 'total': sum(lots.values())}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed sources', {'redemption': {'day': 100, 'sources': [[91, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 51]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 51]], 'total': 51}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 102, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 11, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 101, 'grace': 14, 'max_age': 90}, {'lots': [[115, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 21], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 31], [300, 7]], 'total': 38}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 6]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 6], [150, 10], [200, 40]], 'total': 56}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 81, 'grace': 10, 'max_age': 90}, {'lots': [[91, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[92, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 52]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 52]], 'total': 52}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 103, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 12, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 102, 'grace': 14, 'max_age': 90}, {'lots': [[116, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 22], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 32], [300, 7]], 'total': 39}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 7]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 7], [150, 10], [200, 40]], 'total': 57}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 82, 'grace': 10, 'max_age': 90}, {'lots': [[92, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[93, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 53]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 53]], 'total': 53}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 104, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 13, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 103, 'grace': 14, 'max_age': 90}, {'lots': [[117, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 23], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 33], [300, 7]], 'total': 40}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 8]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 8], [150, 10], [200, 40]], 'total': 58}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 83, 'grace': 10, 'max_age': 90}, {'lots': [[93, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[94, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 54]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 54]], 'total': 54}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 105, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 14, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 104, 'grace': 14, 'max_age': 90}, {'lots': [[118, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 24], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 34], [300, 7]], 'total': 41}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 9]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 9], [150, 10], [200, 40]], 'total': 59}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 84, 'grace': 10, 'max_age': 90}, {'lots': [[94, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[95, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 55]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 55]], 'total': 55}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 106, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 15, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 105, 'grace': 14, 'max_age': 90}, {'lots': [[119, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 25], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 35], [300, 7]], 'total': 42}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 10]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 10], [150, 10], [200, 40]], 'total': 60}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 85, 'grace': 10, 'max_age': 90}, {'lots': [[95, 70]], 'total': 70}]]]
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):
    r = x['redemption']
    if x['cancel_day'] - min(s[0] for s in r['sources']) > x['max_age']:
        return {'error': 'too late'}
    lots = {}
    for exp, p in r['sources']:
        e = exp if exp >= x['cancel_day'] else x['cancel_day'] + x['grace']
        lots[e] = lots.get(e, 0) + p
    return {'lots': [[e, lots[e]] for e in sorted(lots)], 'total': sum(lots.values())}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed sources', {'redemption': {'day': 100, 'sources': [[91, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 51]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 51]], 'total': 51}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 102, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 11, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 101, 'grace': 14, 'max_age': 90}, {'lots': [[115, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 21], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 31], [300, 7]], 'total': 38}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 6]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 6], [150, 10], [200, 40]], 'total': 56}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 81, 'grace': 10, 'max_age': 90}, {'lots': [[91, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[92, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 52]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 52]], 'total': 52}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 103, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 12, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 102, 'grace': 14, 'max_age': 90}, {'lots': [[116, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 22], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 32], [300, 7]], 'total': 39}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 7]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 7], [150, 10], [200, 40]], 'total': 57}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 82, 'grace': 10, 'max_age': 90}, {'lots': [[92, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[93, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 53]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 53]], 'total': 53}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 104, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 13, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 103, 'grace': 14, 'max_age': 90}, {'lots': [[117, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 23], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 33], [300, 7]], 'total': 40}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 8]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 8], [150, 10], [200, 40]], 'total': 58}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 83, 'grace': 10, 'max_age': 90}, {'lots': [[93, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[94, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 54]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 54]], 'total': 54}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 105, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 14, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 104, 'grace': 14, 'max_age': 90}, {'lots': [[118, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 24], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 34], [300, 7]], 'total': 41}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 9]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 9], [150, 10], [200, 40]], 'total': 59}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 84, 'grace': 10, 'max_age': 90}, {'lots': [[94, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[95, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 55]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 55]], 'total': 55}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 106, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 15, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 105, 'grace': 14, 'max_age': 90}, {'lots': [[119, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 25], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 35], [300, 7]], 'total': 42}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 10]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 10], [150, 10], [200, 40]], 'total': 60}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 85, 'grace': 10, 'max_age': 90}, {'lots': [[95, 70]], 'total': 70}]]]
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 cancellation exactly at the age limit is refused.

Input {redemption:{day, sources:[[lot_expiry, pts]]}, cancel_day, grace, max_age}. Cancelling more than max_age days after the redemption returns {"error":"too late"}. Each source lot is reinstated with its original expiry if that expiry is on or after the cancel day, otherwise with expiry cancel_day + grace. Lots with the same resulting expiry are merged. Return {lots:[[expiry,pts]] by expiry, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    r = x['redemption']
    if x['cancel_day'] - r['day'] > x['max_age']:
        return {'error': 'too late'}
    lots = {}
    for exp, p in r['sources']:
        e = exp if exp >= x['cancel_day'] else x['cancel_day'] + x['grace']
        lots[e] = lots.get(e, 0) + p
    return {'lots': [[e, lots[e]] for e in lots], 'total': sum(lots.values())}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed sources', {'redemption': {'day': 100, 'sources': [[91, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 51]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 51]], 'total': 51}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 102, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 11, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 101, 'grace': 14, 'max_age': 90}, {'lots': [[115, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 21], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 31], [300, 7]], 'total': 38}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 6]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 6], [150, 10], [200, 40]], 'total': 56}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 81, 'grace': 10, 'max_age': 90}, {'lots': [[91, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[92, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 52]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 52]], 'total': 52}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 103, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 12, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 102, 'grace': 14, 'max_age': 90}, {'lots': [[116, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 22], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 32], [300, 7]], 'total': 39}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 7]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 7], [150, 10], [200, 40]], 'total': 57}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 82, 'grace': 10, 'max_age': 90}, {'lots': [[92, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[93, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 53]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 53]], 'total': 53}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 104, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 13, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 103, 'grace': 14, 'max_age': 90}, {'lots': [[117, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 23], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 33], [300, 7]], 'total': 40}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 8]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 8], [150, 10], [200, 40]], 'total': 58}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 83, 'grace': 10, 'max_age': 90}, {'lots': [[93, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[94, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 54]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 54]], 'total': 54}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 105, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 14, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 104, 'grace': 14, 'max_age': 90}, {'lots': [[118, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 24], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 34], [300, 7]], 'total': 41}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 9]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 9], [150, 10], [200, 40]], 'total': 59}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 84, 'grace': 10, 'max_age': 90}, {'lots': [[94, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[95, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 55]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 55]], 'total': 55}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 106, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 15, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 105, 'grace': 14, 'max_age': 90}, {'lots': [[119, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 25], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 35], [300, 7]], 'total': 42}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 10]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 10], [150, 10], [200, 40]], 'total': 60}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 85, 'grace': 10, 'max_age': 90}, {'lots': [[95, 70]], 'total': 70}]]]
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):
    r = x['redemption']
    if x['cancel_day'] - r['day'] > x['max_age']:
        return {'error': 'too late'}
    lots = {}
    for exp, p in r['sources']:
        e = exp if exp >= x['cancel_day'] else x['cancel_day'] + x['grace']
        lots[e] = lots.get(e, 0) + p
    return {'lots': [[e, lots[e]] for e in sorted(lots, key=lambda k: lots[k])], 'total': sum(lots.values())}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mixed sources', {'redemption': {'day': 100, 'sources': [[91, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 51]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 51]], 'total': 51}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 102, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 11, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 101, 'grace': 14, 'max_age': 90}, {'lots': [[115, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 21], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 31], [300, 7]], 'total': 38}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 6]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 6], [150, 10], [200, 40]], 'total': 56}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 81, 'grace': 10, 'max_age': 90}, {'lots': [[91, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[92, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 52]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 52]], 'total': 52}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 103, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 12, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 102, 'grace': 14, 'max_age': 90}, {'lots': [[116, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 22], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 32], [300, 7]], 'total': 39}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 7]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 7], [150, 10], [200, 40]], 'total': 57}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 82, 'grace': 10, 'max_age': 90}, {'lots': [[92, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[93, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 53]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 53]], 'total': 53}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 104, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 13, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 103, 'grace': 14, 'max_age': 90}, {'lots': [[117, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 23], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 33], [300, 7]], 'total': 40}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 8]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 8], [150, 10], [200, 40]], 'total': 58}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 83, 'grace': 10, 'max_age': 90}, {'lots': [[93, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[94, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 54]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 54]], 'total': 54}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 105, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 14, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 104, 'grace': 14, 'max_age': 90}, {'lots': [[118, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 24], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 34], [300, 7]], 'total': 41}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 9]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 9], [150, 10], [200, 40]], 'total': 59}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 84, 'grace': 10, 'max_age': 90}, {'lots': [[94, 70]], 'total': 70}]], [['mixed sources', {'redemption': {'day': 100, 'sources': [[95, 300], [150, 200], [400, 100]]}, 'cancel_day': 110, 'grace': 30, 'max_age': 90}, {'lots': [[140, 300], [150, 200], [400, 100]], 'total': 600}], ['expires on cancel day', {'redemption': {'day': 100, 'sources': [[120, 55]]}, 'cancel_day': 120, 'grace': 30, 'max_age': 90}, {'lots': [[120, 55]], 'total': 55}], ['too late', {'redemption': {'day': 10, 'sources': [[500, 100]]}, 'cancel_day': 106, 'grace': 30, 'max_age': 90}, {'error': 'too late'}], ['age edge', {'redemption': {'day': 15, 'sources': [[500, 100], [20, 5]]}, 'cancel_day': 105, 'grace': 14, 'max_age': 90}, {'lots': [[119, 5], [500, 100]], 'total': 105}], ['merge grace lots', {'redemption': {'day': 50, 'sources': [[55, 10], [58, 25], [300, 7]]}, 'cancel_day': 60, 'grace': 45, 'max_age': 90}, {'lots': [[105, 35], [300, 7]], 'total': 42}], ['merge with original', {'redemption': {'day': 50, 'sources': [[200, 40], [150, 10], [90, 10]]}, 'cancel_day': 60, 'grace': 140, 'max_age': 90}, {'lots': [[90, 10], [150, 10], [200, 40]], 'total': 60}], ['late cancel grace base', {'redemption': {'day': 20, 'sources': [[25, 70]]}, 'cancel_day': 85, 'grace': 10, 'max_age': 90}, {'lots': [[95, 70]], 'total': 70}]]]
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:
Reinstated lots are listed in source order, so the soonest-expiring lot is not shown first.

Input {redemption:{day, sources:[[lot_expiry, pts]]}, cancel_day, grace, max_age}. Cancelling more than max_age days after the redemption returns {"error":"too late"}. Each source lot is reinstated with its original expiry if that expiry is on or after the cancel day, otherwise with expiry cancel_day + grace. Lots with the same resulting expiry are merged. Return {lots:[[expiry,pts]] by expiry, total}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            m, d = 3, 1
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29:
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Members born on Feb 29 get their bonus window centred on March 1 in common years.

Input {bmonth, bday, window, bonus, purchases:[[y,m,d]] chronological}. The birthday of year Y is (Y,bmonth,bday), with Feb 29 falling back to Feb 28 in non-leap years (Gregorian rule). A purchase within window days (inclusive, either side) of the birthday of year Y-1, Y or Y+1 earns the bonus once per birthday year. Return per-purchase bonus list.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) < x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2021, 6, 23], [2021, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2022, 6, 23], [2022, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 23], [2023, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 23], [2024, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2025, 6, 23], [2025, 6, 6]]}, [0, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] + 1 and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2021, 6, 23], [2021, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2022, 6, 23], [2022, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 23], [2023, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 23], [2024, 6, 6]]}, [0, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['one day outside', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2025, 6, 23], [2025, 6, 6]]}, [0, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A purchase exactly a week after the birthday misses a seven-day bonus window.

Input {bmonth, bday, window, bonus, purchases:[[y,m,d]] chronological}. The birthday of year Y is (Y,bmonth,bday), with Feb 29 falling back to Feb 28 in non-leap years (Gregorian rule). A purchase within window days (inclusive, either side) of the birthday of year Y-1, Y or Y+1 earns the bonus once per birthday year. Return per-purchase bonus list.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y,):
            if abs((p - bday(yy)).days) <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Purchases in late December miss an early-January birthday window.

Input {bmonth, bday, window, bonus, purchases:[[y,m,d]] chronological}. The birthday of year Y is (Y,bmonth,bday), with Feb 29 falling back to Feb 28 in non-leap years (Gregorian rule). A purchase within window days (inclusive, either side) of the birthday of year Y-1, Y or Y+1 earns the bonus once per birthday year. Return per-purchase bonus list.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] and y not in got:
                got.add(y)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 41, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [41, 41]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 42, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [42, 42]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 43, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [43, 43]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 44, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [44, 44]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 45, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [45, 45]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if abs((p - bday(yy)).days) <= x['window'] and not got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 41, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [41, 41]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 42, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [42, 42]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 43, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [43, 43]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 44, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [44, 44]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]], ['two years', {'bmonth': 5, 'bday': 5, 'window': 2, 'bonus': 45, 'purchases': [[2022, 5, 5], [2023, 5, 6]]}, [45, 45]]]]
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 receives two bonuses for one birthday when purchases straddle New Year.

Input {bmonth, bday, window, bonus, purchases:[[y,m,d]] chronological}. The birthday of year Y is (Y,bmonth,bday), with Feb 29 falling back to Feb 28 in non-leap years (Gregorian rule). A purchase within window days (inclusive, either side) of the birthday of year Y-1, Y or Y+1 earns the bonus once per birthday year. Return per-purchase bonus list.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if (p - bday(yy)).days <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    def bday(y):
        m, d = x['bmonth'], x['bday']
        if m == 2 and d == 29 and not (y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)):
            d = 28
        return datetime.date(y, m, d)
    got = set()
    out = []
    for y, m, d in x['purchases']:
        p = datetime.date(y, m, d)
        award = 0
        for yy in (y - 1, y, y + 1):
            if 0 <= (p - bday(yy)).days <= x['window'] and yy not in got:
                got.add(yy)
                award = x['bonus']
                break
        out.append(award)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 11], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 8]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 801, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [801, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 21], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 12], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 9]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 802, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [802, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 22], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 13], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 10]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 28], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 803, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [803, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 23], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 14], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 11]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 29], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 2], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 804, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [804, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 24], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]], [['inside window', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2024, 6, 15], [2024, 6, 20]]}, [500, 0]], ['window edge', {'bmonth': 6, 'bday': 15, 'window': 7, 'bonus': 500, 'purchases': [[2023, 6, 22], [2023, 6, 12]]}, [500, 0]], ['year crossing', {'bmonth': 1, 'bday': 3, 'window': 7, 'bonus': 300, 'purchases': [[2023, 12, 30], [2024, 1, 5]]}, [300, 0]], ['late december birthday', {'bmonth': 12, 'bday': 30, 'window': 5, 'bonus': 250, 'purchases': [[2025, 1, 3], [2025, 12, 29]]}, [250, 250]], ['leap day', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 800, 'purchases': [[2023, 2, 28], [2024, 2, 29], [2023, 3, 1]]}, [800, 800, 0]], ['century year', {'bmonth': 2, 'bday': 29, 'window': 0, 'bonus': 805, 'purchases': [[2100, 2, 28], [2100, 3, 1]]}, [805, 0]], ['before birthday only', {'bmonth': 9, 'bday': 1, 'window': 3, 'bonus': 100, 'purchases': [[2024, 8, 25], [2024, 8, 30], [2024, 9, 3]]}, [0, 100, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Purchases weeks before a birthday qualify for the bonus.

Input {bmonth, bday, window, bonus, purchases:[[y,m,d]] chronological}. The birthday of year Y is (Y,bmonth,bday), with Feb 29 falling back to Feb 28 in non-leap years (Gregorian rule). A purchase within window days (inclusive, either side) of the birthday of year Y-1, Y or Y+1 earns the bonus once per birthday year. Return per-purchase bonus list.

split: open-access


prompt:
The monthly cap behaves like an annual cap and later months award no bonus.

Input {cap, txns:[[yyyy-mm, base, bonus, exempt_bonus]]}. Base points are never capped. Regular bonus points are capped per calendar month: each transaction receives min(bonus, cap - bonus already awarded that month). Exempt bonus is always awarded and never uses the cap. Return {awards (base + awarded bonus + exempt per txn), total}.

split: open-access


prompt:
A transaction that would exceed the cap gets no bonus at all instead of the remaining allowance.

Input {cap, txns:[[yyyy-mm, base, bonus, exempt_bonus]]}. Base points are never capped. Regular bonus points are capped per calendar month: each transaction receives min(bonus, cap - bonus already awarded that month). Exempt bonus is always awarded and never uses the cap. Return {awards (base + awarded bonus + exempt per txn), total}.

split: open-access


prompt:
Large purchases exhaust the bonus cap with base points.

Input {cap, txns:[[yyyy-mm, base, bonus, exempt_bonus]]}. Base points are never capped. Regular bonus points are capped per calendar month: each transaction receives min(bonus, cap - bonus already awarded that month). Exempt bonus is always awarded and never uses the cap. Return {awards (base + awarded bonus + exempt per txn), total}.

split: open-access


prompt:
Exempt promotional bonus uses up the monthly cap.

Input {cap, txns:[[yyyy-mm, base, bonus, exempt_bonus]]}. Base points are never capped. Regular bonus points are capped per calendar month: each transaction receives min(bonus, cap - bonus already awarded that month). Exempt bonus is always awarded and never uses the cap. Return {awards (base + awarded bonus + exempt per txn), total}.

split: open-access


prompt:
Exempt promotional bonus never reaches the member.

Input {cap, txns:[[yyyy-mm, base, bonus, exempt_bonus]]}. Base points are never capped. Regular bonus points are capped per calendar month: each transaction receives min(bonus, cap - bonus already awarded that month). Exempt bonus is always awarded and never uses the cap. Return {awards (base + awarded bonus + exempt per txn), total}.

split: open-access