FA-60371 / Loyalty points ledgers / Open access
Order points earning: promo multiplier increment · case 01
Promotional categories earn their base points twice.
ROOT CAUSE
The promo bonus uses the full multiplier instead of the increment above the base earn.
VERIFIED REPAIR
Bonus = floor(category spend/100) * (multiplier - 1).
Unsuccessful approach: Subtracting one point instead of one multiplier step leaves the bonus far too high.
Case contract
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}.
Why this case matters
Member point balances, statements and the program liability depend on this ledger rule.
1 / The failure
Exit 1"""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
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 450, 'tier': 238, 'total': 688} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Failed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Passed |
| cents across lines | {'base': 7, 'bonus': 2, 'tier': 8, 'total': 10} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Failed |
| two promos | {'base': 78, 'bonus': 222, 'tier': 117, 'total': 339} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Failed |
SHA-256 / fa8132880167c68e259a515a1ca0e071d398fa12636a76b871e017c769d6d2ea
2 / The unsuccessful fix
Exit 1"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 449, 'tier': 238, 'total': 687} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Failed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Passed |
| cents across lines | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Passed |
| two promos | {'base': 78, 'bonus': 220, 'tier': 117, 'total': 337} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Failed |
SHA-256 / 0e996ca838acf13b144ef034be15e8148f21f9f33aaa3ff9d185bbf19765bf40
3 / The verified repair
Exit 0"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Passed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Passed |
| cents across lines | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Passed |
| two promos | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Passed |
SHA-256 / 15f636ae2efe91fbdf41c1991d49e2dec00ae20628f8e40d786b7be8befb6784
Verification & scope
Stipulated bounded loyalty-program model with explicit toy rules; not any real program terms. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:45.003461+00:00.
Case digest / 3fb50838b73a2c09b38eee0e311f759f0777ac1968a8b68481b1f4e10c51282d