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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig <= 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 499:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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 order of exactly five dollars of eligible spend earns nothing.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = sum(l['amount'] // 100 for l in x['lines'] if l['cat'] != 'giftcard')
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = (elig + 50) // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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:
Orders with many small lines earn fewer points than one line of the same total.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = elig * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 10000
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = (base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] + 50) // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    bonus = min(bonus, 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}]]]
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:
Silver and gold members receive tier points computed from cents rather than base points, off by fractional points.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access


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

N = 1
observations = []
def solve(x):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += (amt // 100) * (mult - 1)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60100}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1101, 'tier': 1101, 'bonus': 1000, 'total': 2101}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60200}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1102, 'tier': 1102, 'bonus': 1000, 'total': 2102}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60300}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1103, 'tier': 1103, 'bonus': 1000, 'total': 2103}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60400}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1104, 'tier': 1104, 'bonus': 1000, 'total': 2104}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60500}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1105, 'tier': 1105, 'bonus': 1000, 'total': 2105}]]]
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):
    elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
    if elig < 500:
        return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
    base = elig // 100
    tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
    bonus = 0
    for cat, mult in sorted(x['promo'].items()):
        if cat == 'giftcard':
            continue
        amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
        bonus += min((amt // 100) * (mult - 1), 1000)
    return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60100}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1101, 'tier': 1101, 'bonus': 1000, 'total': 2101}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60200}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1102, 'tier': 1102, 'bonus': 1000, 'total': 2102}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60300}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1103, 'tier': 1103, 'bonus': 1000, 'total': 2103}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60400}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1104, 'tier': 1104, 'bonus': 1000, 'total': 2104}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60500}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1105, 'tier': 1105, 'bonus': 1000, 'total': 2105}]]]
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:
Large promotional orders receive unlimited bonus points.

Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.

split: open-access