broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = base + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, 40)
    premium = rr * ot / 2
    prem_c = math.floor(premium + Fraction(1, 2))
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252])], [('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452])], [('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068])], [('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('partial-repair probe', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460]), ('normal control', {'hours': 17, 'rate': 3366, 'bonus': 396, 'discretionary': True, 'diff_hours': 8, 'diff': 0}, [0, 57618]), ('normal control', {'hours': 1, 'rate': 1458, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 1458])], [('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('regression', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('partial-repair probe', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('partial-repair probe', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 40, 'rate': 2719, 'bonus': 0, 'discretionary': False, 'diff_hours': 13, 'diff': 100}, [0, 110060]), ('normal control', {'hours': 32, 'rate': 3242, 'bonus': 990, 'discretionary': True, 'diff_hours': 0, 'diff': 48}, [0, 104734]), ('normal control', {'hours': 23, 'rate': 2339, 'bonus': 720, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 54517]), ('normal control', {'hours': 22, 'rate': 2030, 'bonus': 44512, 'discretionary': False, 'diff_hours': 13, 'diff': 183}, [0, 91551])]]
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):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = base + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, h + ot)
    premium = rr * ot / 2
    prem_c = math.floor(premium + Fraction(1, 2))
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252])], [('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452])], [('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068])], [('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('partial-repair probe', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460]), ('normal control', {'hours': 17, 'rate': 3366, 'bonus': 396, 'discretionary': True, 'diff_hours': 8, 'diff': 0}, [0, 57618]), ('normal control', {'hours': 1, 'rate': 1458, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 1458])], [('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('regression', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('partial-repair probe', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('partial-repair probe', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 40, 'rate': 2719, 'bonus': 0, 'discretionary': False, 'diff_hours': 13, 'diff': 100}, [0, 110060]), ('normal control', {'hours': 32, 'rate': 3242, 'bonus': 990, 'discretionary': True, 'diff_hours': 0, 'diff': 48}, [0, 104734]), ('normal control', {'hours': 23, 'rate': 2339, 'bonus': 720, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 54517]), ('normal control', {'hours': 22, 'rate': 2030, 'bonus': 44512, 'discretionary': False, 'diff_hours': 13, 'diff': 183}, [0, 91551])]]
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 working long weeks receive an inflated overtime premium.

Input weekly {hours, rate, bonus, discretionary, diff_hours, diff}. Straight pay = hours*rate + diff_hours*diff. Regular rate = (straight pay + bonus unless discretionary) / hours. Overtime premium = regular rate * max(0, hours-40) / 2, rounded half-up to the cent. Total = straight pay + bonus + premium. Zero hours returns [0, bonus]. Return [premium, total].

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):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = h * x['rate'] + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, h)
    premium = rr * ot / 2
    prem_c = math.floor(premium + Fraction(1, 2))
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744])], [('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422])], [('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('partial-repair probe', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341])], [('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('regression', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('partial-repair probe', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('partial-repair probe', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068]), ('normal control', {'hours': 58, 'rate': 1280, 'bonus': 145, 'discretionary': False, 'diff_hours': 5, 'diff': 0}, [11543, 85928]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545])], [('regression', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('regression', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('partial-repair probe', {'hours': 52, 'rate': 2128, 'bonus': 978, 'discretionary': True, 'diff_hours': 9, 'diff': 100}, [12872, 125406]), ('partial-repair probe', {'hours': 51, 'rate': 3958, 'bonus': 443, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [21769, 224070]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460]), ('normal control', {'hours': 17, 'rate': 3366, 'bonus': 396, 'discretionary': True, 'diff_hours': 8, 'diff': 0}, [0, 57618]), ('normal control', {'hours': 1, 'rate': 1458, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 1458]), ('normal control', {'hours': 40, 'rate': 2719, 'bonus': 0, 'discretionary': False, 'diff_hours': 13, 'diff': 100}, [0, 110060])]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = h * (x['rate'] + x['diff']) + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, h)
    premium = rr * ot / 2
    prem_c = math.floor(premium + Fraction(1, 2))
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744])], [('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422])], [('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617]), ('partial-repair probe', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341])], [('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('regression', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('partial-repair probe', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('partial-repair probe', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068]), ('normal control', {'hours': 58, 'rate': 1280, 'bonus': 145, 'discretionary': False, 'diff_hours': 5, 'diff': 0}, [11543, 85928]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545])], [('regression', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277]), ('regression', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('partial-repair probe', {'hours': 52, 'rate': 2128, 'bonus': 978, 'discretionary': True, 'diff_hours': 9, 'diff': 100}, [12872, 125406]), ('partial-repair probe', {'hours': 51, 'rate': 3958, 'bonus': 443, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [21769, 224070]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460]), ('normal control', {'hours': 17, 'rate': 3366, 'bonus': 396, 'discretionary': True, 'diff_hours': 8, 'diff': 0}, [0, 57618]), ('normal control', {'hours': 1, 'rate': 1458, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 1458]), ('normal control', {'hours': 40, 'rate': 2719, 'bonus': 0, 'discretionary': False, 'diff_hours': 13, 'diff': 100}, [0, 110060])]]
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:
Night-shift workers with overtime are underpaid on their premium.

Input weekly {hours, rate, bonus, discretionary, diff_hours, diff}. Straight pay = hours*rate + diff_hours*diff. Regular rate = (straight pay + bonus unless discretionary) / hours. Overtime premium = regular rate * max(0, hours-40) / 2, rounded half-up to the cent. Total = straight pay + bonus + premium. Zero hours returns [0, bonus]. Return [premium, total].

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):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = base + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, h)
    premium = rr * ot / 2
    prem_c = int(premium)
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 58, 'rate': 1280, 'bonus': 145, 'discretionary': False, 'diff_hours': 5, 'diff': 0}, [11543, 85928]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 55, 'rate': 3779, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [28343, 236188]), ('partial-repair probe', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('normal control', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617])], [('regression', {'hours': 55, 'rate': 3779, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [28343, 236188]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('partial-repair probe', {'hours': 49, 'rate': 2297, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [10337, 122890]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277])], [('regression', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 59, 'rate': 1183, 'bonus': 15895, 'discretionary': True, 'diff_hours': 0, 'diff': 111}, [11239, 96931]), ('partial-repair probe', {'hours': 45, 'rate': 3152, 'bonus': 297, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [7897, 150034]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452])], [('regression', {'hours': 49, 'rate': 2297, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [10337, 122890]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 49, 'rate': 1393, 'bonus': 1015, 'discretionary': True, 'diff_hours': 13, 'diff': 0}, [6269, 75541]), ('partial-repair probe', {'hours': 41, 'rate': 3985, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 218}, [1993, 165378]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864])], [('regression', {'hours': 59, 'rate': 1183, 'bonus': 15895, 'discretionary': True, 'diff_hours': 0, 'diff': 111}, [11239, 96931]), ('regression', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('partial-repair probe', {'hours': 41, 'rate': 1613, 'bonus': 28839, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [807, 95779]), ('partial-repair probe', {'hours': 59, 'rate': 3943, 'bonus': 3183, 'discretionary': True, 'diff_hours': 0, 'diff': 50}, [37459, 273279]), ('normal control', {'hours': 51, 'rate': 3958, 'bonus': 443, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [21769, 224070]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460])]]
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):
    h = x['hours']
    base = h * x['rate'] + x['diff_hours'] * x['diff']
    included = base + (0 if x['discretionary'] else x['bonus'])
    if h == 0:
        return [0, x['bonus']]
    ot = max(0, h - 40)
    rr = Fraction(included, h)
    premium = rr * ot / 2
    prem_c = round(premium)
    total = base + x['bonus'] + prem_c
    return [prem_c, total]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'hours': 58, 'rate': 1280, 'bonus': 145, 'discretionary': False, 'diff_hours': 5, 'diff': 0}, [11543, 85928]), ('regression', {'hours': 48, 'rate': 2361, 'bonus': 0, 'discretionary': False, 'diff_hours': 15, 'diff': 150}, [9632, 125210]), ('partial-repair probe', {'hours': 55, 'rate': 3779, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [28343, 236188]), ('partial-repair probe', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('normal control', {'hours': 56, 'rate': 2894, 'bonus': 0, 'discretionary': True, 'diff_hours': 20, 'diff': 189}, [23692, 189536]), ('normal control', {'hours': 29, 'rate': 3185, 'bonus': 18960, 'discretionary': True, 'diff_hours': 0, 'diff': 235}, [0, 111325]), ('normal control', {'hours': 15, 'rate': 1913, 'bonus': 0, 'discretionary': False, 'diff_hours': 3, 'diff': 100}, [0, 28995]), ('normal control', {'hours': 42, 'rate': 2619, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [2619, 112617])], [('regression', {'hours': 55, 'rate': 3779, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [28343, 236188]), ('regression', {'hours': 45, 'rate': 1070, 'bonus': 6593, 'discretionary': True, 'diff_hours': 3, 'diff': 100}, [2692, 57735]), ('partial-repair probe', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('partial-repair probe', {'hours': 49, 'rate': 2297, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [10337, 122890]), ('normal control', {'hours': 36, 'rate': 1564, 'bonus': 12440, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 68744]), ('normal control', {'hours': 36, 'rate': 3124, 'bonus': 20788, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 133252]), ('normal control', {'hours': 38, 'rate': 3803, 'bonus': 0, 'discretionary': False, 'diff_hours': 5, 'diff': 175}, [0, 145389]), ('normal control', {'hours': 42, 'rate': 1092, 'bonus': 0, 'discretionary': False, 'diff_hours': 2, 'diff': 157}, [1099, 47277])], [('regression', {'hours': 50, 'rate': 3473, 'bonus': 15335, 'discretionary': False, 'diff_hours': 14, 'diff': 0}, [18899, 207884]), ('regression', {'hours': 60, 'rate': 3726, 'bonus': 328, 'discretionary': False, 'diff_hours': 13, 'diff': 0}, [37315, 261203]), ('partial-repair probe', {'hours': 59, 'rate': 1183, 'bonus': 15895, 'discretionary': True, 'diff_hours': 0, 'diff': 111}, [11239, 96931]), ('partial-repair probe', {'hours': 45, 'rate': 3152, 'bonus': 297, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [7897, 150034]), ('normal control', {'hours': 40, 'rate': 2368, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 0}, [0, 94720]), ('normal control', {'hours': 41, 'rate': 1070, 'bonus': 0, 'discretionary': False, 'diff_hours': 14, 'diff': 300}, [586, 48656]), ('normal control', {'hours': 15, 'rate': 1275, 'bonus': 16297, 'discretionary': False, 'diff_hours': 0, 'diff': 100}, [0, 35422]), ('normal control', {'hours': 0, 'rate': 1235, 'bonus': 452, 'discretionary': False, 'diff_hours': 15, 'diff': 0}, [0, 452])], [('regression', {'hours': 49, 'rate': 2297, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [10337, 122890]), ('regression', {'hours': 51, 'rate': 1430, 'bonus': 583, 'discretionary': True, 'diff_hours': 17, 'diff': 212}, [8254, 85371]), ('partial-repair probe', {'hours': 49, 'rate': 1393, 'bonus': 1015, 'discretionary': True, 'diff_hours': 13, 'diff': 0}, [6269, 75541]), ('partial-repair probe', {'hours': 41, 'rate': 3985, 'bonus': 0, 'discretionary': False, 'diff_hours': 0, 'diff': 218}, [1993, 165378]), ('normal control', {'hours': 25, 'rate': 2784, 'bonus': 431, 'discretionary': False, 'diff_hours': 0, 'diff': 150}, [0, 70031]), ('normal control', {'hours': 49, 'rate': 2740, 'bonus': 1615, 'discretionary': True, 'diff_hours': 20, 'diff': 0}, [12330, 148205]), ('normal control', {'hours': 4, 'rate': 2630, 'bonus': 24821, 'discretionary': False, 'diff_hours': 10, 'diff': 100}, [0, 36341]), ('normal control', {'hours': 36, 'rate': 3824, 'bonus': 0, 'discretionary': False, 'diff_hours': 12, 'diff': 100}, [0, 138864])], [('regression', {'hours': 59, 'rate': 1183, 'bonus': 15895, 'discretionary': True, 'diff_hours': 0, 'diff': 111}, [11239, 96931]), ('regression', {'hours': 41, 'rate': 1051, 'bonus': 26, 'discretionary': False, 'diff_hours': 0, 'diff': 259}, [526, 43643]), ('partial-repair probe', {'hours': 41, 'rate': 1613, 'bonus': 28839, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [807, 95779]), ('partial-repair probe', {'hours': 59, 'rate': 3943, 'bonus': 3183, 'discretionary': True, 'diff_hours': 0, 'diff': 50}, [37459, 273279]), ('normal control', {'hours': 51, 'rate': 3958, 'bonus': 443, 'discretionary': True, 'diff_hours': 0, 'diff': 100}, [21769, 224070]), ('normal control', {'hours': 36, 'rate': 3363, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 0}, [0, 121068]), ('normal control', {'hours': 25, 'rate': 1555, 'bonus': 17670, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 56545]), ('normal control', {'hours': 13, 'rate': 3420, 'bonus': 0, 'discretionary': True, 'diff_hours': 0, 'diff': 150}, [0, 44460])]]
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:
Overtime premiums ending in a half cent or more are a cent short.

Input weekly {hours, rate, bonus, discretionary, diff_hours, diff}. Straight pay = hours*rate + diff_hours*diff. Regular rate = (straight pay + bonus unless discretionary) / hours. Overtime premium = regular rate * max(0, hours-40) / 2, rounded half-up to the cent. Total = straight pay + bonus + premium. Zero hours returns [0, bonus]. Return [premium, total].

split: open-access


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

N = 1
observations = []
def solve(x):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = [res, work]
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('partial-repair probe', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('normal control', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('regression', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078})], [('regression', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('regression', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('partial-repair probe', {'wage': 321348, 'res': 'MI', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 500, 'OH': 350, 'MI': 350, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'MI': 11247}), ('partial-repair probe', {'wage': 42946, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 549, 'OH': 206, 'MI': 0, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': False}, {'MI': 0}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305})], [('regression', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('regression', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('partial-repair probe', {'wage': 343460, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 500, 'KY': 425, 'WV': 500}, 'res_credit': True}, {'MI': 21878}), ('partial-repair probe', {'wage': 331933, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 350, 'MI': 307, 'IN': 425, 'KY': 528, 'WV': 500}, 'res_credit': True}, {'MI': 10190}), ('normal control', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775})], [('regression', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('regression', {'wage': 332082, 'res': 'PA', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 160, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 672, 'KY': 322, 'WV': 500}, 'res_credit': True}, {'PA': 5313}), ('partial-repair probe', {'wage': 238028, 'res': 'NJ', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 0, 'MI': 209, 'IN': 523, 'KY': 0, 'WV': 307}, 'res_credit': False}, {'NJ': 0}), ('partial-repair probe', {'wage': 123644, 'res': 'KY', 'work': 'OH', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 350, 'MI': 307, 'IN': 460, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'KY': 7876}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})]]
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['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = [work, res]
    if pair in x['reciprocal']:
        return {res: tax(res)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('partial-repair probe', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('normal control', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('regression', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078})], [('regression', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('regression', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('partial-repair probe', {'wage': 321348, 'res': 'MI', 'work': 'OH', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 500, 'OH': 350, 'MI': 350, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'MI': 11247}), ('partial-repair probe', {'wage': 42946, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 549, 'OH': 206, 'MI': 0, 'IN': 307, 'KY': 425, 'WV': 425}, 'res_credit': False}, {'MI': 0}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305})], [('regression', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('regression', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('partial-repair probe', {'wage': 343460, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 500, 'KY': 425, 'WV': 500}, 'res_credit': True}, {'MI': 21878}), ('partial-repair probe', {'wage': 331933, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 350, 'MI': 307, 'IN': 425, 'KY': 528, 'WV': 500}, 'res_credit': True}, {'MI': 10190}), ('normal control', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775})], [('regression', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('regression', {'wage': 332082, 'res': 'PA', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 160, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 672, 'KY': 322, 'WV': 500}, 'res_credit': True}, {'PA': 5313}), ('partial-repair probe', {'wage': 238028, 'res': 'NJ', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 0, 'MI': 209, 'IN': 523, 'KY': 0, 'WV': 307}, 'res_credit': False}, {'NJ': 0}), ('partial-repair probe', {'wage': 123644, 'res': 'KY', 'work': 'OH', 'reciprocal': [['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 350, 'MI': 307, 'IN': 460, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'KY': 7876}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})]]
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:
Some reciprocity agreements are ignored depending on which state is the residence.

Input {wage, res, work, reciprocal:[sorted state pairs], rates:{state: basis points}, res_credit}. Tax for a state = wage*rate/10000 half-up. Same state: withhold only there. Reciprocal pair: withhold only the resident state. Otherwise withhold the work state; the resident state gets max(0, resident - work) when res_credit else its full tax; omit zero resident lines. Return {state: cents}.

split: open-access


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

N = 1
observations = []
def solve(x):
    rates = x['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {work: tax(work)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('regression', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('partial-repair probe', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('normal control', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078})], [('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('regression', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305})], [('regression', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('partial-repair probe', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('normal control', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775})], [('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('regression', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('partial-repair probe', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('partial-repair probe', {'wage': 332082, 'res': 'PA', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 160, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 672, 'KY': 322, 'WV': 500}, 'res_credit': True}, {'PA': 5313}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})]]
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['rates']
    w = x['wage']
    def tax(st):
        return (w * rates.get(st, 0) + 5000) // 10000
    res, work = x['res'], x['work']
    if res == work:
        return {work: tax(work)}
    pair = sorted([res, work])
    if pair in x['reciprocal']:
        return {res: tax(work)}
    work_tax = tax(work)
    res_tax = max(0, tax(res) - work_tax) if x['res_credit'] else tax(res)
    out = {work: work_tax}
    if res_tax:
        out[res] = res_tax
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 379815, 'res': 'MI', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 637, 'OH': 0, 'MI': 637, 'IN': 350, 'KY': 307, 'WV': 242}, 'res_credit': True}, {'MI': 24194}), ('regression', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('partial-repair probe', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('normal control', {'wage': 92630, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 425, 'KY': 425, 'WV': 637}, 'res_credit': True}, {'WV': 5901}), ('normal control', {'wage': 333788, 'res': 'NJ', 'work': 'NJ', 'reciprocal': [['IN', 'KY']], 'rates': {'PA': 637, 'NJ': 425, 'OH': 446, 'MI': 500, 'IN': 122, 'KY': 312, 'WV': 0}, 'res_credit': True}, {'NJ': 14186}), ('normal control', {'wage': 108935, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 0, 'IN': 425, 'KY': 0, 'WV': 350}, 'res_credit': False}, {'WV': 3813}), ('normal control', {'wage': 267886, 'res': 'PA', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 637, 'KY': 0, 'WV': 637}, 'res_credit': False}, {'IN': 17064, 'PA': 13394})], [('regression', {'wage': 377853, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 637, 'OH': 502, 'MI': 637, 'IN': 500, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 18893}), ('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('partial-repair probe', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('normal control', {'wage': 243443, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 425, 'OH': 0, 'MI': 0, 'IN': 637, 'KY': 307, 'WV': 425}, 'res_credit': True}, {'IN': 15507}), ('normal control', {'wage': 348021, 'res': 'MI', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 307, 'NJ': 355, 'OH': 0, 'MI': 254, 'IN': 425, 'KY': 350, 'WV': 425}, 'res_credit': True}, {'KY': 12181}), ('normal control', {'wage': 133100, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 307, 'NJ': 500, 'OH': 500, 'MI': 350, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': True}, {'PA': 4086, 'KY': 2569}), ('normal control', {'wage': 202229, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 637, 'OH': 350, 'MI': 425, 'IN': 0, 'KY': 0, 'WV': 500}, 'res_credit': True}, {'PA': 7078})], [('regression', {'wage': 201266, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 425, 'OH': 500, 'MI': 500, 'IN': 637, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'OH': 10063}), ('regression', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('partial-repair probe', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('normal control', {'wage': 326976, 'res': 'OH', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 543, 'NJ': 500, 'OH': 500, 'MI': 0, 'IN': 350, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'NJ': 16349}), ('normal control', {'wage': 373364, 'res': 'MI', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 350, 'NJ': 611, 'OH': 307, 'MI': 637, 'IN': 0, 'KY': 500, 'WV': 637}, 'res_credit': False}, {'WV': 23783, 'MI': 23783}), ('normal control', {'wage': 391289, 'res': 'WV', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 0, 'OH': 500, 'MI': 350, 'IN': 425, 'KY': 350, 'WV': 350}, 'res_credit': True}, {'KY': 13695}), ('normal control', {'wage': 214002, 'res': 'KY', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 239, 'NJ': 637, 'OH': 156, 'MI': 0, 'IN': 350, 'KY': 300, 'WV': 350}, 'res_credit': True}, {'PA': 5115, 'KY': 1305})], [('regression', {'wage': 162145, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 350, 'MI': 425, 'IN': 425, 'KY': 0, 'WV': 425}, 'res_credit': False}, {'IN': 6891}), ('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('partial-repair probe', {'wage': 396110, 'res': 'OH', 'work': 'KY', 'reciprocal': [['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 350, 'OH': 3, 'MI': 425, 'IN': 425, 'KY': 637, 'WV': 425}, 'res_credit': True}, {'OH': 119}), ('partial-repair probe', {'wage': 176817, 'res': 'OH', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 425, 'MI': 350, 'IN': 307, 'KY': 500, 'WV': 350}, 'res_credit': True}, {'OH': 7515}), ('normal control', {'wage': 353313, 'res': 'OH', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY']], 'rates': {'PA': 500, 'NJ': 425, 'OH': 159, 'MI': 637, 'IN': 500, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'IN': 17666}), ('normal control', {'wage': 314004, 'res': 'IN', 'work': 'IN', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 350, 'OH': 307, 'MI': 637, 'IN': 307, 'KY': 180, 'WV': 425}, 'res_credit': True}, {'IN': 9640}), ('normal control', {'wage': 190832, 'res': 'KY', 'work': 'OH', 'reciprocal': [['MI', 'OH']], 'rates': {'PA': 637, 'NJ': 0, 'OH': 425, 'MI': 425, 'IN': 637, 'KY': 500, 'WV': 425}, 'res_credit': True}, {'OH': 8110, 'KY': 1432}), ('normal control', {'wage': 51460, 'res': 'KY', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 637, 'NJ': 307, 'OH': 425, 'MI': 350, 'IN': 637, 'KY': 652, 'WV': 0}, 'res_credit': True}, {'NJ': 1580, 'KY': 1775})], [('regression', {'wage': 332910, 'res': 'OH', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 425, 'NJ': 350, 'OH': 350, 'MI': 637, 'IN': 637, 'KY': 425, 'WV': 0}, 'res_credit': True}, {'OH': 11652}), ('regression', {'wage': 215870, 'res': 'IN', 'work': 'KY', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 500, 'NJ': 350, 'OH': 500, 'MI': 425, 'IN': 500, 'KY': 0, 'WV': 0}, 'res_credit': True}, {'IN': 10794}), ('partial-repair probe', {'wage': 202551, 'res': 'KY', 'work': 'IN', 'reciprocal': [['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 114, 'NJ': 637, 'OH': 637, 'MI': 350, 'IN': 141, 'KY': 238, 'WV': 356}, 'res_credit': True}, {'KY': 4821}), ('partial-repair probe', {'wage': 332082, 'res': 'PA', 'work': 'NJ', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 160, 'NJ': 425, 'OH': 425, 'MI': 637, 'IN': 672, 'KY': 322, 'WV': 500}, 'res_credit': True}, {'PA': 5313}), ('normal control', {'wage': 236355, 'res': 'PA', 'work': 'WV', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 425, 'NJ': 307, 'OH': 425, 'MI': 425, 'IN': 350, 'KY': 637, 'WV': 637}, 'res_credit': False}, {'WV': 15056, 'PA': 10045}), ('normal control', {'wage': 92712, 'res': 'MI', 'work': 'PA', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY']], 'rates': {'PA': 0, 'NJ': 425, 'OH': 425, 'MI': 250, 'IN': 350, 'KY': 637, 'WV': 350}, 'res_credit': False}, {'PA': 0, 'MI': 2318}), ('normal control', {'wage': 91863, 'res': 'NJ', 'work': 'OH', 'reciprocal': [['NJ', 'PA'], ['MI', 'OH'], ['IN', 'KY'], ['KY', 'OH']], 'rates': {'PA': 350, 'NJ': 307, 'OH': 350, 'MI': 549, 'IN': 307, 'KY': 637, 'WV': 590}, 'res_credit': False}, {'OH': 3215, 'NJ': 2820}), ('normal control', {'wage': 208890, 'res': 'KY', 'work': 'MI', 'reciprocal': [['NJ', 'PA'], ['KY', 'OH']], 'rates': {'PA': 0, 'NJ': 0, 'OH': 307, 'MI': 0, 'IN': 577, 'KY': 307, 'WV': 350}, 'res_credit': True}, {'MI': 0, 'KY': 6413})]]
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:
Commuters covered by reciprocity have tax sent to the work state instead of their home state.

Input {wage, res, work, reciprocal:[sorted state pairs], rates:{state: basis points}, res_credit}. Tax for a state = wage*rate/10000 half-up. Same state: withhold only there. Reciprocal pair: withhold only the resident state. Otherwise withhold the work state; the resident state gets max(0, resident - work) when res_credit else its full tax; omit zero resident lines. Return {state: cents}.

split: open-access