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

N = 1
observations = []
def solve(x):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            tier = t
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= x['txns'][-1][0]:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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:
Transactions made before an upgrade are re-earned at the new, higher multiplier.

Input {tier_history:[[effective_day,tier]] (any order), txns:[[day,base]], mult:{tier:pct}}. Each transaction earns floor(base*pct/100) using the tier with the latest effective_day <= transaction day ("member" before any entry). Unknown tier names earn at 100%. Return {points, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff < day:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= day + 1:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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:
Transactions on the day a tier takes effect earn at the old tier.

Input {tier_history:[[effective_day,tier]] (any order), txns:[[day,base]], mult:{tier:pct}}. Each transaction earns floor(base*pct/100) using the tier with the latest effective_day <= transaction day ("member" before any entry). Unknown tier names earn at 100%. Return {points, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    hist = x['tier_history']
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= day:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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):
    hist = sorted(x['tier_history'], key=lambda h: h[1])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= day:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 100)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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:
An out-of-order tier history makes later transactions use an older tier.

Input {tier_history:[[effective_day,tier]] (any order), txns:[[day,base]], mult:{tier:pct}}. Each transaction earns floor(base*pct/100) using the tier with the latest effective_day <= transaction day ("member" before any entry). Unknown tier names earn at 100%. Return {points, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= day:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, 0)
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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):
    hist = sorted(x['tier_history'])
    out = []
    for day, base in x['txns']:
        tier = 'member'
        for eff, t in hist:
            if eff <= day:
                tier = t
            else:
                break
        pct = x['mult'].get(tier, max(x['mult'].values()))
        out.append(base * pct // 100)
    return {'points': out, 'total': sum(out)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1001], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1251, 1500], 'total': 3751}], ['effective day', {'tier_history': [[100, 'silver'], [201, 'gold']], 'txns': [[100, 400], [201, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 101], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [151, 200], 'total': 351}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 334]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [334], 'total': 334}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 11]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 11], 'total': 88}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 201]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 251], 'total': 551}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 91]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [113], 'total': 113}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1002], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1252, 1500], 'total': 3752}], ['effective day', {'tier_history': [[100, 'silver'], [202, 'gold']], 'txns': [[100, 400], [202, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 102], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [153, 200], 'total': 353}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 335]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [335], 'total': 335}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 12]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 12], 'total': 89}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 202]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 252], 'total': 552}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 92]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [115], 'total': 115}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1003], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1253, 1500], 'total': 3753}], ['effective day', {'tier_history': [[100, 'silver'], [203, 'gold']], 'txns': [[100, 400], [203, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 103], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [154, 200], 'total': 354}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 336]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [336], 'total': 336}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 13]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 13], 'total': 90}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 203]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 253], 'total': 553}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 93]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [116], 'total': 116}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1004], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1255, 1500], 'total': 3755}], ['effective day', {'tier_history': [[100, 'silver'], [204, 'gold']], 'txns': [[100, 400], [204, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 104], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [156, 200], 'total': 356}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 337]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [337], 'total': 337}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 14]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 14], 'total': 91}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 204]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 255], 'total': 555}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 94]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [117], 'total': 117}]], [['tier changes midyear', {'tier_history': [[100, 'silver'], [200, 'gold']], 'txns': [[50, 1000], [150, 1005], [250, 1000]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [1000, 1256, 1500], 'total': 3756}], ['effective day', {'tier_history': [[100, 'silver'], [205, 'gold']], 'txns': [[100, 400], [205, 400]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [500, 600], 'total': 1100}], ['unsorted history', {'tier_history': [[300, 'platinum'], [100, 'gold']], 'txns': [[150, 105], [350, 100]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [157, 200], 'total': 357}], ['legacy tier', {'tier_history': [[10, 'diamond']], 'txns': [[20, 338]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [338], 'total': 338}], ['before any tier', {'tier_history': [[500, 'gold']], 'txns': [[1, 77], [499, 15]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [77, 15], 'total': 92}], ['downgrade', {'tier_history': [[10, 'gold'], [60, 'silver']], 'txns': [[59, 200], [61, 205]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [300, 256], 'total': 556}], ['late earns', {'tier_history': [[0, 'silver'], [30, 'platinum']], 'txns': [[15, 95]], 'mult': {'member': 100, 'silver': 125, 'gold': 150, 'platinum': 200}}, {'points': [118], 'total': 118}]]]
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 on a retired tier name earn zero points.

Input {tier_history:[[effective_day,tier]] (any order), txns:[[day,base]], mult:{tier:pct}}. Each transaction earns floor(base*pct/100) using the tier with the latest effective_day <= transaction day ("member" before any entry). Unknown tier names earn at 100%. Return {points, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    room = x['price'] - x['min_cash']
    maxp = max(0, -(-room * 10 // x['cpp10']))
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': x['price'] - credit}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}], ['fraction above half', {'price': 1007, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1438, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}], ['fraction above half', {'price': 1014, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1448, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}], ['fraction above half', {'price': 1021, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1458, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}], ['fraction above half', {'price': 1028, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1468, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}], ['fraction above half', {'price': 1035, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1478, 'cash': 1}]]]
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):
    room = x['price'] - x['min_cash']
    maxp = max(0, (room * 10 + x['cpp10'] // 2) // x['cpp10'])
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': x['price'] - credit}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}], ['fraction above half', {'price': 1007, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1438, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}], ['fraction above half', {'price': 1014, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1448, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}], ['fraction above half', {'price': 1021, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1458, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}], ['fraction above half', {'price': 1028, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1468, 'cash': 1}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}], ['fraction above half', {'price': 1035, 'balance': 1000000, 'cpp10': 7, 'min_cash': 0}, {'points': 1478, 'cash': 1}]]]
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:
Cash due falls below the minimum cash component by a fraction of a point.

Input {price, balance, cpp10 (point value in tenths of a cent), min_cash}. Points may cover at most price - min_cash (never negative): max points = floor((price - min_cash)*10/cpp10), limited by balance. Credit = floor(points*cpp10/10); cash = price - credit. Return {points, cash}.

split: open-access


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

N = 1
observations = []
def solve(x):
    room = x['price']
    maxp = max(0, room * 10 // x['cpp10'])
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': x['price'] - credit}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}]]]
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):
    room = x['price']
    maxp = max(0, room * 10 // x['cpp10'])
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': max(x['min_cash'], x['price'] - credit)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}]]]
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:
Awards are fully paid with points although a cash co-pay is required.

Input {price, balance, cpp10 (point value in tenths of a cent), min_cash}. Points may cover at most price - min_cash (never negative): max points = floor((price - min_cash)*10/cpp10), limited by balance. Credit = floor(points*cpp10/10); cash = price - credit. Return {points, cash}.

split: open-access


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

N = 1
observations = []
def solve(x):
    room = x['price'] - x['min_cash']
    maxp = max(0, room // x['cpp10'])
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': x['price'] - credit}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}]]]
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):
    room = x['price'] - x['min_cash']
    maxp = max(0, room * 100 // x['cpp10'])
    pts = min(x['balance'], maxp)
    credit = pts * x['cpp10'] // 10
    return {'points': pts, 'cash': x['price'] - credit}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 501}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3001, 'cpp10': 10, 'min_cash': 100}, {'points': 3001, 'cash': 6999}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 2}, {'points': 7138, 'cash': 3}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 401}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 990}, {'points': 4, 'cash': 990}], ['odd credit', {'price': 2503, 'balance': 1238, 'cpp10': 13, 'min_cash': 3}, {'points': 1238, 'cash': 894}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 502}, {'points': 7915, 'cash': 502}], ['balance limits', {'price': 10000, 'balance': 3002, 'cpp10': 10, 'min_cash': 100}, {'points': 3002, 'cash': 6998}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 3}, {'points': 7137, 'cash': 4}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 402}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 980}, {'points': 8, 'cash': 980}], ['odd credit', {'price': 2503, 'balance': 1239, 'cpp10': 13, 'min_cash': 3}, {'points': 1239, 'cash': 893}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 503}, {'points': 7914, 'cash': 504}], ['balance limits', {'price': 10000, 'balance': 3003, 'cpp10': 10, 'min_cash': 100}, {'points': 3003, 'cash': 6997}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 4}, {'points': 7135, 'cash': 5}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 403}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 970}, {'points': 12, 'cash': 970}], ['odd credit', {'price': 2503, 'balance': 1240, 'cpp10': 13, 'min_cash': 3}, {'points': 1240, 'cash': 891}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 504}, {'points': 7913, 'cash': 505}], ['balance limits', {'price': 10000, 'balance': 3004, 'cpp10': 10, 'min_cash': 100}, {'points': 3004, 'cash': 6996}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 5}, {'points': 7134, 'cash': 6}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 404}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 960}, {'points': 16, 'cash': 960}], ['odd credit', {'price': 2503, 'balance': 1241, 'cpp10': 13, 'min_cash': 3}, {'points': 1241, 'cash': 890}]], [['points cover most', {'price': 10000, 'balance': 50000, 'cpp10': 12, 'min_cash': 505}, {'points': 7912, 'cash': 506}], ['balance limits', {'price': 10000, 'balance': 3005, 'cpp10': 10, 'min_cash': 100}, {'points': 3005, 'cash': 6995}], ['fractional value', {'price': 4999, 'balance': 99999, 'cpp10': 7, 'min_cash': 6}, {'points': 7132, 'cash': 7}], ['price below minimum cash', {'price': 300, 'balance': 1000, 'cpp10': 10, 'min_cash': 405}, {'points': 0, 'cash': 300}], ['exact minimum', {'price': 1000, 'balance': 100000, 'cpp10': 25, 'min_cash': 950}, {'points': 20, 'cash': 950}], ['odd credit', {'price': 2503, 'balance': 1242, 'cpp10': 13, 'min_cash': 3}, {'points': 1242, 'cash': 889}]]]
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:
Only a tenth of the allowed points are applied.

Input {price, balance, cpp10 (point value in tenths of a cent), min_cash}. Points may cover at most price - min_cash (never negative): max points = floor((price - min_cash)*10/cpp10), limited by balance. Credit = floor(points*cpp10/10); cash = price - credit. Return {points, cash}.

split: open-access