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

N = 1
observations = []
def solve(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = allow - (ani - 100000) // 2
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression allowance-floor 1', (140000, 0), 4920300), ('regression allowance-floor 2', (200000, 0), 7620300),
  ('partial repair guard 2', (125143, 0), 4251735), ('control: basic and higher', (50000, 0), 748600),
  ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200),
  ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression allowance-floor 1', (125143, 0), 4251735), ('regression allowance-floor 2', (125142, 0), 4251690),
  ('partial repair guard 2', (195853, 51587), 5112270), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600), ('control: below allowance', (9000, 0), 0),
  ('control: large pension', (160000, 60000), 2743200)],
 [('regression allowance-floor 1', (286985, 0), 11534625), ('regression allowance-floor 2', (196467, 5000), 7236315),
  ('partial repair guard 1', (127056, 1), 4337775), ('partial repair guard 2', (129722, 1), 4457745),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression allowance-floor 1', (233138, 36810), 7455060),
  ('regression allowance-floor 2', (260916, 5000), 10136520), ('partial repair guard 1', (128692, 0), 4411440),
  ('partial repair guard 2', (145918, 8578), 4800600), ('control: basic and higher', (50000, 0), 748600),
  ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression allowance-floor 1', (291558, 0), 11740410), ('regression allowance-floor 2', (220311, 12207), 7984980),
  ('partial repair guard 1', (127233, 1), 4345740), ('partial repair guard 2', (151401, 22890), 4403295),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[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(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = 0 if ani >= 150000 else allow - (ani - 100000) // 2
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression allowance-floor 1', (140000, 0), 4920300), ('regression allowance-floor 2', (200000, 0), 7620300),
  ('partial repair guard 2', (125143, 0), 4251735), ('control: basic and higher', (50000, 0), 748600),
  ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200),
  ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression allowance-floor 1', (125143, 0), 4251735), ('regression allowance-floor 2', (125142, 0), 4251690),
  ('partial repair guard 2', (195853, 51587), 5112270), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600), ('control: below allowance', (9000, 0), 0),
  ('control: large pension', (160000, 60000), 2743200)],
 [('regression allowance-floor 1', (286985, 0), 11534625), ('regression allowance-floor 2', (196467, 5000), 7236315),
  ('partial repair guard 1', (127056, 1), 4337775), ('partial repair guard 2', (129722, 1), 4457745),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression allowance-floor 1', (233138, 36810), 7455060),
  ('regression allowance-floor 2', (260916, 5000), 10136520), ('partial repair guard 1', (128692, 0), 4411440),
  ('partial repair guard 2', (145918, 8578), 4800600), ('control: basic and higher', (50000, 0), 748600),
  ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression allowance-floor 1', (291558, 0), 11740410), ('regression allowance-floor 2', (220311, 12207), 7984980),
  ('partial repair guard 1', (127233, 1), 4345740), ('partial repair guard 2', (151401, 22890), 4403295),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[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:
Very high earners are taxed on more than their income.

solve(income, pension): stipulated allowance taper in whole pounds. Adjusted net income ani = income - pension. The personal allowance 12570 is reduced by 1 for every 2 whole pounds of ani above 100000 (floor of half the excess), never below 0. Taxable = max(0, ani - allowance). Taxable income is taxed 20% up to 37700, 40% from 37700 to 125140, 45% above 125140. Return tax in integer pence.

split: open-access


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

N = 1
observations = []
def solve(income, pension):
    ani = income - pension
    allow = 12570
    if income > 100000: allow = max(0, allow - (income - 100000) // 2)
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taper-measure 1', (130000, 5000), 4243200), ('regression taper-measure 2', (160000, 60000), 2743200),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression taper-measure 1', (125142, 20000), 3051720), ('regression taper-measure 2', (100003, 5000), 2543320),
  ('partial repair guard 1', (100001, 5000), 2543240), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression taper-measure 1', (103415, 5000), 2679800), ('regression taper-measure 2', (125142, 31576), 2485840),
  ('partial repair guard 1', (100003, 5000), 2543320), ('control: below allowance', (9000, 0), 0),
  ('control: large pension', (160000, 60000), 2743200), ('control: mid taper', (140000, 0), 4920300),
  ('control: basic and higher', (50000, 0), 748600)],
 [('regression taper-measure 1', (113902, 1), 3577240), ('regression taper-measure 2', (125141, 5000), 3951640),
  ('partial repair guard 1', (125142, 1), 4251645), ('partial repair guard 2', (125141, 1), 4251600),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression taper-measure 1', (100003, 7786), 2431880), ('regression taper-measure 2', (105804, 5000), 2791440),
  ('partial repair guard 1', (125142, 31576), 2485840), ('partial repair guard 2', (100003, 1), 2743320),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[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(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = max(0, allow - (ani - 100000) // 2)
    taxable = max(0, income - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(taxable, 125140) - 37700)
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression taper-measure 1', (130000, 5000), 4243200), ('regression taper-measure 2', (160000, 60000), 2743200),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600)],
 [('regression taper-measure 1', (125142, 20000), 3051720), ('regression taper-measure 2', (100003, 5000), 2543320),
  ('partial repair guard 1', (100001, 5000), 2543240), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression taper-measure 1', (103415, 5000), 2679800), ('regression taper-measure 2', (125142, 31576), 2485840),
  ('partial repair guard 1', (100003, 5000), 2543320), ('control: below allowance', (9000, 0), 0),
  ('control: large pension', (160000, 60000), 2743200), ('control: mid taper', (140000, 0), 4920300),
  ('control: basic and higher', (50000, 0), 748600)],
 [('regression taper-measure 1', (113902, 1), 3577240), ('regression taper-measure 2', (125141, 5000), 3951640),
  ('partial repair guard 1', (125142, 1), 4251645), ('partial repair guard 2', (125141, 1), 4251600),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression taper-measure 1', (100003, 7786), 2431880), ('regression taper-measure 2', (105804, 5000), 2791440),
  ('partial repair guard 1', (125142, 31576), 2485840), ('partial repair guard 2', (100003, 1), 2743320),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[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:
Pension contributions no longer restore the personal allowance.

solve(income, pension): stipulated allowance taper in whole pounds. Adjusted net income ani = income - pension. The personal allowance 12570 is reduced by 1 for every 2 whole pounds of ani above 100000 (floor of half the excess), never below 0. Taxable = max(0, ani - allowance). Taxable income is taxed 20% up to 37700, 40% from 37700 to 125140, 45% above 125140. Return tax in integer pence.

split: open-access


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

N = 1
observations = []
def solve(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = max(0, allow - (ani - 100000) // 2)
    taxable = max(0, ani - allow)
    basic = max(0, min(ani, 37700) - allow)
    higher = max(0, min(ani, 125140) - max(37700, allow))
    additional = max(0, ani - max(125140, allow))
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-base 1', (50000, 0), 748600), ('regression band-base 2', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735)],
 [('regression band-base 1', (130000, 5000), 4243200), ('regression band-base 2', (160000, 60000), 2743200),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression band-base 1', (73848, 0), 1697120), ('regression band-base 2', (100003, 0), 2743360),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression band-base 1', (77280, 0), 1834400), ('regression band-base 2', (100001, 5000), 2543240),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression band-base 1', (112519, 0), 3494320), ('regression band-base 2', (125142, 20000), 3051720),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[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(income, pension):
    ani = income - pension
    allow = 12570
    if ani > 100000: allow = max(0, allow - (ani - 100000) // 2)
    taxable = max(0, ani - allow)
    basic = min(taxable, 37700)
    higher = max(0, min(ani, 125140) - max(37700, allow))
    additional = max(0, taxable - 125140)
    return basic * 20 + higher * 40 + additional * 45
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression band-base 1', (50000, 0), 748600), ('regression band-base 2', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300),
  ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735)],
 [('regression band-base 1', (130000, 5000), 4243200), ('regression band-base 2', (160000, 60000), 2743200),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)],
 [('regression band-base 1', (73848, 0), 1697120), ('regression band-base 2', (100003, 0), 2743360),
  ('control: below allowance', (9000, 0), 0), ('control: large pension', (160000, 60000), 2743200),
  ('control: mid taper', (140000, 0), 4920300), ('control: basic and higher', (50000, 0), 748600)],
 [('regression band-base 1', (77280, 0), 1834400), ('regression band-base 2', (100001, 5000), 2543240),
  ('control: basic and higher', (50000, 0), 748600), ('control: odd excess in taper', (110001, 0), 3343240),
  ('control: pension restores allowance', (130000, 5000), 4243200), ('control: fully tapered', (200000, 0), 7620300)],
 [('regression band-base 1', (112519, 0), 3494320), ('regression band-base 2', (125142, 20000), 3051720),
  ('control: fully tapered', (200000, 0), 7620300), ('control: allowance exhausted exactly', (125140, 0), 4251600),
  ('control: just beyond exhaustion', (125143, 0), 4251735), ('control: below allowance', (9000, 0), 0)]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The higher rate starts 12570 pounds too early.

solve(income, pension): stipulated allowance taper in whole pounds. Adjusted net income ani = income - pension. The personal allowance 12570 is reduced by 1 for every 2 whole pounds of ani above 100000 (floor of half the excess), never below 0. Taxable = max(0, ani - allowance). Taxable income is taxed 20% up to 37700, 40% from 37700 to 125140, 45% above 125140. Return tax in integer pence.

split: open-access


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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    use_n = min(n, t)
    t -= use_n
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-before-carry 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression nonref-before-carry 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('partial repair guard 2', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'), ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('regression nonref-before-carry 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]),
   [0, 350]),
  ('regression nonref-before-carry 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('partial repair guard 2', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-before-carry 1', (1000, [['carry', 0], ['nonref', 1810], ['carry', 123]]), [0, 123]),
  ('regression nonref-before-carry 2', (100, [['nonref', 300], ['carry', 853], ['carry', 0]]), [0, 853]),
  ('partial repair guard 1', (500, [['ref', 1249], ['ref', 300], ['carry', 300], ['carry', 1980]]), [-1549, 1780]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-before-carry 1', (100, [['nonref', 50], ['carry', 100], ['ref', 0]]), [0, 50]),
  ('regression nonref-before-carry 2', (500, [['nonref', 100], ['carry', 300], ['carry', 300]]), [0, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (1000, [['ref', 2008], ['ref', 50], ['nonref', 100]]), [-1158, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    t -= r
    use_n = min(n, max(0, t))
    t -= use_n
    use_c = min(c, max(0, t))
    t -= use_c
    cf = c - use_c
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-before-carry 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression nonref-before-carry 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('partial repair guard 2', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'), ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('regression nonref-before-carry 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-before-carry 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]),
   [0, 350]),
  ('regression nonref-before-carry 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('partial repair guard 2', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-before-carry 1', (1000, [['carry', 0], ['nonref', 1810], ['carry', 123]]), [0, 123]),
  ('regression nonref-before-carry 2', (100, [['nonref', 300], ['carry', 853], ['carry', 0]]), [0, 853]),
  ('partial repair guard 1', (500, [['ref', 1249], ['ref', 300], ['carry', 300], ['carry', 1980]]), [-1549, 1780]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-before-carry 1', (100, [['nonref', 50], ['carry', 100], ['ref', 0]]), [0, 50]),
  ('regression nonref-before-carry 2', (500, [['nonref', 100], ['carry', 300], ['carry', 300]]), [0, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (1000, [['ref', 2008], ['ref', 50], ['nonref', 100]]), [-1158, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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:
Expiring nonrefundable credits are wasted while carryable credits are used up.

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

split: open-access


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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = n
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-limit 1', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('regression nonref-limit 2', (300, [['nonref', 500]]), [0, 0]),
  ('partial repair guard 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind')],
 [('regression nonref-limit 1', (0, [['nonref', 1308]]), [0, 0]),
  ('regression nonref-limit 2', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-limit 1', (0, [['nonref', 100], ['carry', 0], ['ref', 0], ['nonref', 50]]), [0, 0]),
  ('regression nonref-limit 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (0, [['ref', 100], ['nonref', 50], ['carry', 100], ['ref', 130]]), [-230, 100]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-limit 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('regression nonref-limit 2', (0, [['nonref', 889]]), [0, 0]),
  ('partial repair guard 1', (0, [['nonref', 100], ['carry', 100], ['ref', 1667]]), [-1667, 100]),
  ('partial repair guard 2', (100, [['nonref', 2372], ['carry', 100], ['carry', 50], ['ref', 300]]), [-300, 150]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-limit 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]), [0, 350]),
  ('regression nonref-limit 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('partial repair guard 1', (100, [['nonref', 100], ['ref', 50], ['nonref', 300], ['ref', 1614]]), [-1664, 0]),
  ('partial repair guard 2', (100, [['carry', 0], ['nonref', 1027], ['ref', 2757]]), [-2757, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t + r)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression nonref-limit 1', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('regression nonref-limit 2', (300, [['nonref', 500]]), [0, 0]),
  ('partial repair guard 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind')],
 [('regression nonref-limit 1', (0, [['nonref', 1308]]), [0, 0]),
  ('regression nonref-limit 2', (1467, [['nonref', 0], ['carry', 50], ['nonref', 2387]]), [0, 50]),
  ('partial repair guard 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('partial repair guard 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression nonref-limit 1', (0, [['nonref', 100], ['carry', 0], ['ref', 0], ['nonref', 50]]), [0, 0]),
  ('regression nonref-limit 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('partial repair guard 1', (100, [['ref', 50], ['nonref', 300], ['ref', 380]]), [-430, 0]),
  ('partial repair guard 2', (0, [['ref', 100], ['nonref', 50], ['carry', 100], ['ref', 130]]), [-230, 100]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression nonref-limit 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('regression nonref-limit 2', (0, [['nonref', 889]]), [0, 0]),
  ('partial repair guard 1', (0, [['nonref', 100], ['carry', 100], ['ref', 1667]]), [-1667, 100]),
  ('partial repair guard 2', (100, [['nonref', 2372], ['carry', 100], ['carry', 50], ['ref', 300]]), [-300, 150]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression nonref-limit 1', (100, [['carry', 300], ['nonref', 300], ['carry', 50], ['nonref', 2635]]), [0, 350]),
  ('regression nonref-limit 2', (100, [['ref', 50], ['nonref', 2064]]), [-50, 0]),
  ('partial repair guard 1', (100, [['nonref', 100], ['ref', 50], ['nonref', 300], ['ref', 1614]]), [-1664, 0]),
  ('partial repair guard 2', (100, [['carry', 0], ['nonref', 1027], ['ref', 2757]]), [-2757, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A nonrefundable credit larger than the tax pays out cash.

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

split: open-access


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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression carryforward-amount 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression carryforward-amount 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0])],
 [('regression carryforward-amount 1', (500, [['carry', 50], ['carry', 1626], ['carry', 2439], ['carry', 2757]]),
   [0, 6372]),
  ('regression carryforward-amount 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression carryforward-amount 1', (2284, [['carry', 50], ['ref', 300]]), [1934, 0]),
  ('regression carryforward-amount 2', (1112, [['carry', 300]]), [812, 0]),
  ('partial repair guard 1', (500, [['carry', 300]]), [200, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression carryforward-amount 1', (500, [['carry', 300]]), [200, 0]),
  ('regression carryforward-amount 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 1', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 2', (1000, [['ref', 50], ['carry', 0], ['carry', 483], ['nonref', 50]]), [417, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression carryforward-amount 1', (500, [['carry', 100]]), [400, 0]),
  ('regression carryforward-amount 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (100, [['carry', 100], ['carry', 0]]), [0, 0]),
  ('partial repair guard 2', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = max(0, c - t)
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression carryforward-amount 1', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('regression carryforward-amount 2', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0])],
 [('regression carryforward-amount 1', (500, [['carry', 50], ['carry', 1626], ['carry', 2439], ['carry', 2757]]),
   [0, 6372]),
  ('regression carryforward-amount 2', (1000, [['carry', 300], ['nonref', 100], ['nonref', 100], ['nonref', 765]]),
   [0, 265]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression carryforward-amount 1', (2284, [['carry', 50], ['ref', 300]]), [1934, 0]),
  ('regression carryforward-amount 2', (1112, [['carry', 300]]), [812, 0]),
  ('partial repair guard 1', (500, [['carry', 300]]), [200, 0]),
  ('partial repair guard 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression carryforward-amount 1', (500, [['carry', 300]]), [200, 0]),
  ('regression carryforward-amount 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 1', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 2', (1000, [['ref', 50], ['carry', 0], ['carry', 483], ['nonref', 50]]), [417, 0]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression carryforward-amount 1', (500, [['carry', 100]]), [400, 0]),
  ('regression carryforward-amount 2', (500, [['carry', 2501], ['carry', 0], ['nonref', 300], ['ref', 0]]), [0, 2301]),
  ('partial repair guard 1', (100, [['carry', 100], ['carry', 0]]), [0, 0]),
  ('partial repair guard 2', (500, [['ref', 300], ['carry', 2443]]), [-300, 1943]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The full carry credit is carried forward even after it reduced this year's tax.

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

split: open-access


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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t = max(0, t - r)
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression refundable-limit 1', (500, [['ref', 700]]), [-200, 0]),
  ('regression refundable-limit 2', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('partial repair guard 2', (0, [['carry', 300], ['ref', 50]]), [-50, 300]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression refundable-limit 1', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('regression refundable-limit 2', (0, [['carry', 300], ['ref', 50]]), [-50, 300]),
  ('partial repair guard 1', (0, [['ref', 2834], ['carry', 0]]), [-2834, 0]),
  ('partial repair guard 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200])],
 [('regression refundable-limit 1', (0, [['ref', 2834], ['carry', 0]]), [-2834, 0]),
  ('regression refundable-limit 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('partial repair guard 1', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 2', (100, [['ref', 300]]), [-200, 0]), ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression refundable-limit 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('regression refundable-limit 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['ref', 300], ['ref', 300], ['ref', 100]]), [-650, 0]),
  ('partial repair guard 2', (0, [['ref', 100], ['carry', 100]]), [-100, 100]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression refundable-limit 1', (100, [['ref', 300]]), [-200, 0]),
  ('regression refundable-limit 2', (100, [['ref', 50], ['ref', 300], ['ref', 300], ['ref', 100]]), [-650, 0]),
  ('partial repair guard 1', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('partial repair guard 2', (500, [['ref', 50], ['ref', 50], ['nonref', 0], ['ref', 2444]]), [-2044, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind not in tot: return 'ERR:kind'
        tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= min(r, tax)
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression refundable-limit 1', (500, [['ref', 700]]), [-200, 0]),
  ('regression refundable-limit 2', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('partial repair guard 2', (0, [['carry', 300], ['ref', 50]]), [-50, 300]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression refundable-limit 1', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('regression refundable-limit 2', (0, [['carry', 300], ['ref', 50]]), [-50, 300]),
  ('partial repair guard 1', (0, [['ref', 2834], ['carry', 0]]), [-2834, 0]),
  ('partial repair guard 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200])],
 [('regression refundable-limit 1', (0, [['ref', 2834], ['carry', 0]]), [-2834, 0]),
  ('regression refundable-limit 2', (0, [['nonref', 100], ['ref', 0], ['ref', 50], ['carry', 300]]), [-50, 300]),
  ('partial repair guard 1', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 2', (100, [['ref', 300]]), [-200, 0]), ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression refundable-limit 1', (444, [['nonref', 806], ['ref', 2], ['nonref', 464], ['ref', 0]]), [-2, 0]),
  ('regression refundable-limit 2', (100, [['ref', 931], ['carry', 300], ['ref', 50]]), [-981, 200]),
  ('partial repair guard 1', (100, [['ref', 50], ['ref', 300], ['ref', 300], ['ref', 100]]), [-650, 0]),
  ('partial repair guard 2', (0, [['ref', 100], ['carry', 100]]), [-100, 100]),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression refundable-limit 1', (100, [['ref', 300]]), [-200, 0]),
  ('regression refundable-limit 2', (100, [['ref', 50], ['ref', 300], ['ref', 300], ['ref', 100]]), [-650, 0]),
  ('partial repair guard 1', (500, [['carry', 100], ['nonref', 100], ['ref', 634], ['nonref', 100]]), [-434, 0]),
  ('partial repair guard 2', (500, [['ref', 50], ['ref', 50], ['nonref', 0], ['ref', 2444]]), [-2044, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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:
Refundable credits never produce a refund.

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

split: open-access


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

N = 1
observations = []
def solve(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        if kind in tot: tot[kind] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression unknown-credit-kind 1', (100, [['bonus', 5]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (1000, [['other', 100]]), 'ERR:kind'),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0])],
 [('regression unknown-credit-kind 1', (0, [['carry', 1689], ['ref', 50], ['nonref', 50], ['other', 300]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (1935, [['nonref', 100], ['ref', 0], ['ref', 0], ['other', 300]]), 'ERR:kind'),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression unknown-credit-kind 1', (0, [['other', 0], ['carry', 300], ['nonref', 50], ['ref', 1736]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['other', 50], ['ref', 50], ['ref', 182], ['carry', 300]]), 'ERR:kind'),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression unknown-credit-kind 1', (0, [['nonref', 300], ['nonref', 100], ['other', 300]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['ref', 1350], ['other', 1002]]), 'ERR:kind'),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression unknown-credit-kind 1', (832, [['nonref', 100], ['other', 50]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['other', 50]]), 'ERR:kind'),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[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(tax, credits):
    tot = {'nonref': 0, 'carry': 0, 'ref': 0}
    for kind, amount in credits:
        tot[kind if kind in tot else 'nonref'] += amount
    n, c, r = tot['nonref'], tot['carry'], tot['ref']
    t = tax
    use_n = min(n, t)
    t -= use_n
    use_c = min(c, t)
    t -= use_c
    cf = c - use_c
    t -= r
    return [t, cf]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression unknown-credit-kind 1', (100, [['bonus', 5]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (1000, [['other', 100]]), 'ERR:kind'),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0])],
 [('regression unknown-credit-kind 1', (0, [['carry', 1689], ['ref', 50], ['nonref', 50], ['other', 300]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (1935, [['nonref', 100], ['ref', 0], ['ref', 0], ['other', 300]]), 'ERR:kind'),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0])],
 [('regression unknown-credit-kind 1', (0, [['other', 0], ['carry', 300], ['nonref', 50], ['ref', 1736]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['other', 50], ['ref', 50], ['ref', 182], ['carry', 300]]), 'ERR:kind'),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0]), ('control: no tax carry', (0, [['carry', 50]]), [0, 50])],
 [('regression unknown-credit-kind 1', (0, [['nonref', 300], ['nonref', 100], ['other', 300]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['ref', 1350], ['other', 1002]]), 'ERR:kind'),
  ('control: no tax carry', (0, [['carry', 50]]), [0, 50]),
  ('control: unknown kind', (100, [['bonus', 5]]), 'ERR:kind'),
  ('control: nonref exceeds tax', (300, [['nonref', 500], ['ref', 100]]), [-100, 0]),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200])],
 [('regression unknown-credit-kind 1', (832, [['nonref', 100], ['other', 50]]), 'ERR:kind'),
  ('regression unknown-credit-kind 2', (100, [['other', 50]]), 'ERR:kind'),
  ('control: split carries', (900, [['carry', 400], ['nonref', 600], ['carry', 100]]), [0, 200]),
  ('control: empty', (1234, []), [1234, 0]),
  ('control: all kinds', (1000, [['nonref', 400], ['carry', 800], ['ref', 300]]), [-300, 200]),
  ('control: refund', (500, [['ref', 700]]), [-200, 0])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A mistyped credit code disappears from the computation without an error.

solve(tax, credits): tax is integer cents >= 0; credits is a list of [kind, cents] with kind 'nonref' (nonrefundable, unused part lost), 'carry' (nonrefundable, unused part carried forward) or 'ref' (refundable). Unknown kinds return 'ERR:kind'. Apply all nonref credits first (limited to the remaining tax), then carry credits (limited to what remains), then refundable credits in full (a negative result is a refund). Return [final_tax, carryforward].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable < upper)
    eff = cents(tax * 100 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582])],
 [('regression threshold-membership 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression threshold-membership 2', (40000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1150]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0])],
 [('regression threshold-membership 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression threshold-membership 2', (40000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1150]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable < upper or taxable == 0)
    eff = cents(tax * 100 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582])],
 [('regression threshold-membership 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression threshold-membership 2', (40000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1150]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0])],
 [('regression threshold-membership 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression threshold-membership 2', (40000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1150]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression threshold-membership 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression threshold-membership 2', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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:
Someone with taxable income exactly 40000 is told their marginal rate is 22%.

solve(gross, deduction, brackets): taxable = max(0, gross - deduction); tax uses the progressive slices. The marginal rate is the rate of the bracket containing taxable income with (lower, upper] semantics (income exactly at a threshold is in the lower bracket), and is '0' when gross < deduction (unused deduction absorbs the next dollar; at gross == deduction the next dollar is taxed at the first rate). The effective rate is tax / gross in basis points rounded half-up (0 when gross <= 0). Return [marginal_rate_string, effective_bps].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = cents(tax * 100 / taxable) if taxable > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression effective-denominator 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression effective-denominator 2',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('partial repair guard 2', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-denominator 1', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('regression effective-denominator 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 1', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('partial repair guard 2',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842])],
 [('regression effective-denominator 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('regression effective-denominator 2',
   (10000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['10', 700]),
  ('partial repair guard 1', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('partial repair guard 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression effective-denominator 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('regression effective-denominator 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('partial repair guard 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('partial repair guard 2',
   (10000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['10', 700]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-denominator 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression effective-denominator 2',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('partial repair guard 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('partial repair guard 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = cents(prog(gross, brackets) * 100 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression effective-denominator 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('regression effective-denominator 2',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('partial repair guard 2', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-denominator 1', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('regression effective-denominator 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 1', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('partial repair guard 2',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842])],
 [('regression effective-denominator 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('regression effective-denominator 2',
   (10000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['10', 700]),
  ('partial repair guard 1', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('partial repair guard 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression effective-denominator 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('regression effective-denominator 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('partial repair guard 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('partial repair guard 2',
   (10000, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['10', 700]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-denominator 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('regression effective-denominator 2',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('partial repair guard 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('partial repair guard 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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:
Effective rates are overstated for every filer with a deduction.

solve(gross, deduction, brackets): taxable = max(0, gross - deduction); tax uses the progressive slices. The marginal rate is the rate of the bracket containing taxable income with (lower, upper] semantics (income exactly at a threshold is in the lower bracket), and is '0' when gross < deduction (unused deduction absorbs the next dollar; at gross == deduction the next dollar is taxed at the first rate). The effective rate is tax / gross in basis points rounded half-up (0 when gross <= 0). Return [marginal_rate_string, effective_bps].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = int(tax * 10000 / gross) if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression effective-rounding 1',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('regression effective-rounding 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('partial repair guard 2', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-rounding 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('regression effective-rounding 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('partial repair guard 1',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('partial repair guard 2', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])],
 [('regression effective-rounding 1',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('regression effective-rounding 2',
   (272814, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['32.5', 2267]),
  ('partial repair guard 1',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 2', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression effective-rounding 1',
   (13000, 0, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 1031]),
  ('regression effective-rounding 2',
   (236107, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['32.5', 2114]),
  ('partial repair guard 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('partial repair guard 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-rounding 1',
   (50000, 0, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1262]),
  ('regression effective-rounding 2', (54600, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1431]),
  ('partial repair guard 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('partial repair guard 2',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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
from fractions import Fraction
N = 1
observations = []
def solve(gross, deduction, brackets):
    def prog(x, br):
        tax, lower = Fraction(0), 0
        for upper, rate in br:
            top = x if upper is None else min(x, upper)
            if top > lower: tax += (top - lower) * Fraction(rate) / 100
            if upper is None or x <= upper: break
            lower = upper
        return tax
    def cents(v):
        v = v * 100
        return int(v + Fraction(1, 2)) if v >= 0 else -int(-v + Fraction(1, 2))

    taxable = max(0, gross - deduction)
    tax = prog(taxable, brackets)
    if gross < deduction:
        marginal = '0'
    else:
        marginal = next(rate for upper, rate in brackets if upper is None or taxable <= upper)
    eff = cents(tax / gross) * 100 if gross > 0 else 0
    return [marginal, eff]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression effective-rounding 1',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('regression effective-rounding 2',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 1', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('partial repair guard 2', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-rounding 1', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('regression effective-rounding 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('partial repair guard 1',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('partial repair guard 2', (50000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1228]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])],
 [('regression effective-rounding 1',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('regression effective-rounding 2',
   (272814, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['32.5', 2267]),
  ('partial repair guard 1',
   (54600, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 839]),
  ('partial repair guard 2', (50000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 810]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000]),
  ('control: at threshold after deduction', (54600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 842]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360])],
 [('regression effective-rounding 1',
   (13000, 0, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 1031]),
  ('regression effective-rounding 2',
   (236107, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['32.5', 2114]),
  ('partial repair guard 1', (108005, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1750]),
  ('partial repair guard 2',
   (54600, 3000, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1220]),
  ('control: top bracket', (50000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1360]),
  ('control: exact first threshold', (10000, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 1000]),
  ('control: deduction not exhausted', (10000, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['0', 0]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0])],
 [('regression effective-rounding 1',
   (50000, 0, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['22', 1262]),
  ('regression effective-rounding 2', (54600, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['22', 1431]),
  ('partial repair guard 1', (13000, 3000, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 769]),
  ('partial repair guard 2',
   (39261, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['12', 698]),
  ('control: deduction exactly used', (14600, 14600, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: five brackets',
   (123456, 14600, [[11000, '10'], [44725, '12'], [95375, '22'], [182100, '24'], [None, '32.5']]), ['24', 1582]),
  ('control: zero gross', (0, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['10', 0]),
  ('control: one above threshold', (10001, 0, [[10000, '10'], [40000, '12'], [None, '22']]), ['12', 1000])]]
for label, args, expected in cases[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 effective rate of 8.4296% is reported as 842 bps instead of 843 bps.

solve(gross, deduction, brackets): taxable = max(0, gross - deduction); tax uses the progressive slices. The marginal rate is the rate of the bracket containing taxable income with (lower, upper] semantics (income exactly at a threshold is in the lower bracket), and is '0' when gross < deduction (unused deduction absorbs the next dollar; at gross == deduction the next dollar is taxed at the first rate). The effective rate is tax / gross in basis points rounded half-up (0 when gross <= 0). Return [marginal_rate_string, effective_bps].

split: open-access