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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    annual = x['wage'] * periods
    adjusted = max(0, annual - x['allow'] * 430000)
    mult = 2 if x['status'] == 'married' else 1
    brackets = [(400000 * mult, 10), (1500000 * mult, 12), (5000000 * mult, 22)]
    tax = 0
    for i, (lo, rate) in enumerate(brackets):
        hi = brackets[i + 1][0] if i + 1 < len(brackets) else None
        if adjusted > lo:
            top = adjusted if hi is None else min(adjusted, hi)
            tax = adjusted * rate
    wh = (tax * 2 + 100 * periods) // (200 * periods)
    return wh
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('regression (boundary)', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('partial-repair probe', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 22359, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 89742, 'freq': 'monthly', 'allow': 1, 'status': 'married'}, 0), ('normal control', {'wage': 17607, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6134, 'freq': 'semimonthly', 'allow': 0, 'status': 'single'}, 0)], [('regression (boundary)', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 52312, 'freq': 'semimonthly', 'allow': 5, 'status': 'single'}, 0), ('normal control', {'wage': 28087, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 97334, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 18119, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 0)], [('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('regression', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 10871, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 836, 'freq': 'semimonthly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 30453, 'freq': 'biweekly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 27188, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0)], [('regression', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 157996, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 5300), ('partial-repair probe', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 23859, 'freq': 'semimonthly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 50426, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 128102, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 6608, 'freq': 'semimonthly', 'allow': 0, 'status': 'married'}, 0)], [('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('partial-repair probe', {'wage': 143245, 'freq': 'biweekly', 'allow': 5, 'status': 'married'}, 2978), ('partial-repair probe', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 49359, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 56499, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6762, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 30428, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    annual = x['wage'] * periods
    adjusted = max(0, annual - x['allow'] * 430000)
    mult = 2 if x['status'] == 'married' else 1
    brackets = [(400000 * mult, 10), (1500000 * mult, 12), (5000000 * mult, 22)]
    tax = 0
    for i, (lo, rate) in enumerate(brackets):
        hi = brackets[i + 1][0] if i + 1 < len(brackets) else None
        if adjusted > lo:
            top = adjusted if hi is None else min(adjusted, hi)
            tax += top * rate
    wh = (tax * 2 + 100 * periods) // (200 * periods)
    return wh
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('regression (boundary)', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('partial-repair probe', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 22359, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 89742, 'freq': 'monthly', 'allow': 1, 'status': 'married'}, 0), ('normal control', {'wage': 17607, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6134, 'freq': 'semimonthly', 'allow': 0, 'status': 'single'}, 0)], [('regression (boundary)', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 52312, 'freq': 'semimonthly', 'allow': 5, 'status': 'single'}, 0), ('normal control', {'wage': 28087, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 97334, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 18119, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 0)], [('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('regression', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 10871, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 836, 'freq': 'semimonthly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 30453, 'freq': 'biweekly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 27188, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0)], [('regression', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 157996, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 5300), ('partial-repair probe', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 23859, 'freq': 'semimonthly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 50426, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 128102, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 6608, 'freq': 'semimonthly', 'allow': 0, 'status': 'married'}, 0)], [('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('partial-repair probe', {'wage': 143245, 'freq': 'biweekly', 'allow': 5, 'status': 'married'}, 2978), ('partial-repair probe', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 49359, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 56499, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6762, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 30428, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Withholding jumps discontinuously when income crosses a bracket, taxing all income at the top reached rate.

Input {wage, freq, allow, status}. Annualize: wage*periods (weekly 52, biweekly 26, semimonthly 24, monthly 12); subtract 4,300.00 per allowance, floor 0. Marginal brackets over 4,000/15,000/50,000 dollars at 10/12/22% (married thresholds doubled). Annual tax (in cent-percent units) is divided by periods and rounded half-up to cents once.

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    annual = x['wage'] * periods
    adjusted = max(0, annual - x['allow'] * 430000)
    mult = 2 if x['status'] == 'married' else 1
    brackets = [(400000 * mult, 10), (1500000 * mult, 12), (5000000 * mult, 22)]
    tax = 0
    for i, (lo, rate) in enumerate(brackets):
        hi = brackets[i + 1][0] if i + 1 < len(brackets) else None
        if adjusted > lo:
            top = adjusted if hi is None else min(adjusted, hi)
            tax += (top - lo) * rate
    wh = ((tax + 5000) // 10000 * 200 + periods) // (2 * periods)
    return wh
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('normal control', {'wage': 22359, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 89742, 'freq': 'monthly', 'allow': 1, 'status': 'married'}, 0), ('normal control', {'wage': 17607, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6134, 'freq': 'semimonthly', 'allow': 0, 'status': 'single'}, 0)], [('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 157996, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 5300), ('partial-repair probe', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 52312, 'freq': 'semimonthly', 'allow': 5, 'status': 'single'}, 0), ('normal control', {'wage': 28087, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 97334, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 18119, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 0)], [('regression', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('partial-repair probe', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('partial-repair probe', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('normal control', {'wage': 10871, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 836, 'freq': 'semimonthly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 30453, 'freq': 'biweekly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 27188, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0)], [('regression', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('regression', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('partial-repair probe', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('partial-repair probe', {'wage': 166201, 'freq': 'weekly', 'allow': 0, 'status': 'married'}, 17252), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('normal control', {'wage': 23859, 'freq': 'semimonthly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 50426, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 128102, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 6608, 'freq': 'semimonthly', 'allow': 0, 'status': 'married'}, 0)], [('regression', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('regression', {'wage': 143245, 'freq': 'biweekly', 'allow': 5, 'status': 'married'}, 2978), ('partial-repair probe', {'wage': 1203384, 'freq': 'biweekly', 'allow': 6, 'status': 'single'}, 220991), ('partial-repair probe', {'wage': 1136572, 'freq': 'weekly', 'allow': 1, 'status': 'married'}, 226304), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 49359, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 56499, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6762, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 30428, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    annual = x['wage'] * periods
    adjusted = max(0, annual - x['allow'] * 430000)
    mult = 2 if x['status'] == 'married' else 1
    brackets = [(400000 * mult, 10), (1500000 * mult, 12), (5000000 * mult, 22)]
    tax = 0
    for i, (lo, rate) in enumerate(brackets):
        hi = brackets[i + 1][0] if i + 1 < len(brackets) else None
        if adjusted > lo:
            top = adjusted if hi is None else min(adjusted, hi)
            tax += (top - lo) * rate
    wh = tax // (100 * periods)
    return wh
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 998152, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 168152), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 992194, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 190902), ('partial-repair probe', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('normal control', {'wage': 22359, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 89742, 'freq': 'monthly', 'allow': 1, 'status': 'married'}, 0), ('normal control', {'wage': 17607, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6134, 'freq': 'semimonthly', 'allow': 0, 'status': 'single'}, 0)], [('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('regression', {'wage': 36754, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 483), ('partial-repair probe', {'wage': 157996, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 5300), ('partial-repair probe', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 52312, 'freq': 'semimonthly', 'allow': 5, 'status': 'single'}, 0), ('normal control', {'wage': 28087, 'freq': 'biweekly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 97334, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 18119, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 0)], [('regression', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('regression', {'wage': 124657, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 1966), ('partial-repair probe', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('partial-repair probe', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('normal control', {'wage': 10871, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 836, 'freq': 'semimonthly', 'allow': 1, 'status': 'single'}, 0), ('normal control', {'wage': 30453, 'freq': 'biweekly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 27188, 'freq': 'semimonthly', 'allow': 4, 'status': 'married'}, 0)], [('regression', {'wage': 475908, 'freq': 'monthly', 'allow': 6, 'status': 'single'}, 25476), ('regression', {'wage': 1223812, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 134822), ('partial-repair probe', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('partial-repair probe', {'wage': 166201, 'freq': 'weekly', 'allow': 0, 'status': 'married'}, 17252), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('boundary control', {'wage': 57693, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 5577), ('normal control', {'wage': 23859, 'freq': 'semimonthly', 'allow': 2, 'status': 'married'}, 0), ('normal control', {'wage': 50426, 'freq': 'semimonthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 128102, 'freq': 'monthly', 'allow': 5, 'status': 'married'}, 0), ('normal control', {'wage': 6608, 'freq': 'semimonthly', 'allow': 0, 'status': 'married'}, 0)], [('regression', {'wage': 872994, 'freq': 'weekly', 'allow': 3, 'status': 'married'}, 164678), ('regression', {'wage': 143245, 'freq': 'biweekly', 'allow': 5, 'status': 'married'}, 2978), ('partial-repair probe', {'wage': 1203384, 'freq': 'biweekly', 'allow': 6, 'status': 'single'}, 220991), ('partial-repair probe', {'wage': 1136572, 'freq': 'weekly', 'allow': 1, 'status': 'married'}, 226304), ('boundary control', {'wage': 125000, 'freq': 'semimonthly', 'allow': 1, 'status': 'married'}, 7375), ('boundary control', {'wage': 0, 'freq': 'weekly', 'allow': 0, 'status': 'single'}, 0), ('normal control', {'wage': 49359, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 56499, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0), ('normal control', {'wage': 6762, 'freq': 'weekly', 'allow': 6, 'status': 'single'}, 0), ('normal control', {'wage': 30428, 'freq': 'monthly', 'allow': 4, 'status': 'married'}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Per-period withholding drifts by several cents from the exact annualized result.

Input {wage, freq, allow, status}. Annualize: wage*periods (weekly 52, biweekly 26, semimonthly 24, monthly 12); subtract 4,300.00 per allowance, floor 0. Marginal brackets over 4,000/15,000/50,000 dollars at 10/12/22% (married thresholds doubled). Annual tax (in cent-percent units) is divided by periods and rounded half-up to cents once.

split: open-access


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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(0, tentative - credit_pp + x['extra'])
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('partial-repair probe', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('partial-repair probe', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])], [('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('regression', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('partial-repair probe', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('partial-repair probe', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('normal control', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076])], [('regression', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('partial-repair probe', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('normal control', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568])], [('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0])], [('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('regression', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500]), ('partial-repair probe', {'wage': 113270, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [3369, 5869]), ('partial-repair probe', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('normal control', {'wage': 197261, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [0, 0]), ('normal control', {'wage': 228867, 'periods': 52, 'status': 'single', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [38628, 38628]), ('normal control', {'wage': 176, 'periods': 12, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 1390591, 'deductions': 0, 'extra': 0}, [398, 398]), ('normal control', {'wage': 668083, 'periods': 12, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [55320, 21987])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(x['extra'], tentative - credit_pp)
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('partial-repair probe', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('partial-repair probe', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])], [('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('regression', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('partial-repair probe', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('partial-repair probe', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('normal control', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076])], [('regression', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('partial-repair probe', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('normal control', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568])], [('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0])], [('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('regression', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500]), ('partial-repair probe', {'wage': 113270, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [3369, 5869]), ('partial-repair probe', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('normal control', {'wage': 197261, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [0, 0]), ('normal control', {'wage': 228867, 'periods': 52, 'status': 'single', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [38628, 38628]), ('normal control', {'wage': 176, 'periods': 12, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 1390591, 'deductions': 0, 'extra': 0}, [398, 398]), ('normal control', {'wage': 668083, 'periods': 12, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [55320, 21987])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Employees whose credits exceed tentative withholding lose some or all of their requested extra withholding.

Input {wage, periods, status single|mfj|hoh, step2, credits, other_income, deductions, extra}; annual amounts in cents except wage and extra (per period). Annual = wage*periods + other_income. Deduction = base standard (single 8,600, mfj 12,900, hoh 8,600 dollars; halved when step2) + itemized deductions (never halved). Thresholds 7,000/30,000/90,000 dollars at 10/12/22% scaled by status unit (single 2, mfj 4, hoh 3)/2, or /4 when step2. Tentative per-period = annual tax/periods half-up; credits/periods half-up is subtracted, floored at 0, then extra is added.

split: open-access


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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = x['credits']
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0])], [('regression', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('regression', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])], [('regression', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('regression', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('partial-repair probe', {'wage': 190399, 'periods': 24, 'status': 'mfj', 'step2': True, 'credits': 200000, 'other_income': 1327070, 'deductions': 0, 'extra': 0}, [20842, 12509]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('normal control', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('normal control', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604])], [('regression', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('regression', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 292525, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 400000, 'other_income': 645414, 'deductions': 0, 'extra': 8294}, [36467, 29376]), ('partial-repair probe', {'wage': 242233, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17599, 2214]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302])], [('regression', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('regression', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('partial-repair probe', {'wage': 617786, 'periods': 24, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 1587260, 'deductions': 0, 'extra': 2500}, [125063, 110896]), ('partial-repair probe', {'wage': 344993, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [25445, 20253]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = x['credits'] // 12
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0])], [('regression', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('regression', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])], [('regression', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('regression', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('partial-repair probe', {'wage': 190399, 'periods': 24, 'status': 'mfj', 'step2': True, 'credits': 200000, 'other_income': 1327070, 'deductions': 0, 'extra': 0}, [20842, 12509]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('normal control', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('normal control', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604])], [('regression', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('regression', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 292525, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 400000, 'other_income': 645414, 'deductions': 0, 'extra': 8294}, [36467, 29376]), ('partial-repair probe', {'wage': 242233, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17599, 2214]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302])], [('regression', {'wage': 452063, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 1399}, [48654, 41720]), ('regression', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('partial-repair probe', {'wage': 617786, 'periods': 24, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 1587260, 'deductions': 0, 'extra': 2500}, [125063, 110896]), ('partial-repair probe', {'wage': 344993, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [25445, 20253]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Any employee claiming dependents has withholding wiped out entirely each paycheck.

Input {wage, periods, status single|mfj|hoh, step2, credits, other_income, deductions, extra}; annual amounts in cents except wage and extra (per period). Annual = wage*periods + other_income. Deduction = base standard (single 8,600, mfj 12,900, hoh 8,600 dollars; halved when step2) + itemized deductions (never halved). Thresholds 7,000/30,000/90,000 dollars at 10/12/22% scaled by status unit (single 2, mfj 4, hoh 3)/2, or /4 when step2. Tentative per-period = annual tax/periods half-up; credits/periods half-up is subtracted, floored at 0, then extra is added.

split: open-access


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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = (x['wage'] + x['other_income']) * p
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('partial-repair probe', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272])], [('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('partial-repair probe', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707])], [('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('regression', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('partial-repair probe', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('normal control', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468])], [('regression', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568]), ('normal control', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500])], [('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0]), ('normal control', {'wage': 80276, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 10576}, [5149, 10576]), ('normal control', {'wage': 23105, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income'] // p
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std // 2 if x['step2'] else base_std) + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('partial-repair probe', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272])], [('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('partial-repair probe', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707])], [('regression', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('regression', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('partial-repair probe', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('normal control', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468])], [('regression', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('partial-repair probe', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568]), ('normal control', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500])], [('regression', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664]), ('regression', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('partial-repair probe', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('partial-repair probe', {'wage': 667888, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 200000, 'other_income': 923171, 'deductions': 893525, 'extra': 2500}, [74949, 69116]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0]), ('normal control', {'wage': 80276, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 10576}, [5149, 10576]), ('normal control', {'wage': 23105, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Employees reporting other income are withheld as if that income recurred every paycheck.

Input {wage, periods, status single|mfj|hoh, step2, credits, other_income, deductions, extra}; annual amounts in cents except wage and extra (per period). Annual = wage*periods + other_income. Deduction = base standard (single 8,600, mfj 12,900, hoh 8,600 dollars; halved when step2) + itemized deductions (never halved). Thresholds 7,000/30,000/90,000 dollars at 10/12/22% scaled by status unit (single 2, mfj 4, hoh 3)/2, or /4 when step2. Tentative per-period = annual tax/periods half-up; credits/periods half-up is subtracted, floored at 0, then extra is added.

split: open-access


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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = (base_std + x['deductions']) // 2 if x['step2'] else base_std + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('regression', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('partial-repair probe', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354])], [('regression', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('regression', {'wage': 178354, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 112718, 'extra': 0}, [12905, 12905]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('partial-repair probe', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993])], [('regression', {'wage': 178354, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 112718, 'extra': 0}, [12905, 12905]), ('regression', {'wage': 205442, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1801669, 'deductions': 1137902, 'extra': 0}, [21574, 4907]), ('partial-repair probe', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('partial-repair probe', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('normal control', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('normal control', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664])], [('regression', {'wage': 205442, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1801669, 'deductions': 1137902, 'extra': 0}, [21574, 4907]), ('regression', {'wage': 117375, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 546474, 'other_income': 0, 'deductions': 599256, 'extra': 0}, [5261, 0]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568])], [('regression', {'wage': 117375, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 546474, 'other_income': 0, 'deductions': 599256, 'extra': 0}, [5261, 0]), ('regression', {'wage': 121406, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1123754, 'deductions': 405924, 'extra': 0}, [12030, 0]), ('partial-repair probe', {'wage': 228867, 'periods': 52, 'status': 'single', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [38628, 38628]), ('partial-repair probe', {'wage': 176, 'periods': 12, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 1390591, 'deductions': 0, 'extra': 0}, [398, 398]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('normal control', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    p = x['periods']
    annual = x['wage'] * p + x['other_income']
    base_std = {'single': 860000, 'mfj': 1290000, 'hoh': 860000}[x['status']]
    ded = base_std + x['deductions']
    taxable = max(0, annual - ded)
    unit = {'single': 2, 'mfj': 4, 'hoh': 3}[x['status']]
    div = 4 if x['step2'] else 2
    bounds = [700000 * unit // div, 3000000 * unit // div, 9000000 * unit // div]
    rates = [10, 12, 22]
    tax = 0
    for i, lo in enumerate(bounds):
        hi = bounds[i + 1] if i + 1 < len(bounds) else taxable
        if taxable > lo:
            tax += (min(taxable, hi) - lo) * rates[i]
    tentative = (tax * 2 + 100 * p) // (200 * p)
    credit_pp = (x['credits'] * 2 + p) // (2 * p)
    wh = max(0, tentative - credit_pp) + x['extra']
    return [tentative, wh]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 69636, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 877725, 'other_income': 1721162, 'deductions': 1014955, 'extra': 0}, [5927, 0]), ('regression', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('partial-repair probe', {'wage': 492438, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 400000, 'other_income': 131536, 'deductions': 0, 'extra': 0}, [59948, 26615]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 4942, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 1831505, 'deductions': 0, 'extra': 8860}, [2757, 8860]), ('normal control', {'wage': 111690, 'periods': 26, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [823, 823]), ('normal control', {'wage': 67447, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 1041418, 'periods': 24, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [156854, 159354])], [('regression', {'wage': 285367, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 1182238, 'extra': 2500}, [41104, 43604]), ('regression', {'wage': 178354, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 112718, 'extra': 0}, [12905, 12905]), ('partial-repair probe', {'wage': 170108, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 167672, 'deductions': 0, 'extra': 0}, [12373, 0]), ('partial-repair probe', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 245742, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19772, 22272]), ('normal control', {'wage': 196398, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [6640, 6640]), ('normal control', {'wage': 64669, 'periods': 24, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [0, 2500]), ('normal control', {'wage': 232685, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 0, 'deductions': 479252, 'extra': 0}, [18839, 14993])], [('regression', {'wage': 178354, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 112718, 'extra': 0}, [12905, 12905]), ('regression', {'wage': 205442, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1801669, 'deductions': 1137902, 'extra': 0}, [21574, 4907]), ('partial-repair probe', {'wage': 124748, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [7302, 7302]), ('partial-repair probe', {'wage': 90292, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [7968, 10468]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 79014, 'periods': 24, 'status': 'mfj', 'step2': False, 'credits': 400000, 'other_income': 1864011, 'deductions': 0, 'extra': 0}, [4460, 0]), ('normal control', {'wage': 322003, 'periods': 12, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [19207, 21707]), ('normal control', {'wage': 93316, 'periods': 12, 'status': 'mfj', 'step2': False, 'credits': 200000, 'other_income': 1111591, 'deductions': 0, 'extra': 1563}, [0, 1563]), ('normal control', {'wage': 37313, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 117737, 'other_income': 1320234, 'deductions': 0, 'extra': 5664}, [1097, 5664])], [('regression', {'wage': 205442, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1801669, 'deductions': 1137902, 'extra': 0}, [21574, 4907]), ('regression', {'wage': 117375, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 546474, 'other_income': 0, 'deductions': 599256, 'extra': 0}, [5261, 0]), ('partial-repair probe', {'wage': 142479, 'periods': 52, 'status': 'hoh', 'step2': True, 'credits': 551126, 'other_income': 0, 'deductions': 0, 'extra': 3806}, [14670, 7877]), ('partial-repair probe', {'wage': 606158, 'periods': 26, 'status': 'hoh', 'step2': True, 'credits': 0, 'other_income': 1548001, 'deductions': 0, 'extra': 0}, [113103, 113103]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 179669, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [17076, 17076]), ('normal control', {'wage': 244499, 'periods': 26, 'status': 'hoh', 'step2': False, 'credits': 305778, 'other_income': 170107, 'deductions': 0, 'extra': 0}, [18656, 6895]), ('normal control', {'wage': 250357, 'periods': 52, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [31632, 34132]), ('normal control', {'wage': 251742, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 392790, 'extra': 0}, [23568, 23568])], [('regression', {'wage': 117375, 'periods': 24, 'status': 'hoh', 'step2': True, 'credits': 546474, 'other_income': 0, 'deductions': 599256, 'extra': 0}, [5261, 0]), ('regression', {'wage': 121406, 'periods': 12, 'status': 'single', 'step2': True, 'credits': 200000, 'other_income': 1123754, 'deductions': 405924, 'extra': 0}, [12030, 0]), ('partial-repair probe', {'wage': 228867, 'periods': 52, 'status': 'single', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [38628, 38628]), ('partial-repair probe', {'wage': 176, 'periods': 12, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 1390591, 'deductions': 0, 'extra': 0}, [398, 398]), ('boundary control', {'wage': 0, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 5000}, [0, 5000]), ('normal control', {'wage': 290758, 'periods': 26, 'status': 'single', 'step2': False, 'credits': 0, 'other_income': 1100573, 'deductions': 944056, 'extra': 0}, [26644, 26644]), ('normal control', {'wage': 76761, 'periods': 52, 'status': 'hoh', 'step2': False, 'credits': 400000, 'other_income': 0, 'deductions': 0, 'extra': 2500}, [4003, 2500]), ('normal control', {'wage': 451331, 'periods': 52, 'status': 'mfj', 'step2': False, 'credits': 0, 'other_income': 0, 'deductions': 0, 'extra': 0}, [54220, 54220]), ('normal control', {'wage': 37554, 'periods': 26, 'status': 'mfj', 'step2': True, 'credits': 0, 'other_income': 0, 'deductions': 695042, 'extra': 0}, [0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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:
Multiple-job employees who also itemize are over-withheld because half their itemized deductions vanish.

Input {wage, periods, status single|mfj|hoh, step2, credits, other_income, deductions, extra}; annual amounts in cents except wage and extra (per period). Annual = wage*periods + other_income. Deduction = base standard (single 8,600, mfj 12,900, hoh 8,600 dollars; halved when step2) + itemized deductions (never halved). Thresholds 7,000/30,000/90,000 dollars at 10/12/22% scaled by status unit (single 2, mfj 4, hoh 3)/2, or /4 when step2. Tentative per-period = annual tax/periods half-up; credits/periods half-up is subtracted, floored at 0, then extra is added.

split: open-access