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

N = 1
observations = []
def solve(x):
    rates = [x['federal']] + [r for r in (x['state'], x['local']) if r is not None]
    applicable = max(rates)
    if x['age'] < 20 and x['days_employed'] < 90 and x['state'] is None and x['local'] is None:
        applicable = min(applicable, 425)
    return [applicable, max(0, x['hours'] * applicable - x['paid'])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 6, 'paid': 3640}, [725, 710]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 6, 'paid': 16880}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 21, 'days_employed': 10, 'hours': 36, 'paid': 32014}, [900, 386]), ('normal control', {'federal': 725, 'state': 1500, 'local': 900, 'age': 19, 'days_employed': 200, 'hours': 32, 'paid': 60214}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 17, 'days_employed': 10, 'hours': 44, 'paid': 52557}, [1500, 13443]), ('normal control', {'federal': 725, 'state': 700, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 42, 'paid': 43650}, [900, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 119, 'hours': 35, 'paid': 32541}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 91, 'hours': 13, 'paid': 19333}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 200, 'hours': 49, 'paid': 66535}, [725, 0]), ('normal control', {'federal': 725, 'state': 700, 'local': 1400, 'age': 20, 'days_employed': 119, 'hours': 50, 'paid': 49362}, [1400, 20638]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 17, 'days_employed': 200, 'hours': 12, 'paid': 62529}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 13, 'paid': 52409}, [1500, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 100, 'hours': 29, 'paid': 59285}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 119, 'hours': 44, 'paid': 55291}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 1700, 'age': 21, 'days_employed': 200, 'hours': 31, 'paid': 26649}, [1700, 26051]), ('normal control', {'federal': 725, 'state': 700, 'local': None, 'age': 35, 'days_employed': 200, 'hours': 25, 'paid': 55516}, [725, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 91, 'hours': 3, 'paid': 73893}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 44, 'paid': 29457}, [900, 10143])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 100, 'hours': 21, 'paid': 28873}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 19, 'paid': 42785}, [725, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 19, 'days_employed': 90, 'hours': 35, 'paid': 10142}, [1500, 42358]), ('normal control', {'federal': 725, 'state': 800, 'local': 1400, 'age': 21, 'days_employed': 89, 'hours': 42, 'paid': 70854}, [1400, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 27, 'paid': 8188}, [900, 16112]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 200, 'hours': 2, 'paid': 39319}, [900, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 119, 'hours': 23, 'paid': 24115}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 6, 'paid': 3640}, [725, 710]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 21, 'days_employed': 100, 'hours': 38, 'paid': 59758}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 35, 'days_employed': 91, 'hours': 1, 'paid': 31574}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 89, 'hours': 20, 'paid': 19880}, [1500, 10120]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 20, 'days_employed': 89, 'hours': 13, 'paid': 20235}, [1500, 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):
    rates = [x['federal']] + [r for r in (x['state'], x['local']) if r is not None]
    applicable = max(rates)
    if x['age'] < 20 and x['days_employed'] // 30 <= 3 and x['state'] is None and x['local'] is None:
        applicable = min(applicable, 425)
    return [applicable, max(0, x['hours'] * applicable - x['paid'])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 6, 'paid': 3640}, [725, 710]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 6, 'paid': 16880}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 21, 'days_employed': 10, 'hours': 36, 'paid': 32014}, [900, 386]), ('normal control', {'federal': 725, 'state': 1500, 'local': 900, 'age': 19, 'days_employed': 200, 'hours': 32, 'paid': 60214}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 17, 'days_employed': 10, 'hours': 44, 'paid': 52557}, [1500, 13443]), ('normal control', {'federal': 725, 'state': 700, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 42, 'paid': 43650}, [900, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 119, 'hours': 35, 'paid': 32541}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 91, 'hours': 13, 'paid': 19333}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 200, 'hours': 49, 'paid': 66535}, [725, 0]), ('normal control', {'federal': 725, 'state': 700, 'local': 1400, 'age': 20, 'days_employed': 119, 'hours': 50, 'paid': 49362}, [1400, 20638]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 17, 'days_employed': 200, 'hours': 12, 'paid': 62529}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 13, 'paid': 52409}, [1500, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 100, 'hours': 29, 'paid': 59285}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 119, 'hours': 44, 'paid': 55291}, [725, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 1700, 'age': 21, 'days_employed': 200, 'hours': 31, 'paid': 26649}, [1700, 26051]), ('normal control', {'federal': 725, 'state': 700, 'local': None, 'age': 35, 'days_employed': 200, 'hours': 25, 'paid': 55516}, [725, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 91, 'hours': 3, 'paid': 73893}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 44, 'paid': 29457}, [900, 10143])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 23, 'paid': 23235}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 100, 'hours': 21, 'paid': 28873}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 19, 'paid': 42785}, [725, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 19, 'days_employed': 90, 'hours': 35, 'paid': 10142}, [1500, 42358]), ('normal control', {'federal': 725, 'state': 800, 'local': 1400, 'age': 21, 'days_employed': 89, 'hours': 42, 'paid': 70854}, [1400, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 27, 'paid': 8188}, [900, 16112]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 200, 'hours': 2, 'paid': 39319}, [900, 0])], [('regression', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 90, 'hours': 40, 'paid': 47076}, [425, 0]), ('regression', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 90, 'hours': 19, 'paid': 48745}, [425, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 17, 'days_employed': 119, 'hours': 23, 'paid': 24115}, [725, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 6, 'paid': 3640}, [725, 710]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 21, 'days_employed': 100, 'hours': 38, 'paid': 59758}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 35, 'days_employed': 91, 'hours': 1, 'paid': 31574}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 89, 'hours': 20, 'paid': 19880}, [1500, 10120]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 20, 'days_employed': 89, 'hours': 13, 'paid': 20235}, [1500, 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:
Young workers on their 90th day are shortchanged or overpaid at the window edge.

Input {federal, state|None, local|None, age, days_employed, hours, paid}. Applicable rate is the highest of the defined federal, state and local minimums. A youth rate of 4.25 may replace it when age < 20, days_employed <= 90 and neither a state nor local minimum is defined. Return [rate, max(0, hours*rate - paid)].

split: open-access


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

N = 1
observations = []
def solve(x):
    rates = [x['federal']] + [r for r in (x['state'], x['local']) if r is not None]
    applicable = max(rates)
    if x['age'] < 20 and x['days_employed'] <= 90 :
        applicable = min(applicable, 425)
    return [applicable, max(0, x['hours'] * applicable - x['paid'])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('regression', {'federal': 725, 'state': 1500, 'local': None, 'age': 17, 'days_employed': 10, 'hours': 44, 'paid': 52557}, [1500, 13443]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 90, 'hours': 18, 'paid': 17771}, [1700, 12829]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 21, 'days_employed': 10, 'hours': 36, 'paid': 32014}, [900, 386]), ('normal control', {'federal': 725, 'state': 1500, 'local': 900, 'age': 19, 'days_employed': 200, 'hours': 32, 'paid': 60214}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 200, 'hours': 49, 'paid': 66535}, [725, 0]), ('normal control', {'federal': 725, 'state': 700, 'local': 1400, 'age': 20, 'days_employed': 119, 'hours': 50, 'paid': 49362}, [1400, 20638])], [('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 90, 'hours': 18, 'paid': 17771}, [1700, 12829]), ('regression', {'federal': 725, 'state': 700, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 42, 'paid': 43650}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 89, 'hours': 27, 'paid': 71203}, [1400, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 17, 'days_employed': 200, 'hours': 12, 'paid': 62529}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 13, 'paid': 52409}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 1700, 'age': 21, 'days_employed': 200, 'hours': 31, 'paid': 26649}, [1700, 26051]), ('normal control', {'federal': 725, 'state': 700, 'local': None, 'age': 35, 'days_employed': 200, 'hours': 25, 'paid': 55516}, [725, 0])], [('regression', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('regression', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 19, 'days_employed': 90, 'hours': 35, 'paid': 10142}, [1500, 42358]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 10, 'hours': 4, 'paid': 8906}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 89, 'hours': 9, 'paid': 34655}, [1700, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 91, 'hours': 3, 'paid': 73893}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 44, 'paid': 29457}, [900, 10143]), ('normal control', {'federal': 725, 'state': 800, 'local': 1400, 'age': 21, 'days_employed': 89, 'hours': 42, 'paid': 70854}, [1400, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 27, 'paid': 8188}, [900, 16112])], [('regression', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 89, 'hours': 27, 'paid': 71203}, [1400, 0]), ('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 90, 'hours': 17, 'paid': 63085}, [1400, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 90, 'hours': 37, 'paid': 49772}, [1400, 2028]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 200, 'hours': 2, 'paid': 39319}, [900, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 21, 'days_employed': 100, 'hours': 38, 'paid': 59758}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 35, 'days_employed': 91, 'hours': 1, 'paid': 31574}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 89, 'hours': 20, 'paid': 19880}, [1500, 10120])], [('regression', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 10, 'hours': 4, 'paid': 8906}, [900, 0]), ('regression', {'federal': 725, 'state': 800, 'local': 1700, 'age': 19, 'days_employed': 10, 'hours': 35, 'paid': 45995}, [1700, 13505]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 19, 'days_employed': 89, 'hours': 11, 'paid': 62799}, [1400, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 20, 'days_employed': 89, 'hours': 13, 'paid': 20235}, [1500, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 1700, 'age': 17, 'days_employed': 119, 'hours': 36, 'paid': 42057}, [1700, 19143]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 21, 'paid': 76399}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 20, 'days_employed': 91, 'hours': 50, 'paid': 25834}, [725, 10416])]]
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):
    rates = [x['federal']] + [r for r in (x['state'], x['local']) if r is not None]
    applicable = max(rates)
    if x['age'] < 20 and x['days_employed'] <= 90 and x['state'] is None:
        applicable = min(applicable, 425)
    return [applicable, max(0, x['hours'] * applicable - x['paid'])]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('regression', {'federal': 725, 'state': 1500, 'local': None, 'age': 17, 'days_employed': 10, 'hours': 44, 'paid': 52557}, [1500, 13443]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 90, 'hours': 18, 'paid': 17771}, [1700, 12829]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 21, 'days_employed': 10, 'hours': 36, 'paid': 32014}, [900, 386]), ('normal control', {'federal': 725, 'state': 1500, 'local': 900, 'age': 19, 'days_employed': 200, 'hours': 32, 'paid': 60214}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 19, 'days_employed': 200, 'hours': 49, 'paid': 66535}, [725, 0]), ('normal control', {'federal': 725, 'state': 700, 'local': 1400, 'age': 20, 'days_employed': 119, 'hours': 50, 'paid': 49362}, [1400, 20638])], [('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 90, 'hours': 18, 'paid': 17771}, [1700, 12829]), ('regression', {'federal': 725, 'state': 700, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 42, 'paid': 43650}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 89, 'hours': 27, 'paid': 71203}, [1400, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 17, 'days_employed': 200, 'hours': 12, 'paid': 62529}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 91, 'hours': 13, 'paid': 52409}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 1700, 'age': 21, 'days_employed': 200, 'hours': 31, 'paid': 26649}, [1700, 26051]), ('normal control', {'federal': 725, 'state': 700, 'local': None, 'age': 35, 'days_employed': 200, 'hours': 25, 'paid': 55516}, [725, 0])], [('regression', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 90, 'hours': 1, 'paid': 51150}, [900, 0]), ('regression', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 19, 'days_employed': 90, 'hours': 35, 'paid': 10142}, [1500, 42358]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 10, 'hours': 4, 'paid': 8906}, [900, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 17, 'days_employed': 89, 'hours': 9, 'paid': 34655}, [1700, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 91, 'hours': 3, 'paid': 73893}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 44, 'paid': 29457}, [900, 10143]), ('normal control', {'federal': 725, 'state': 800, 'local': 1400, 'age': 21, 'days_employed': 89, 'hours': 42, 'paid': 70854}, [1400, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 900, 'age': 35, 'days_employed': 10, 'hours': 27, 'paid': 8188}, [900, 16112])], [('regression', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 89, 'hours': 27, 'paid': 71203}, [1400, 0]), ('regression', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 90, 'hours': 17, 'paid': 63085}, [1400, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 17, 'days_employed': 90, 'hours': 37, 'paid': 49772}, [1400, 2028]), ('normal control', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 200, 'hours': 2, 'paid': 39319}, [900, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 21, 'days_employed': 100, 'hours': 38, 'paid': 59758}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 35, 'days_employed': 91, 'hours': 1, 'paid': 31574}, [1500, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 21, 'days_employed': 89, 'hours': 20, 'paid': 19880}, [1500, 10120])], [('regression', {'federal': 725, 'state': None, 'local': 900, 'age': 17, 'days_employed': 10, 'hours': 4, 'paid': 8906}, [900, 0]), ('regression', {'federal': 725, 'state': 800, 'local': 1700, 'age': 19, 'days_employed': 10, 'hours': 35, 'paid': 45995}, [1700, 13505]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1400, 'age': 19, 'days_employed': 89, 'hours': 11, 'paid': 62799}, [1400, 0]), ('partial-repair probe', {'federal': 725, 'state': None, 'local': 1700, 'age': 19, 'days_employed': 90, 'hours': 1, 'paid': 33812}, [1700, 0]), ('normal control', {'federal': 725, 'state': 1500, 'local': 1400, 'age': 20, 'days_employed': 89, 'hours': 13, 'paid': 20235}, [1500, 0]), ('normal control', {'federal': 725, 'state': 800, 'local': 1700, 'age': 17, 'days_employed': 119, 'hours': 36, 'paid': 42057}, [1700, 19143]), ('normal control', {'federal': 725, 'state': 1500, 'local': None, 'age': 19, 'days_employed': 100, 'hours': 21, 'paid': 76399}, [1500, 0]), ('normal control', {'federal': 725, 'state': None, 'local': None, 'age': 20, 'days_employed': 91, 'hours': 50, 'paid': 25834}, [725, 10416])]]
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:
Young workers in states with their own minimum wage are paid the youth rate.

Input {federal, state|None, local|None, age, days_employed, hours, paid}. Applicable rate is the highest of the defined federal, state and local minimums. A youth rate of 4.25 may replace it when age < 20, days_employed <= 90 and neither a state nor local minimum is defined. Return [rate, max(0, hours*rate - paid)].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(x['wage'] * x['periods'], 1)
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 4000000) * Fraction(24, 100)
        return t
    due = tax(annual) * k / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 0), ('normal control', {'ytd_wages': 30504, 'ytd_wh': 1425, 'wage': 14017, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 255421, 'ytd_wh': 47741, 'wage': 37513, 'period_index': 11, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 4101816, 'ytd_wh': 781382, 'wage': 93819, 'period_index': 46, 'periods': 52}, 0), ('normal control', {'ytd_wages': 1734664, 'ytd_wh': 216863, 'wage': 75980, 'period_index': 15, 'periods': 26}, 0), ('normal control', {'ytd_wages': 2864664, 'ytd_wh': 419863, 'wage': 94961, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 430759, 'ytd_wh': 55675, 'wage': 54560, 'period_index': 5, 'periods': 12}, 0)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 353147, 'ytd_wh': 9536, 'wage': 96030, 'period_index': 6, 'periods': 12}, 0), ('normal control', {'ytd_wages': 659564, 'ytd_wh': 7849, 'wage': 18236, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 2446975, 'ytd_wh': 466368, 'wage': 202023, 'period_index': 12, 'periods': 12}, 0), ('normal control', {'ytd_wages': 152088, 'ytd_wh': 11592, 'wage': 17915, 'period_index': 8, 'periods': 26}, 0)], [('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('regression', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('partial-repair probe', {'ytd_wages': 7572146, 'ytd_wh': 1352041, 'wage': 228907, 'period_index': 18, 'periods': 52}, 312519), ('normal control', {'ytd_wages': 2303411, 'ytd_wh': 406780, 'wage': 112030, 'period_index': 23, 'periods': 26}, 0), ('normal control', {'ytd_wages': 288287, 'ytd_wh': 41455, 'wage': 26146, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 102743, 'ytd_wh': 20507, 'wage': 5626, 'period_index': 12, 'periods': 12}, 0), ('normal control', {'ytd_wages': 1160977, 'ytd_wh': 199709, 'wage': 91537, 'period_index': 11, 'periods': 26}, 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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(total * x['periods'], x['periods'])
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 4000000) * Fraction(24, 100)
        return t
    due = tax(annual) * k / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 0), ('normal control', {'ytd_wages': 30504, 'ytd_wh': 1425, 'wage': 14017, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 255421, 'ytd_wh': 47741, 'wage': 37513, 'period_index': 11, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 4101816, 'ytd_wh': 781382, 'wage': 93819, 'period_index': 46, 'periods': 52}, 0), ('normal control', {'ytd_wages': 1734664, 'ytd_wh': 216863, 'wage': 75980, 'period_index': 15, 'periods': 26}, 0), ('normal control', {'ytd_wages': 2864664, 'ytd_wh': 419863, 'wage': 94961, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 430759, 'ytd_wh': 55675, 'wage': 54560, 'period_index': 5, 'periods': 12}, 0)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 353147, 'ytd_wh': 9536, 'wage': 96030, 'period_index': 6, 'periods': 12}, 0), ('normal control', {'ytd_wages': 659564, 'ytd_wh': 7849, 'wage': 18236, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 2446975, 'ytd_wh': 466368, 'wage': 202023, 'period_index': 12, 'periods': 12}, 0), ('normal control', {'ytd_wages': 152088, 'ytd_wh': 11592, 'wage': 17915, 'period_index': 8, 'periods': 26}, 0)], [('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('regression', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('partial-repair probe', {'ytd_wages': 7572146, 'ytd_wh': 1352041, 'wage': 228907, 'period_index': 18, 'periods': 52}, 312519), ('normal control', {'ytd_wages': 2303411, 'ytd_wh': 406780, 'wage': 112030, 'period_index': 23, 'periods': 26}, 0), ('normal control', {'ytd_wages': 288287, 'ytd_wh': 41455, 'wage': 26146, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 102743, 'ytd_wh': 20507, 'wage': 5626, 'period_index': 12, 'periods': 12}, 0), ('normal control', {'ytd_wages': 1160977, 'ytd_wh': 199709, 'wage': 91537, 'period_index': 11, 'periods': 26}, 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:
Employees on the cumulative method are withheld as if on the ordinary per-period method.

Input {ytd_wages, ytd_wh, wage, period_index k (1-based, includes this period), periods}. Annualized = (ytd_wages + wage)*periods/k exactly. Annual tax: 0% to 10,000.00, 12% to 40,000.00, 24% above. Tax to date = annual tax * k/periods. Withholding = max(0, tax_to_date - ytd_wh) rounded half-up at the end.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(total * x['periods'], k)
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 4000000) * Fraction(24, 100)
        return t
    due = tax(annual) / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('normal control', {'ytd_wages': 2268722, 'ytd_wh': 255963, 'wage': 370037, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 32735, 'ytd_wh': 3167, 'wage': 155253, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 507467, 'ytd_wh': 39498, 'wage': 384392, 'period_index': 10, 'periods': 12}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 5196549, 'ytd_wh': 1001382, 'wage': 210690, 'period_index': 42, 'periods': 52}, 0), ('normal control', {'ytd_wages': 1078164, 'ytd_wh': 161049, 'wage': 458540, 'period_index': 6, 'periods': 12}, 0)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 978329, 'ytd_wh': 122337, 'wage': 298469, 'period_index': 9, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3416481, 'ytd_wh': 668694, 'wage': 525477, 'period_index': 15, 'periods': 26}, 0), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 0)], [('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('regression', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 3055036, 'ytd_wh': 132701, 'wage': 516493, 'period_index': 12, 'periods': 12}, 175882), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('normal control', {'ytd_wages': 343578, 'ytd_wh': 51820, 'wage': 340882, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 30504, 'ytd_wh': 1425, 'wage': 14017, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 255421, 'ytd_wh': 47741, 'wage': 37513, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 4101816, 'ytd_wh': 781382, 'wage': 93819, 'period_index': 46, 'periods': 52}, 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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(total * x['periods'], k)
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 4000000) * Fraction(24, 100)
        return t
    due = tax(annual) * (k - 1) / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('normal control', {'ytd_wages': 2268722, 'ytd_wh': 255963, 'wage': 370037, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 32735, 'ytd_wh': 3167, 'wage': 155253, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 507467, 'ytd_wh': 39498, 'wage': 384392, 'period_index': 10, 'periods': 12}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 5196549, 'ytd_wh': 1001382, 'wage': 210690, 'period_index': 42, 'periods': 52}, 0), ('normal control', {'ytd_wages': 1078164, 'ytd_wh': 161049, 'wage': 458540, 'period_index': 6, 'periods': 12}, 0)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 978329, 'ytd_wh': 122337, 'wage': 298469, 'period_index': 9, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3416481, 'ytd_wh': 668694, 'wage': 525477, 'period_index': 15, 'periods': 26}, 0), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 0)], [('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('regression', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 3055036, 'ytd_wh': 132701, 'wage': 516493, 'period_index': 12, 'periods': 12}, 175882), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('normal control', {'ytd_wages': 343578, 'ytd_wh': 51820, 'wage': 340882, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 30504, 'ytd_wh': 1425, 'wage': 14017, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 255421, 'ytd_wh': 47741, 'wage': 37513, 'period_index': 11, 'periods': 12}, 0), ('normal control', {'ytd_wages': 4101816, 'ytd_wh': 781382, 'wage': 93819, 'period_index': 46, 'periods': 52}, 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 collapses to a single period's share of tax despite prior withholding being subtracted.

Input {ytd_wages, ytd_wh, wage, period_index k (1-based, includes this period), periods}. Annualized = (ytd_wages + wage)*periods/k exactly. Annual tax: 0% to 10,000.00, 12% to 40,000.00, 24% above. Tax to date = annual tax * k/periods. Withholding = max(0, tax_to_date - ytd_wh) rounded half-up at the end.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(total * x['periods'], k)
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 1000000) * Fraction(24, 100)
        return t
    due = tax(annual) * k / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('normal control', {'ytd_wages': 2268722, 'ytd_wh': 255963, 'wage': 370037, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 32735, 'ytd_wh': 3167, 'wage': 155253, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 507467, 'ytd_wh': 39498, 'wage': 384392, 'period_index': 10, 'periods': 12}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3055036, 'ytd_wh': 132701, 'wage': 516493, 'period_index': 12, 'periods': 12}, 175882), ('normal control', {'ytd_wages': 36870, 'ytd_wh': 6321, 'wage': 487926, 'period_index': 2, 'periods': 12}, 36655)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 1078164, 'ytd_wh': 161049, 'wage': 458540, 'period_index': 6, 'periods': 12}, 0), ('normal control', {'ytd_wages': 978329, 'ytd_wh': 122337, 'wage': 298469, 'period_index': 9, 'periods': 26}, 0), ('normal control', {'ytd_wages': 81196, 'ytd_wh': 9361, 'wage': 306786, 'period_index': 2, 'periods': 12}, 17197), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0)], [('regression', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('partial-repair probe', {'ytd_wages': 7572146, 'ytd_wh': 1352041, 'wage': 228907, 'period_index': 18, 'periods': 52}, 312519), ('normal control', {'ytd_wages': 1412754, 'ytd_wh': 40526, 'wage': 95617, 'period_index': 11, 'periods': 12}, 30479), ('normal control', {'ytd_wages': 867698, 'ytd_wh': 9315, 'wage': 86343, 'period_index': 8, 'periods': 12}, 25170), ('normal control', {'ytd_wages': 179570, 'ytd_wh': 6855, 'wage': 84088, 'period_index': 5, 'periods': 52}, 13245), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    k = x['period_index']
    total = x['ytd_wages'] + x['wage']
    annual = Fraction(total * x['periods'], k)
    def tax(a):
        t = Fraction(0)
        if a > 1000000:
            t += (min(a, 4000000) - 1000000) * Fraction(12, 100)
        if a > 4000000:
            t += (a - 4000000) * Fraction(12, 100)
        return t
    due = tax(annual) * k / x['periods']
    wh = max(0, due - x['ytd_wh'])
    return math.floor(wh + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'ytd_wages': 7060061, 'ytd_wh': 424656, 'wage': 491569, 'period_index': 24, 'periods': 52}, 1110812), ('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('partial-repair probe', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('normal control', {'ytd_wages': 2182615, 'ytd_wh': 379871, 'wage': 414670, 'period_index': 20, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3504142, 'ytd_wh': 423680, 'wage': 219362, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 953768, 'ytd_wh': 32122, 'wage': 67782, 'period_index': 21, 'periods': 26}, 0), ('normal control', {'ytd_wages': 185427, 'ytd_wh': 36091, 'wage': 108159, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 9590400, 'ytd_wh': 237513, 'wage': 534789, 'period_index': 22, 'periods': 26}, 1684840), ('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('partial-repair probe', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('normal control', {'ytd_wages': 2268722, 'ytd_wh': 255963, 'wage': 370037, 'period_index': 8, 'periods': 12}, 0), ('normal control', {'ytd_wages': 141603, 'ytd_wh': 11497, 'wage': 15563, 'period_index': 7, 'periods': 12}, 0), ('normal control', {'ytd_wages': 29165, 'ytd_wh': 3348, 'wage': 5167, 'period_index': 8, 'periods': 52}, 0), ('normal control', {'ytd_wages': 32735, 'ytd_wh': 3167, 'wage': 155253, 'period_index': 2, 'periods': 12}, 0)], [('regression', {'ytd_wages': 8775450, 'ytd_wh': 1616919, 'wage': 334681, 'period_index': 24, 'periods': 26}, 15666), ('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('partial-repair probe', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('normal control', {'ytd_wages': 507467, 'ytd_wh': 39498, 'wage': 384392, 'period_index': 10, 'periods': 12}, 0), ('normal control', {'ytd_wages': 2675147, 'ytd_wh': 522064, 'wage': 171429, 'period_index': 26, 'periods': 26}, 0), ('normal control', {'ytd_wages': 3055036, 'ytd_wh': 132701, 'wage': 516493, 'period_index': 12, 'periods': 12}, 175882), ('normal control', {'ytd_wages': 36870, 'ytd_wh': 6321, 'wage': 487926, 'period_index': 2, 'periods': 12}, 36655)], [('regression', {'ytd_wages': 6145936, 'ytd_wh': 219937, 'wage': 315568, 'period_index': 15, 'periods': 52}, 1157747), ('regression', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('partial-repair probe', {'ytd_wages': 2724662, 'ytd_wh': 86701, 'wage': 332622, 'period_index': 7, 'periods': 52}, 566278), ('partial-repair probe', {'ytd_wages': 1665992, 'ytd_wh': 58323, 'wage': 387492, 'period_index': 4, 'periods': 12}, 234513), ('normal control', {'ytd_wages': 1078164, 'ytd_wh': 161049, 'wage': 458540, 'period_index': 6, 'periods': 12}, 0), ('normal control', {'ytd_wages': 978329, 'ytd_wh': 122337, 'wage': 298469, 'period_index': 9, 'periods': 26}, 0), ('normal control', {'ytd_wages': 81196, 'ytd_wh': 9361, 'wage': 306786, 'period_index': 2, 'periods': 12}, 17197), ('normal control', {'ytd_wages': 78474, 'ytd_wh': 12616, 'wage': 2681, 'period_index': 35, 'periods': 52}, 0)], [('regression', {'ytd_wages': 0, 'ytd_wh': 1, 'wage': 366567, 'period_index': 1, 'periods': 12}, 37975), ('regression', {'ytd_wages': 4585857, 'ytd_wh': 265867, 'wage': 360821, 'period_index': 12, 'periods': 26}, 644413), ('partial-repair probe', {'ytd_wages': 17382079, 'ytd_wh': 703861, 'wage': 564605, 'period_index': 25, 'periods': 52}, 3314882), ('partial-repair probe', {'ytd_wages': 7572146, 'ytd_wh': 1352041, 'wage': 228907, 'period_index': 18, 'periods': 52}, 312519), ('normal control', {'ytd_wages': 1412754, 'ytd_wh': 40526, 'wage': 95617, 'period_index': 11, 'periods': 12}, 30479), ('normal control', {'ytd_wages': 867698, 'ytd_wh': 9315, 'wage': 86343, 'period_index': 8, 'periods': 12}, 25170), ('normal control', {'ytd_wages': 179570, 'ytd_wh': 6855, 'wage': 84088, 'period_index': 5, 'periods': 52}, 13245), ('normal control', {'ytd_wages': 780083, 'ytd_wh': 115357, 'wage': 60520, 'period_index': 12, 'periods': 26}, 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:
High earners are withheld far more than the bracket schedule implies.

Input {ytd_wages, ytd_wh, wage, period_index k (1-based, includes this period), periods}. Annualized = (ytd_wages + wage)*periods/k exactly. Annual tax: 0% to 10,000.00, 12% to 40,000.00, 24% above. Tax to date = annual tax * k/periods. Withholding = max(0, tax_to_date - ytd_wh) rounded half-up at the end.

split: open-access


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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('regression', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('partial-repair probe', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('partial-repair probe', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3})], [('regression', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('regression', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('partial-repair probe', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('partial-repair probe', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('normal control', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1})], [('regression', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('regression', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('partial-repair probe', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('normal control', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14})], [('regression', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('regression', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('partial-repair probe', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27}), ('partial-repair probe', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('normal control', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989})], [('regression', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('regression', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('partial-repair probe', {'wage': 402912, 'days': {'CT': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 402912}), ('partial-repair probe', {'wage': 891837, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 891837}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 10, 'days': {'CT': 19, 'MA': 0}, 'resident': 'NJ'}, {'CT': 10}), ('normal control', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('normal control', {'wage': 200160, 'days': {'CT': 0, 'NJ': 3, 'NY': 17, 'PA': 0}, 'resident': 'CT'}, {'NY': 170136, 'NJ': 30024}), ('normal control', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597})]]
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):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {s: 0 for s in days}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('regression', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('partial-repair probe', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('partial-repair probe', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3})], [('regression', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('regression', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('partial-repair probe', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('partial-repair probe', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('normal control', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1})], [('regression', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('regression', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('partial-repair probe', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('normal control', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14})], [('regression', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('regression', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('partial-repair probe', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27}), ('partial-repair probe', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('normal control', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989})], [('regression', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('regression', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('partial-repair probe', {'wage': 402912, 'days': {'CT': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 402912}), ('partial-repair probe', {'wage': 891837, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 891837}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('normal control', {'wage': 10, 'days': {'CT': 19, 'MA': 0}, 'resident': 'NJ'}, {'CT': 10}), ('normal control', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('normal control', {'wage': 200160, 'days': {'CT': 0, 'NJ': 3, 'NY': 17, 'PA': 0}, 'resident': 'CT'}, {'NY': 170136, 'NJ': 30024}), ('normal control', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597})]]
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:
Remote employees with no recorded work days have wages allocated to no state.

Input {wage, days: {state: work days}, resident}. With zero total days all wages go to the resident state. Otherwise each state gets floor(wage*days/total); leftover cents go one each to states ranked by largest fractional remainder, ties by the base order (days descending, then state name). States allocated 0 cents are omitted. Return {state: cents}.

split: open-access


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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = order
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3}), ('regression', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('partial-repair probe', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('partial-repair probe', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22})], [('regression', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('regression', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('partial-repair probe', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('partial-repair probe', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1})], [('regression', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('regression', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989}), ('partial-repair probe', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14})], [('regression', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989}), ('regression', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('partial-repair probe', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 10, 'days': {'CT': 19, 'MA': 0}, 'resident': 'NJ'}, {'CT': 10}), ('normal control', {'wage': 200160, 'days': {'CT': 0, 'NJ': 3, 'NY': 17, 'PA': 0}, 'resident': 'CT'}, {'NY': 170136, 'NJ': 30024}), ('normal control', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27})], [('regression', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('regression', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('partial-repair probe', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('partial-repair probe', {'wage': 22, 'days': {'PA': 0, 'CT': 1, 'MA': 2, 'NJ': 1}, 'resident': 'NY'}, {'MA': 11, 'CT': 6, 'NJ': 5}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 29, 'days': {'PA': 2}, 'resident': 'NJ'}, {'PA': 29}), ('normal control', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522}), ('normal control', {'wage': 402912, 'days': {'CT': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 402912}), ('normal control', {'wage': 891837, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 891837})]]
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):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (x['wage'] * days[s] % total, order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3}), ('regression', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('partial-repair probe', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('partial-repair probe', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22})], [('regression', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('regression', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('partial-repair probe', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('partial-repair probe', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1})], [('regression', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('regression', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989}), ('partial-repair probe', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14})], [('regression', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989}), ('regression', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('partial-repair probe', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 10, 'days': {'CT': 19, 'MA': 0}, 'resident': 'NJ'}, {'CT': 10}), ('normal control', {'wage': 200160, 'days': {'CT': 0, 'NJ': 3, 'NY': 17, 'PA': 0}, 'resident': 'CT'}, {'NY': 170136, 'NJ': 30024}), ('normal control', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27})], [('regression', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('regression', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('partial-repair probe', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('partial-repair probe', {'wage': 22, 'days': {'PA': 0, 'CT': 1, 'MA': 2, 'NJ': 1}, 'resident': 'NY'}, {'MA': 11, 'CT': 6, 'NJ': 5}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 29, 'days': {'PA': 2}, 'resident': 'NJ'}, {'PA': 29}), ('normal control', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522}), ('normal control', {'wage': 402912, 'days': {'CT': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 402912}), ('normal control', {'wage': 891837, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 891837})]]
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:
Leftover cents go to the states with the most days instead of the largest fractional shares.

Input {wage, days: {state: work days}, resident}. With zero total days all wages go to the resident state. Otherwise each state gets floor(wage*days/total); leftover cents go one each to states ranked by largest fractional remainder, ties by the base order (days descending, then state name). States allocated 0 cents are omitted. Return {state: cents}.

split: open-access