broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(profits, dividends, associates, days):
    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))

    div = associates + 1
    L = Fraction(50000 * days, 365 * div)
    U = Fraction(250000 * days, 365 * div)
    A = profits
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A) * N / A
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression augmented-profits 1', (100000, 25000, 0, 365), 2350000),
  ('regression augmented-profits 2', (200000, 60000, 0, 365), 5000000),
  ('partial repair guard 2', (100000, 5000, 1, 365), 2471429), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500)],
 [('regression augmented-profits 1', (100000, 5000, 1, 365), 2471429),
  ('regression augmented-profits 2', (50000, 25000, 0, 365), 1075000), ('partial repair guard 1', (0, 5000, 4, 181), 0),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000)],
 [('regression augmented-profits 1', (100000, 5000, 0, 300), 2356458),
  ('regression augmented-profits 2', (50000, 60000, 0, 365), 1154545),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression augmented-profits 1', (30000, 5000, 0, 200), 618875),
  ('regression augmented-profits 2', (30000, 25000, 4, 365), 750000), ('partial repair guard 1', (0, 25000, 0, 181), 0),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression augmented-profits 1', (50000, 60000, 0, 90), 1250000),
  ('regression augmented-profits 2', (50000, 5000, 0, 300), 1044801),
  ('partial repair guard 2', (180000, 60000, 0, 365), 4488750),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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(profits, dividends, associates, days):
    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))

    div = associates + 1
    L = Fraction(50000 * days, 365 * div)
    U = Fraction(250000 * days, 365 * div)
    A = profits + dividends
    N = Fraction(profits)
    if A <= L: tax = N * 19 / 100
    elif A >= U: tax = N * 25 / 100
    else: tax = N * 25 / 100 - Fraction(3, 200) * (U - A)
    return cents(tax)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression augmented-profits 1', (100000, 25000, 0, 365), 2350000),
  ('regression augmented-profits 2', (200000, 60000, 0, 365), 5000000),
  ('partial repair guard 2', (100000, 5000, 1, 365), 2471429), ('control: small profits', (40000, 0, 0, 365), 760000),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500)],
 [('regression augmented-profits 1', (100000, 5000, 1, 365), 2471429),
  ('regression augmented-profits 2', (50000, 25000, 0, 365), 1075000), ('partial repair guard 1', (0, 5000, 4, 181), 0),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000)],
 [('regression augmented-profits 1', (100000, 5000, 0, 300), 2356458),
  ('regression augmented-profits 2', (50000, 60000, 0, 365), 1154545),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000),
  ('control: small profits', (40000, 0, 0, 365), 760000), ('control: relief zone', (100000, 0, 0, 365), 2275000)],
 [('regression augmented-profits 1', (30000, 5000, 0, 200), 618875),
  ('regression augmented-profits 2', (30000, 25000, 4, 365), 750000), ('partial repair guard 1', (0, 25000, 0, 181), 0),
  ('control: relief zone', (100000, 0, 0, 365), 2275000), ('control: main rate', (300000, 0, 0, 365), 7500000),
  ('control: associated company', (60000, 0, 1, 365), 1402500),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000)],
 [('regression augmented-profits 1', (50000, 60000, 0, 90), 1250000),
  ('regression augmented-profits 2', (50000, 5000, 0, 300), 1044801),
  ('partial repair guard 2', (180000, 60000, 0, 365), 4488750),
  ('control: with dividends', (100000, 25000, 0, 365), 2350000), ('control: short period', (30000, 0, 0, 181), 609041),
  ('control: two associates short', (70000, 5000, 2, 200), 1750000),
  ('control: dividends push to main rate', (200000, 60000, 0, 365), 5000000)]]
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 company whose dividends lift it above the limit keeps small-profits treatment.

solve(profits, dividends, associates, days): stipulated small-profits relief. Limits L = 50000 and U = 250000 are divided by (associates + 1) and prorated by days/365 (exact fractions). Augmented profits A = profits + dividends decide the band: A <= L taxes profits N at 19%; A >= U at 25%; otherwise tax = 25% of N minus 3/200 * (U - A) * N / A. Return integer cents rounded half-up.

split: open-access


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

N = 1
observations = []
def solve(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression first-time-buyer-cap 1', (625001, True, False, False), 18750),
  ('regression first-time-buyer-cap 2', (925000, True, False, False), 33750),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500)],
 [('regression first-time-buyer-cap 1', (2087334, True, False, False), 161730),
  ('regression first-time-buyer-cap 2', (1462530, True, False, False), 87503),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression first-time-buyer-cap 1', (1130152, True, False, False), 54265),
  ('regression first-time-buyer-cap 2', (1943189, True, False, True), 183296),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression first-time-buyer-cap 1', (906584, True, False, False), 32829),
  ('regression first-time-buyer-cap 2', (1946173, True, False, False), 144790),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression first-time-buyer-cap 1', (625001, True, False, True), 31250),
  ('regression first-time-buyer-cap 2', (2255703, True, False, True), 227048),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500)]]
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(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price < 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression first-time-buyer-cap 1', (625001, True, False, False), 18750),
  ('regression first-time-buyer-cap 2', (925000, True, False, False), 33750),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500)],
 [('regression first-time-buyer-cap 1', (2087334, True, False, False), 161730),
  ('regression first-time-buyer-cap 2', (1462530, True, False, False), 87503),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression first-time-buyer-cap 1', (1130152, True, False, False), 54265),
  ('regression first-time-buyer-cap 2', (1943189, True, False, True), 183296),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression first-time-buyer-cap 1', (906584, True, False, False), 32829),
  ('regression first-time-buyer-cap 2', (1946173, True, False, False), 144790),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression first-time-buyer-cap 1', (625001, True, False, True), 31250),
  ('regression first-time-buyer-cap 2', (2255703, True, False, True), 227048),
  ('partial repair guard 1', (625000, True, False, False), 10000),
  ('partial repair guard 2', (625000, True, False, True), 22500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500)]]
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 700000 purchase by a first-time buyer is taxed only on the 425000-625000 slice.

solve(price, ftb, additional, nonresident): stipulated property transfer tax in whole pounds. Normal slices: 0% to 250000, 5% to 925000, 10% to 1500000, 12% above. First-time-buyer slices (0% to 425000, 5% to 625000) apply only when ftb is true, the purchase is not an additional dwelling, and price <= 625000; otherwise normal slices. Surcharges add percentage points to every slice including 0% slices: +3 for an additional dwelling when price >= 40000, +2 for a non-resident buyer; they stack. Return the tax rounded down to whole pounds.

split: open-access


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

N = 1
observations = []
def solve(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * ((rate + sur) if rate else 0)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression surcharge-zero-slice 1', (300000, False, True, True), 17500),
  ('regression surcharge-zero-slice 2', (39999, False, False, True), 799),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression surcharge-zero-slice 1', (300000, False, True, False), 11500),
  ('regression surcharge-zero-slice 2', (400000, True, True, False), 19500),
  ('partial repair guard 1', (625000, False, True, True), 50000),
  ('partial repair guard 2', (40000, False, False, True), 800),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799)],
 [('regression surcharge-zero-slice 1', (625000, False, True, True), 50000),
  ('regression surcharge-zero-slice 2', (40000, False, True, False), 1200),
  ('partial repair guard 1', (250001, True, False, True), 5000),
  ('partial repair guard 2', (628677, True, True, True), 50367),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression surcharge-zero-slice 1', (40000, False, False, True), 800),
  ('regression surcharge-zero-slice 2', (625001, True, True, False), 37500),
  ('partial repair guard 1', (250001, False, True, True), 12500),
  ('partial repair guard 2', (625001, False, False, True), 31250),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression surcharge-zero-slice 1', (925000, False, True, False), 61500),
  ('regression surcharge-zero-slice 2', (919321, True, True, False), 61045),
  ('partial repair guard 1', (250001, False, False, True), 5000),
  ('partial repair guard 2', (2021858, False, False, True), 194310),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * ((rate + sur) if rate else (3 if additional and price >= 40000 else 0))
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression surcharge-zero-slice 1', (300000, False, True, True), 17500),
  ('regression surcharge-zero-slice 2', (39999, False, False, True), 799),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression surcharge-zero-slice 1', (300000, False, True, False), 11500),
  ('regression surcharge-zero-slice 2', (400000, True, True, False), 19500),
  ('partial repair guard 1', (625000, False, True, True), 50000),
  ('partial repair guard 2', (40000, False, False, True), 800),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799)],
 [('regression surcharge-zero-slice 1', (625000, False, True, True), 50000),
  ('regression surcharge-zero-slice 2', (40000, False, True, False), 1200),
  ('partial repair guard 1', (250001, True, False, True), 5000),
  ('partial repair guard 2', (628677, True, True, True), 50367),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression surcharge-zero-slice 1', (40000, False, False, True), 800),
  ('regression surcharge-zero-slice 2', (625001, True, True, False), 37500),
  ('partial repair guard 1', (250001, False, True, True), 12500),
  ('partial repair guard 2', (625001, False, False, True), 31250),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression surcharge-zero-slice 1', (925000, False, True, False), 61500),
  ('regression surcharge-zero-slice 2', (919321, True, True, False), 61045),
  ('partial repair guard 1', (250001, False, False, True), 5000),
  ('partial repair guard 2', (2021858, False, False, True), 194310),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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:
Additional-dwelling purchases under 250000 pay no surcharge.

solve(price, ftb, additional, nonresident): stipulated property transfer tax in whole pounds. Normal slices: 0% to 250000, 5% to 925000, 10% to 1500000, 12% above. First-time-buyer slices (0% to 425000, 5% to 625000) apply only when ftb is true, the purchase is not an additional dwelling, and price <= 625000; otherwise normal slices. Surcharges add percentage points to every slice including 0% slices: +3 for an additional dwelling when price >= 40000, +2 for a non-resident buyer; they stack. Return the tax rounded down to whole pounds.

split: open-access


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

N = 1
observations = []
def solve(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return (tax + 50) // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression round-down-pounds 1', (250013, False, False, False), 0),
  ('regression round-down-pounds 2', (250019, False, False, False), 0),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression round-down-pounds 1', (39999, False, False, True), 799),
  ('regression round-down-pounds 2', (919321, True, True, False), 61045),
  ('partial repair guard 1', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: ftb additional', (400000, True, True, False), 19500)],
 [('regression round-down-pounds 1', (575918, True, False, False), 7545),
  ('regression round-down-pounds 2', (628677, True, True, True), 50367),
  ('partial repair guard 1', (625001, True, True, False), 37500),
  ('partial repair guard 2', (919321, True, True, False), 61045),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression round-down-pounds 1', (665697, False, False, False), 20784),
  ('regression round-down-pounds 2', (330173, False, False, False), 4008),
  ('partial repair guard 1', (250001, False, False, False), 0),
  ('partial repair guard 2', (625001, False, False, False), 18750),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression round-down-pounds 1', (1296206, False, True, False), 109756),
  ('regression round-down-pounds 2', (558699, True, False, False), 6684),
  ('partial repair guard 1', (250001, True, False, True), 5000),
  ('partial repair guard 2', (2087334, True, False, False), 161730),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return -(-tax // 100)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression round-down-pounds 1', (250013, False, False, False), 0),
  ('regression round-down-pounds 2', (250019, False, False, False), 0),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression round-down-pounds 1', (39999, False, False, True), 799),
  ('regression round-down-pounds 2', (919321, True, True, False), 61045),
  ('partial repair guard 1', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: ftb additional', (400000, True, True, False), 19500)],
 [('regression round-down-pounds 1', (575918, True, False, False), 7545),
  ('regression round-down-pounds 2', (628677, True, True, True), 50367),
  ('partial repair guard 1', (625001, True, True, False), 37500),
  ('partial repair guard 2', (919321, True, True, False), 61045),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression round-down-pounds 1', (665697, False, False, False), 20784),
  ('regression round-down-pounds 2', (330173, False, False, False), 4008),
  ('partial repair guard 1', (250001, False, False, False), 0),
  ('partial repair guard 2', (625001, False, False, False), 18750),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression round-down-pounds 1', (1296206, False, True, False), 109756),
  ('regression round-down-pounds 2', (558699, True, False, False), 6684),
  ('partial repair guard 1', (250001, True, False, True), 5000),
  ('partial repair guard 2', (2087334, True, False, False), 161730),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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:
Some liabilities are one pound higher than stipulated.

solve(price, ftb, additional, nonresident): stipulated property transfer tax in whole pounds. Normal slices: 0% to 250000, 5% to 925000, 10% to 1500000, 12% above. First-time-buyer slices (0% to 425000, 5% to 625000) apply only when ftb is true, the purchase is not an additional dwelling, and price <= 625000; otherwise normal slices. Surcharges add percentage points to every slice including 0% slices: +3 for an additional dwelling when price >= 40000, +2 for a non-resident buyer; they stack. Return the tax rounded down to whole pounds.

split: open-access


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

N = 1
observations = []
def solve(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression ftb-with-additional 1', (400000, True, True, False), 19500),
  ('regression ftb-with-additional 2', (625000, True, True, False), 37500),
  ('partial repair guard 2', (625001, True, True, False), 37500),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression ftb-with-additional 1', (349659, True, True, False), 15472),
  ('regression ftb-with-additional 2', (625000, True, True, True), 50000),
  ('partial repair guard 1', (919321, True, True, False), 61045),
  ('partial repair guard 2', (925000, True, True, False), 61500),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression ftb-with-additional 1', (539991, True, True, False), 30699),
  ('regression ftb-with-additional 2', (488087, True, True, False), 26546),
  ('partial repair guard 1', (628677, True, True, True), 50367),
  ('partial repair guard 2', (250001, True, True, False), 7500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression ftb-with-additional 1', (402343, True, True, False), 19687),
  ('regression ftb-with-additional 2', (523207, True, True, False), 29356),
  ('partial repair guard 1', (625000, True, True, False), 37500),
  ('partial repair guard 2', (40000, True, True, False), 1200),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression ftb-with-additional 1', (459827, True, True, False), 24286),
  ('regression ftb-with-additional 2', (443484, True, True, True), 31848),
  ('partial repair guard 1', (625001, True, True, True), 50000),
  ('partial repair guard 2', (745541, True, True, True), 62054),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = (3 if additional and not ftb and price >= 40000 else 0) + (2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression ftb-with-additional 1', (400000, True, True, False), 19500),
  ('regression ftb-with-additional 2', (625000, True, True, False), 37500),
  ('partial repair guard 2', (625001, True, True, False), 37500),
  ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression ftb-with-additional 1', (349659, True, True, False), 15472),
  ('regression ftb-with-additional 2', (625000, True, True, True), 50000),
  ('partial repair guard 1', (919321, True, True, False), 61045),
  ('partial repair guard 2', (925000, True, True, False), 61500),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression ftb-with-additional 1', (539991, True, True, False), 30699),
  ('regression ftb-with-additional 2', (488087, True, True, False), 26546),
  ('partial repair guard 1', (628677, True, True, True), 50367),
  ('partial repair guard 2', (250001, True, True, False), 7500),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: nonresident cheap', (39999, False, False, True), 799),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250)],
 [('regression ftb-with-additional 1', (402343, True, True, False), 19687),
  ('regression ftb-with-additional 2', (523207, True, True, False), 29356),
  ('partial repair guard 1', (625000, True, True, False), 37500),
  ('partial repair guard 2', (40000, True, True, False), 1200),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression ftb-with-additional 1', (459827, True, True, False), 24286),
  ('regression ftb-with-additional 2', (443484, True, True, True), 31848),
  ('partial repair guard 1', (625001, True, True, True), 50000),
  ('partial repair guard 2', (745541, True, True, True), 62054),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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 buyer flagged as both first-time and additional-dwelling gets relief plus a surcharge on relief slices.

solve(price, ftb, additional, nonresident): stipulated property transfer tax in whole pounds. Normal slices: 0% to 250000, 5% to 925000, 10% to 1500000, 12% above. First-time-buyer slices (0% to 425000, 5% to 625000) apply only when ftb is true, the purchase is not an additional dwelling, and price <= 625000; otherwise normal slices. Surcharges add percentage points to every slice including 0% slices: +3 for an additional dwelling when price >= 40000, +2 for a non-resident buyer; they stack. Return the tax rounded down to whole pounds.

split: open-access


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

N = 1
observations = []
def solve(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = max(3 if additional and price >= 40000 else 0, 2 if nonresident else 0)
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression surcharge-stacking 1', (300000, False, True, True), 17500),
  ('regression surcharge-stacking 2', (625000, False, True, True), 50000),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression surcharge-stacking 1', (628677, True, True, True), 50367),
  ('regression surcharge-stacking 2', (250001, False, True, True), 12500),
  ('partial repair guard 1', (39999, True, True, True), 799),
  ('partial repair guard 2', (39999, True, False, True), 799),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression surcharge-stacking 1', (625001, True, True, True), 50000),
  ('regression surcharge-stacking 2', (1103643, False, True, True), 106796),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0)],
 [('regression surcharge-stacking 1', (925000, False, True, True), 80000),
  ('regression surcharge-stacking 2', (745541, True, True, True), 62054),
  ('partial repair guard 1', (39999, True, True, True), 799),
  ('partial repair guard 2', (39999, True, False, True), 799),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression surcharge-stacking 1', (625000, True, True, True), 50000),
  ('regression surcharge-stacking 2', (458948, False, True, True), 33394),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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(price, ftb, additional, nonresident):
    normal = [(250000, 0), (925000, 5), (1500000, 10), (None, 12)]
    first = [(425000, 0), (625000, 5)]
    use_ftb = ftb and not additional and price <= 625000
    bands = first if use_ftb else normal
    sur = ((3 if additional else 0) + (2 if nonresident else 0)) if price >= 40000 else 0
    tax, lower = 0, 0
    for upper, rate in bands:
        top = price if upper is None else min(price, upper)
        if top > lower: tax += (top - lower) * (rate + sur)
        if upper is None or price <= upper: break
        lower = upper
    return tax // 100
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression surcharge-stacking 1', (300000, False, True, True), 17500),
  ('regression surcharge-stacking 2', (625000, False, True, True), 50000),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750)],
 [('regression surcharge-stacking 1', (628677, True, True, True), 50367),
  ('regression surcharge-stacking 2', (250001, False, True, True), 12500),
  ('partial repair guard 1', (39999, True, True, True), 799),
  ('partial repair guard 2', (39999, True, False, True), 799),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500),
  ('control: additional nonresident', (300000, False, True, True), 17500),
  ('control: below surcharge floor', (39999, False, True, False), 0)],
 [('regression surcharge-stacking 1', (625001, True, True, True), 50000),
  ('regression surcharge-stacking 2', (1103643, False, True, True), 106796),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799),
  ('control: below surcharge floor', (39999, False, True, False), 0),
  ('control: ftb additional', (400000, True, True, False), 19500),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0)],
 [('regression surcharge-stacking 1', (925000, False, True, True), 80000),
  ('regression surcharge-stacking 2', (745541, True, True, True), 62054),
  ('partial repair guard 1', (39999, True, True, True), 799),
  ('partial repair guard 2', (39999, True, False, True), 799),
  ('control: expensive', (2000000, False, False, False), 151250),
  ('control: odd pounds', (250013, False, False, False), 0), ('control: normal', (300000, False, False, False), 2500),
  ('control: first-time buyer', (500000, True, False, False), 3750)],
 [('regression surcharge-stacking 1', (625000, True, True, True), 50000),
  ('regression surcharge-stacking 2', (458948, False, True, True), 33394),
  ('partial repair guard 1', (39999, False, False, True), 799),
  ('partial repair guard 2', (39999, False, True, True), 799),
  ('control: first-time buyer', (500000, True, False, False), 3750),
  ('control: ftb at cap', (625000, True, False, False), 10000),
  ('control: ftb over cap', (625001, True, False, False), 18750),
  ('control: additional dwelling', (300000, False, True, False), 11500)]]
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:
Non-resident second-home buyers pay 3 surcharge points instead of 5.

solve(price, ftb, additional, nonresident): stipulated property transfer tax in whole pounds. Normal slices: 0% to 250000, 5% to 925000, 10% to 1500000, 12% above. First-time-buyer slices (0% to 425000, 5% to 625000) apply only when ftb is true, the purchase is not an additional dwelling, and price <= 625000; otherwise normal slices. Surcharges add percentage points to every slice including 0% slices: +3 for an additional dwelling when price >= 40000, +2 for a non-resident buyer; they stack. Return the tax rounded down to whole pounds.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression quotient-multiplier 1', (80000, 4, True), 10572),
  ('regression quotient-multiplier 2', (80000, 6, True), 7054), ('partial repair guard 2', (40000, 2, False), 5286),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921)],
 [('regression quotient-multiplier 1', (30000, 5, True), 194),
  ('regression quotient-multiplier 2', (250000, 8, True), 63921), ('partial repair guard 1', (80000, 6, True), 7054),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression quotient-multiplier 1', (40000, 7, False), 51),
  ('regression quotient-multiplier 2', (150000, 6, True), 28054), ('partial repair guard 1', (60000, 3, False), 9527),
  ('partial repair guard 2', (250000, 8, True), 63921), ('control: single one part', (40000, 2, False), 5286),
  ('control: couple two parts', (80000, 4, True), 10572), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194)],
 [('regression quotient-multiplier 1', (150000, 4, True), 31572),
  ('regression quotient-multiplier 2', (193969, 6, True), 44466), ('partial repair guard 1', (40000, 7, False), 51),
  ('partial repair guard 2', (150000, 6, True), 28054), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527)],
 [('regression quotient-multiplier 1', (150000, 8, True), 24536),
  ('regression quotient-multiplier 2', (40000, 5, True), 1294), ('partial repair guard 1', (80000, 6, False), 10250),
  ('partial repair guard 2', (150000, 4, True), 31572), ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return 2 * p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression quotient-multiplier 1', (80000, 4, True), 10572),
  ('regression quotient-multiplier 2', (80000, 6, True), 7054), ('partial repair guard 2', (40000, 2, False), 5286),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921)],
 [('regression quotient-multiplier 1', (30000, 5, True), 194),
  ('regression quotient-multiplier 2', (250000, 8, True), 63921), ('partial repair guard 1', (80000, 6, True), 7054),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression quotient-multiplier 1', (40000, 7, False), 51),
  ('regression quotient-multiplier 2', (150000, 6, True), 28054), ('partial repair guard 1', (60000, 3, False), 9527),
  ('partial repair guard 2', (250000, 8, True), 63921), ('control: single one part', (40000, 2, False), 5286),
  ('control: couple two parts', (80000, 4, True), 10572), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194)],
 [('regression quotient-multiplier 1', (150000, 4, True), 31572),
  ('regression quotient-multiplier 2', (193969, 6, True), 44466), ('partial repair guard 1', (40000, 7, False), 51),
  ('partial repair guard 2', (150000, 6, True), 28054), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527)],
 [('regression quotient-multiplier 1', (150000, 8, True), 24536),
  ('regression quotient-multiplier 2', (40000, 5, True), 1294), ('partial repair guard 1', (80000, 6, False), 10250),
  ('partial repair guard 2', (150000, 4, True), 31572), ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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 couple's tax is roughly halved.

solve(income, halves, couple): stipulated household quotient. Parts p = halves/2; the base is 2 parts for a couple and 1 otherwise (fewer halves than the base returns 'ERR:parts'). Tax with all parts = p * T(income/p) using slices 0% to 11294, 11% to 28797, 30% to 82341, 41% to 177106, 45% above. The benefit of each half-part beyond the base is capped at 1759: tax = max(full, T_base - 1759 * extra_halves) where T_base = base * T(income/base). Return whole units rounded down.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(min(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cap-direction 1', (80000, 6, True), 7054), ('regression cap-direction 2', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts')],
 [('regression cap-direction 1', (30000, 5, True), 194), ('regression cap-direction 2', (250000, 8, True), 63921),
  ('partial repair guard 1', (150000, 6, True), 28054), ('partial repair guard 2', (193969, 6, True), 44466),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression cap-direction 1', (40000, 7, False), 51), ('regression cap-direction 2', (40000, 8, True), 0),
  ('partial repair guard 1', (150000, 4, False), 42210), ('partial repair guard 2', (70423, 3, False), 12654),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression cap-direction 1', (150000, 6, True), 28054), ('regression cap-direction 2', (16143, 5, False), 0),
  ('partial repair guard 1', (287118, 5, True), 84416), ('partial repair guard 2', (247910, 5, True), 68341),
  ('control: couple with two children', (80000, 6, True), 7054), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527)],
 [('regression cap-direction 1', (80000, 6, False), 10250), ('regression cap-direction 2', (193969, 6, True), 44466),
  ('partial repair guard 1', (80000, 4, False), 13768), ('partial repair guard 2', (80000, 3, False), 15527),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(max(full, capped) if halves - 2 * base > 2 else full)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cap-direction 1', (80000, 6, True), 7054), ('regression cap-direction 2', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts')],
 [('regression cap-direction 1', (30000, 5, True), 194), ('regression cap-direction 2', (250000, 8, True), 63921),
  ('partial repair guard 1', (150000, 6, True), 28054), ('partial repair guard 2', (193969, 6, True), 44466),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression cap-direction 1', (40000, 7, False), 51), ('regression cap-direction 2', (40000, 8, True), 0),
  ('partial repair guard 1', (150000, 4, False), 42210), ('partial repair guard 2', (70423, 3, False), 12654),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression cap-direction 1', (150000, 6, True), 28054), ('regression cap-direction 2', (16143, 5, False), 0),
  ('partial repair guard 1', (287118, 5, True), 84416), ('partial repair guard 2', (247910, 5, True), 68341),
  ('control: couple with two children', (80000, 6, True), 7054), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527)],
 [('regression cap-direction 1', (80000, 6, False), 10250), ('regression cap-direction 2', (193969, 6, True), 44466),
  ('partial repair guard 1', (80000, 4, False), 13768), ('partial repair guard 2', (80000, 3, False), 15527),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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:
Families with extra parts pay less than the capped amount.

solve(income, halves, couple): stipulated household quotient. Parts p = halves/2; the base is 2 parts for a couple and 1 otherwise (fewer halves than the base returns 'ERR:parts'). Tax with all parts = p * T(income/p) using slices 0% to 11294, 11% to 28797, 30% to 82341, 41% to 177106, 45% above. The benefit of each half-part beyond the base is capped at 1759: tax = max(full, T_base - 1759 * extra_halves) where T_base = base * T(income/base). Return whole units rounded down.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * Fraction(halves - 2 * base, 2)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cap-unit 1', (80000, 6, True), 7054), ('regression cap-unit 2', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts')],
 [('regression cap-unit 1', (250000, 8, True), 63921), ('regression cap-unit 2', (40000, 7, False), 51),
  ('partial repair guard 1', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527), ('control: single one part', (40000, 2, False), 5286),
  ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression cap-unit 1', (150000, 6, True), 28054), ('regression cap-unit 2', (80000, 6, False), 10250),
  ('partial repair guard 1', (40000, 7, False), 51), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression cap-unit 1', (193969, 6, True), 44466), ('regression cap-unit 2', (150000, 8, True), 24536),
  ('partial repair guard 1', (80000, 6, False), 10250), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527)],
 [('regression cap-unit 1', (80000, 8, False), 6732), ('regression cap-unit 2', (274066, 8, True), 73788),
  ('partial repair guard 1', (150000, 8, True), 24536), ('partial repair guard 2', (40000, 5, True), 1294),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2 * base: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * ((halves - 2 * base) // 2)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression cap-unit 1', (80000, 6, True), 7054), ('regression cap-unit 2', (60000, 3, False), 9527),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts')],
 [('regression cap-unit 1', (250000, 8, True), 63921), ('regression cap-unit 2', (40000, 7, False), 51),
  ('partial repair guard 1', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527), ('control: single one part', (40000, 2, False), 5286),
  ('control: couple two parts', (80000, 4, True), 10572)],
 [('regression cap-unit 1', (150000, 6, True), 28054), ('regression cap-unit 2', (80000, 6, False), 10250),
  ('partial repair guard 1', (40000, 7, False), 51), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression cap-unit 1', (193969, 6, True), 44466), ('regression cap-unit 2', (150000, 8, True), 24536),
  ('partial repair guard 1', (80000, 6, False), 10250), ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194), ('control: too few parts', (50000, 3, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527)],
 [('regression cap-unit 1', (80000, 8, False), 6732), ('regression cap-unit 2', (274066, 8, True), 73788),
  ('partial repair guard 1', (150000, 8, True), 24536), ('partial repair guard 2', (40000, 5, True), 1294),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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:
Each child's half-part is capped at half the stipulated amount.

solve(income, halves, couple): stipulated household quotient. Parts p = halves/2; the base is 2 parts for a couple and 1 otherwise (fewer halves than the base returns 'ERR:parts'). Tax with all parts = p * T(income/p) using slices 0% to 11294, 11% to 28797, 30% to 82341, 41% to 177106, 45% above. The benefit of each half-part beyond the base is capped at 1759: tax = max(full, T_base - 1759 * extra_halves) where T_base = base * T(income/base). Return whole units rounded down.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(income, halves, couple):
    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))

    base = 2 if couple else 1
    pass
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parts-validation 1', (50000, 3, True), 'ERR:parts'),
  ('regression parts-validation 2', (50000, 2, True), 'ERR:parts'),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194)],
 [('regression parts-validation 1', (40000, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 3, True), 'ERR:parts'),
  ('partial repair guard 2', (16932, 3, True), 'ERR:parts'), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921)],
 [('regression parts-validation 1', (281381, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 1, True), 'ERR:parts'),
  ('partial repair guard 1', (40000, 2, True), 'ERR:parts'), ('partial repair guard 2', (23136, 3, True), 'ERR:parts'),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression parts-validation 1', (65970, 1, True), 'ERR:parts'),
  ('regression parts-validation 2', (16932, 3, True), 'ERR:parts'),
  ('partial repair guard 1', (125562, 2, True), 'ERR:parts'), ('partial repair guard 2', (80000, 3, True), 'ERR:parts'),
  ('control: couple with two children', (80000, 6, True), 7054), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527)],
 [('regression parts-validation 1', (95963, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 2, True), 'ERR:parts'),
  ('partial repair guard 1', (80000, 2, True), 'ERR:parts'), ('partial repair guard 2', (150000, 2, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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(income, halves, couple):
    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))

    base = 2 if couple else 1
    if halves < 2: return 'ERR:parts'
    scale = [[11294, '0'], [28797, '11'], [82341, '30'], [177106, '41'], [None, '45']]
    def tax_for(p): return p * prog(Fraction(income) / p, scale)
    full = tax_for(Fraction(halves, 2))
    capped = tax_for(Fraction(base)) - 1759 * (halves - 2 * base)
    return int(max(full, capped))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression parts-validation 1', (50000, 3, True), 'ERR:parts'),
  ('regression parts-validation 2', (50000, 2, True), 'ERR:parts'),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054),
  ('control: low income family', (30000, 5, True), 194)],
 [('regression parts-validation 1', (40000, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 3, True), 'ERR:parts'),
  ('partial repair guard 2', (16932, 3, True), 'ERR:parts'), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527),
  ('control: large family high income', (250000, 8, True), 63921)],
 [('regression parts-validation 1', (281381, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 1, True), 'ERR:parts'),
  ('partial repair guard 1', (40000, 2, True), 'ERR:parts'), ('partial repair guard 2', (23136, 3, True), 'ERR:parts'),
  ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572),
  ('control: couple with two children', (80000, 6, True), 7054)],
 [('regression parts-validation 1', (65970, 1, True), 'ERR:parts'),
  ('regression parts-validation 2', (16932, 3, True), 'ERR:parts'),
  ('partial repair guard 1', (125562, 2, True), 'ERR:parts'), ('partial repair guard 2', (80000, 3, True), 'ERR:parts'),
  ('control: couple with two children', (80000, 6, True), 7054), ('control: low income family', (30000, 5, True), 194),
  ('control: too few parts', (50000, 3, True), 'ERR:parts'), ('control: single parent', (60000, 3, False), 9527)],
 [('regression parts-validation 1', (95963, 1, False), 'ERR:parts'),
  ('regression parts-validation 2', (40000, 2, True), 'ERR:parts'),
  ('partial repair guard 1', (80000, 2, True), 'ERR:parts'), ('partial repair guard 2', (150000, 2, True), 'ERR:parts'),
  ('control: single parent', (60000, 3, False), 9527), ('control: large family high income', (250000, 8, True), 63921),
  ('control: single one part', (40000, 2, False), 5286), ('control: couple two parts', (80000, 4, True), 10572)]]
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 couple with 1.5 parts gets a negative extra-part count that raises the capped tax.

solve(income, halves, couple): stipulated household quotient. Parts p = halves/2; the base is 2 parts for a couple and 1 otherwise (fewer halves than the base returns 'ERR:parts'). Tax with all parts = p * T(income/p) using slices 0% to 11294, 11% to 28797, 30% to 82341, 41% to 177106, 45% above. The benefit of each half-part beyond the base is capped at 1759: tax = max(full, T_base - 1759 * extra_halves) where T_base = base * T(income/base). Return whole units rounded down.

split: open-access


prompt:
Old losses expire unused while recent losses are absorbed.

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

split: open-access


prompt:
Taxable income drops to zero in a year after a large loss.

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

split: open-access


prompt:
A loss is unusable in its final permitted year.

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

split: open-access


prompt:
In some years one extra unit of carryforward is used.

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

split: open-access


prompt:
The carryforward schedule lists zero balances and long-expired losses.

solve(years, life): years are pre-deduction incomes by year index (negative = operating loss). A loss year reports taxable 0 and creates a carryforward [origin, amount]. In an income year, carryforwards older than life years (year - origin > life) expire; the rest are applied oldest first, limited in total to floor(80% of that year's income). Return [taxable_by_year, remaining] where remaining lists [origin, amount] with amount > 0 not expired as of the final year.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000 + dsue)
    tent = T(estate)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression gifts-in-base 1', (10000000, 5000000, 0), 55600000),
  ('regression gifts-in-base 2', (5000000, 15000000, 0), 200000000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000), ('control: modest', (1500000, 200000, 0), 0)],
 [('regression gifts-in-base 1', (13610000, 15000000, 0), 544400000),
  ('regression gifts-in-base 2', (8632782, 5000000, 0), 911280),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gifts-in-base 1', (788866, 18885032, 2000000), 31554640),
  ('regression gifts-in-base 2', (21431981, 500000, 0), 332879240),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression gifts-in-base 1', (13610000, 500000, 0), 20000000),
  ('regression gifts-in-base 2', (13610000, 5000000, 2000000), 120000000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gifts-in-base 1', (13610000, 5703648, 0), 228145920),
  ('regression gifts-in-base 2', (27783445, 500000, 5000000), 386937800),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = T(13610000 + dsue)
    tent = T(estate) + T(gifts)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression gifts-in-base 1', (10000000, 5000000, 0), 55600000),
  ('regression gifts-in-base 2', (5000000, 15000000, 0), 200000000),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000), ('control: modest', (1500000, 200000, 0), 0)],
 [('regression gifts-in-base 1', (13610000, 15000000, 0), 544400000),
  ('regression gifts-in-base 2', (8632782, 5000000, 0), 911280),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gifts-in-base 1', (788866, 18885032, 2000000), 31554640),
  ('regression gifts-in-base 2', (21431981, 500000, 0), 332879240),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression gifts-in-base 1', (13610000, 500000, 0), 20000000),
  ('regression gifts-in-base 2', (13610000, 5000000, 2000000), 120000000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression gifts-in-base 1', (13610000, 5703648, 0), 228145920),
  ('regression gifts-in-base 2', (27783445, 500000, 5000000), 386937800),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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 estate after large gifts is taxed in lower brackets than the cumulative transfers warrant.

solve(estate, gifts, dsue): stipulated unified transfer tax in whole dollars. T is the progressive schedule 18% to 10000 rising to 40% above 1000000. The exclusion is 13610000 + dsue; the unified credit is T(exclusion). Tentative tax = T(estate + gifts). Gift credit = max(0, T(gifts) - unified credit). Tax = max(0, tentative - gift credit - unified credit), returned in integer cents.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = Fraction(13610000 + dsue)
    tent = T(estate + gifts)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-not-exclusion 1', (20000000, 0, 0), 255600000),
  ('regression credit-not-exclusion 2', (10000000, 5000000, 0), 55600000),
  ('control: under exclusion', (10000000, 0, 0), 0), ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0)],
 [('regression credit-not-exclusion 1', (20000000, 0, 5000000), 55600000),
  ('regression credit-not-exclusion 2', (5000000, 15000000, 0), 200000000),
  ('partial repair guard 2', (8632782, 5000000, 0), 911280), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000)],
 [('regression credit-not-exclusion 1', (13610000, 15000000, 0), 544400000),
  ('regression credit-not-exclusion 2', (8632782, 5000000, 0), 911280),
  ('partial repair guard 1', (21431981, 500000, 0), 332879240),
  ('partial repair guard 2', (13610000, 500000, 0), 20000000), ('control: large estate', (20000000, 0, 0), 255600000),
  ('control: under exclusion', (10000000, 0, 0), 0), ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression credit-not-exclusion 1', (788866, 18885032, 2000000), 31554640),
  ('regression credit-not-exclusion 2', (21431981, 500000, 0), 332879240),
  ('partial repair guard 1', (13610000, 5000000, 2000000), 120000000),
  ('partial repair guard 2', (13610000, 5703648, 0), 228145920),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression credit-not-exclusion 1', (13610000, 500000, 0), 20000000),
  ('regression credit-not-exclusion 2', (13610000, 5000000, 2000000), 120000000),
  ('partial repair guard 1', (27783445, 500000, 5000000), 386937800),
  ('partial repair guard 2', (22327855, 5000000, 2000000), 468714200),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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(estate, gifts, dsue):
    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))

    sched = [[10000, '18'], [20000, '20'], [40000, '22'], [60000, '24'], [80000, '26'], [100000, '28'], [150000, '30'], [250000, '32'], [500000, '34'], [750000, '37'], [1000000, '39'], [None, '40']]
    T = lambda x: prog(x, sched)
    credit = Fraction(13610000 + dsue) * 40 / 100
    tent = T(estate + gifts)
    gift_credit = max(0, T(gifts) - credit)
    return cents(max(0, tent - gift_credit - credit))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression credit-not-exclusion 1', (20000000, 0, 0), 255600000),
  ('regression credit-not-exclusion 2', (10000000, 5000000, 0), 55600000),
  ('control: under exclusion', (10000000, 0, 0), 0), ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0)],
 [('regression credit-not-exclusion 1', (20000000, 0, 5000000), 55600000),
  ('regression credit-not-exclusion 2', (5000000, 15000000, 0), 200000000),
  ('partial repair guard 2', (8632782, 5000000, 0), 911280), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000)],
 [('regression credit-not-exclusion 1', (13610000, 15000000, 0), 544400000),
  ('regression credit-not-exclusion 2', (8632782, 5000000, 0), 911280),
  ('partial repair guard 1', (21431981, 500000, 0), 332879240),
  ('partial repair guard 2', (13610000, 500000, 0), 20000000), ('control: large estate', (20000000, 0, 0), 255600000),
  ('control: under exclusion', (10000000, 0, 0), 0), ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)],
 [('regression credit-not-exclusion 1', (788866, 18885032, 2000000), 31554640),
  ('regression credit-not-exclusion 2', (21431981, 500000, 0), 332879240),
  ('partial repair guard 1', (13610000, 5000000, 2000000), 120000000),
  ('partial repair guard 2', (13610000, 5703648, 0), 228145920),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000),
  ('control: gifts above exclusion', (5000000, 15000000, 0), 200000000), ('control: modest', (1500000, 200000, 0), 0),
  ('control: large estate', (20000000, 0, 0), 255600000)],
 [('regression credit-not-exclusion 1', (13610000, 500000, 0), 20000000),
  ('regression credit-not-exclusion 2', (13610000, 5000000, 2000000), 120000000),
  ('partial repair guard 1', (27783445, 500000, 5000000), 386937800),
  ('partial repair guard 2', (22327855, 5000000, 2000000), 468714200),
  ('control: large estate', (20000000, 0, 0), 255600000), ('control: under exclusion', (10000000, 0, 0), 0),
  ('control: with prior gifts', (10000000, 5000000, 0), 55600000),
  ('control: ported exclusion', (20000000, 0, 5000000), 55600000)]]
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:
Estates owe no tax far above the exclusion because 13.6 million of tax is forgiven.

solve(estate, gifts, dsue): stipulated unified transfer tax in whole dollars. T is the progressive schedule 18% to 10000 rising to 40% above 1000000. The exclusion is 13610000 + dsue; the unified credit is T(exclusion). Tentative tax = T(estate + gifts). Gift credit = max(0, T(gifts) - unified credit). Tax = max(0, tentative - gift credit - unified credit), returned in integer cents.

split: open-access