broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    target = Fraction(x['receipts'] * 8, 100)
    reported = sum(e[2] for e in x['staff'])
    short = target - reported
    if short <= 0:
        return {}
    hours_total = sum(e[1] for e in x['staff'])
    deficits = {}
    for name, hrs, rep in x['staff']:
        share = target * hrs / hours_total
        if rep <= share:
            deficits[name] = share - rep
    dsum = sum(deficits.values())
    out = {}
    for name, d in deficits.items():
        out[name] = math.floor(short * d / dsum + Fraction(1, 2))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'receipts': 404460, 'staff': [['ben', 32, 0], ['cy', 0, 0]]}, {'ben': 32357}), ('regression', {'receipts': 2293403, 'staff': [['eli', 2, 18937], ['dee', 32, 0], ['cy', 0, 0]]}, {'dee': 164535}), ('partial-repair probe', {'receipts': 1926229, 'staff': [['dee', 20, 0], ['eli', 23, 0], ['ben', 15, 23516], ['ana', 9, 0]]}, {'dee': 45999, 'eli': 52899, 'ben': 10984, 'ana': 20700}), ('partial-repair probe', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('normal control', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('normal control', {'receipts': 296732, 'staff': [['cy', 31, 25635], ['ben', 23, 0], ['ana', 23, 0]]}, {}), ('normal control', {'receipts': 550244, 'staff': [['cy', 19, 57024]]}, {}), ('normal control', {'receipts': 831709, 'staff': [['eli', 25, 0], ['dee', 27, 33872], ['cy', 8, 38931], ['ben', 2, 0]]}, {})], [('regression', {'receipts': 2293403, 'staff': [['eli', 2, 18937], ['dee', 32, 0], ['cy', 0, 0]]}, {'dee': 164535}), ('regression', {'receipts': 2880982, 'staff': [['dee', 30, 65246], ['eli', 0, 0], ['ana', 39, 55839], ['cy', 37, 0], ['ben', 1, 0]]}, {'ana': 28007, 'cy': 79245, 'ben': 2142}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('normal control', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('normal control', {'receipts': 2458851, 'staff': [['cy', 31, 15683], ['ben', 27, 76376]]}, {'cy': 89454, 'ben': 15195}), ('normal control', {'receipts': 2589131, 'staff': [['cy', 0, 9383], ['ana', 9, 74166], ['dee', 1, 54844]]}, {'ana': 68737}), ('normal control', {'receipts': 2640630, 'staff': [['eli', 21, 16955], ['dee', 0, 76011]]}, {'eli': 118284})], [('regression', {'receipts': 2880982, 'staff': [['dee', 30, 65246], ['eli', 0, 0], ['ana', 39, 55839], ['cy', 37, 0], ['ben', 1, 0]]}, {'ana': 28007, 'cy': 79245, 'ben': 2142}), ('regression', {'receipts': 1122488, 'staff': [['ben', 2, 31588], ['eli', 0, 0], ['dee', 15, 0]]}, {'dee': 58211}), ('partial-repair probe', {'receipts': 377533, 'staff': [['ben', 14, 0], ['eli', 20, 18063], ['dee', 33, 0]]}, {'ben': 3616, 'dee': 8524}), ('partial-repair probe', {'receipts': 789350, 'staff': [['dee', 24, 0], ['ben', 32, 0], ['cy', 33, 0], ['ana', 25, 0]]}, {'dee': 13294, 'ben': 17726, 'cy': 18280, 'ana': 13848}), ('normal control', {'receipts': 1484874, 'staff': [['cy', 38, 0], ['dee', 4, 11025], ['eli', 23, 61900], ['ana', 1, 55590]]}, {}), ('normal control', {'receipts': 414394, 'staff': [['ben', 30, 72971], ['dee', 11, 50779], ['cy', 12, 57744], ['ana', 33, 0], ['eli', 37, 0]]}, {}), ('normal control', {'receipts': 15877, 'staff': [['dee', 2, 0], ['ben', 29, 36864], ['cy', 36, 367]]}, {}), ('normal control', {'receipts': 325470, 'staff': [['ana', 24, 0], ['dee', 18, 39572]]}, {})], [('regression', {'receipts': 1122488, 'staff': [['ben', 2, 31588], ['eli', 0, 0], ['dee', 15, 0]]}, {'dee': 58211}), ('regression', {'receipts': 751513, 'staff': [['dee', 11, 23705], ['ana', 0, 0], ['cy', 8, 0]]}, {'dee': 11102, 'cy': 25314}), ('partial-repair probe', {'receipts': 1043666, 'staff': [['dee', 21, 0], ['eli', 31, 46444]]}, {'dee': 33718, 'eli': 3331}), ('partial-repair probe', {'receipts': 2921186, 'staff': [['cy', 25, 21684], ['dee', 15, 2874], ['eli', 3, 0], ['ana', 20, 0]]}, {'cy': 71052, 'dee': 52768, 'eli': 11128, 'ana': 74189}), ('normal control', {'receipts': 1844273, 'staff': [['ben', 6, 9908], ['cy', 2, 35253], ['dee', 0, 47647], ['eli', 24, 54448], ['ana', 19, 60962]]}, {}), ('normal control', {'receipts': 305915, 'staff': [['ben', 17, 0], ['cy', 35, 49832], ['dee', 14, 0]]}, {}), ('normal control', {'receipts': 97470, 'staff': [['ana', 8, 0], ['eli', 19, 14113], ['dee', 6, 49117], ['ben', 0, 0], ['cy', 33, 9103]]}, {}), ('normal control', {'receipts': 1562647, 'staff': [['dee', 25, 0], ['ana', 2, 45159], ['ben', 28, 79991], ['eli', 7, 0], ['cy', 29, 0]]}, {})], [('regression', {'receipts': 751513, 'staff': [['dee', 11, 23705], ['ana', 0, 0], ['cy', 8, 0]]}, {'dee': 11102, 'cy': 25314}), ('regression', {'receipts': 2167152, 'staff': [['ana', 0, 0], ['ben', 8, 8970], ['dee', 8, 0]]}, {'ben': 77716, 'dee': 86686}), ('partial-repair probe', {'receipts': 588846, 'staff': [['ana', 19, 0], ['cy', 28, 19233], ['eli', 8, 0]]}, {'ana': 16274, 'cy': 4749, 'eli': 6852}), ('partial-repair probe', {'receipts': 1019554, 'staff': [['dee', 11, 0]]}, {'dee': 81564}), ('normal control', {'receipts': 498706, 'staff': [['dee', 17, 44639], ['ana', 25, 0], ['cy', 9, 0]]}, {}), ('normal control', {'receipts': 937562, 'staff': [['eli', 3, 44205], ['ana', 5, 63945], ['dee', 2, 72206], ['cy', 27, 6437]]}, {}), ('normal control', {'receipts': 1576485, 'staff': [['ben', 34, 8023], ['dee', 32, 3525]]}, {'ben': 56947, 'dee': 57624}), ('normal control', {'receipts': 2072929, 'staff': [['dee', 16, 65338]]}, {'dee': 100496})]]
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):
    target = Fraction(x['receipts'] * 8, 100)
    reported = sum(e[2] for e in x['staff'])
    short = target - reported
    if short <= 0:
        return {}
    hours_total = sum(e[1] for e in x['staff'])
    deficits = {}
    for name, hrs, rep in x['staff']:
        share = target * hrs / hours_total
        if rep < share and rep > 0:
            deficits[name] = share - rep
    dsum = sum(deficits.values())
    out = {}
    for name, d in deficits.items():
        out[name] = math.floor(short * d / dsum + Fraction(1, 2))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'receipts': 404460, 'staff': [['ben', 32, 0], ['cy', 0, 0]]}, {'ben': 32357}), ('regression', {'receipts': 2293403, 'staff': [['eli', 2, 18937], ['dee', 32, 0], ['cy', 0, 0]]}, {'dee': 164535}), ('partial-repair probe', {'receipts': 1926229, 'staff': [['dee', 20, 0], ['eli', 23, 0], ['ben', 15, 23516], ['ana', 9, 0]]}, {'dee': 45999, 'eli': 52899, 'ben': 10984, 'ana': 20700}), ('partial-repair probe', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('normal control', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('normal control', {'receipts': 296732, 'staff': [['cy', 31, 25635], ['ben', 23, 0], ['ana', 23, 0]]}, {}), ('normal control', {'receipts': 550244, 'staff': [['cy', 19, 57024]]}, {}), ('normal control', {'receipts': 831709, 'staff': [['eli', 25, 0], ['dee', 27, 33872], ['cy', 8, 38931], ['ben', 2, 0]]}, {})], [('regression', {'receipts': 2293403, 'staff': [['eli', 2, 18937], ['dee', 32, 0], ['cy', 0, 0]]}, {'dee': 164535}), ('regression', {'receipts': 2880982, 'staff': [['dee', 30, 65246], ['eli', 0, 0], ['ana', 39, 55839], ['cy', 37, 0], ['ben', 1, 0]]}, {'ana': 28007, 'cy': 79245, 'ben': 2142}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('normal control', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('normal control', {'receipts': 2458851, 'staff': [['cy', 31, 15683], ['ben', 27, 76376]]}, {'cy': 89454, 'ben': 15195}), ('normal control', {'receipts': 2589131, 'staff': [['cy', 0, 9383], ['ana', 9, 74166], ['dee', 1, 54844]]}, {'ana': 68737}), ('normal control', {'receipts': 2640630, 'staff': [['eli', 21, 16955], ['dee', 0, 76011]]}, {'eli': 118284})], [('regression', {'receipts': 2880982, 'staff': [['dee', 30, 65246], ['eli', 0, 0], ['ana', 39, 55839], ['cy', 37, 0], ['ben', 1, 0]]}, {'ana': 28007, 'cy': 79245, 'ben': 2142}), ('regression', {'receipts': 1122488, 'staff': [['ben', 2, 31588], ['eli', 0, 0], ['dee', 15, 0]]}, {'dee': 58211}), ('partial-repair probe', {'receipts': 377533, 'staff': [['ben', 14, 0], ['eli', 20, 18063], ['dee', 33, 0]]}, {'ben': 3616, 'dee': 8524}), ('partial-repair probe', {'receipts': 789350, 'staff': [['dee', 24, 0], ['ben', 32, 0], ['cy', 33, 0], ['ana', 25, 0]]}, {'dee': 13294, 'ben': 17726, 'cy': 18280, 'ana': 13848}), ('normal control', {'receipts': 1484874, 'staff': [['cy', 38, 0], ['dee', 4, 11025], ['eli', 23, 61900], ['ana', 1, 55590]]}, {}), ('normal control', {'receipts': 414394, 'staff': [['ben', 30, 72971], ['dee', 11, 50779], ['cy', 12, 57744], ['ana', 33, 0], ['eli', 37, 0]]}, {}), ('normal control', {'receipts': 15877, 'staff': [['dee', 2, 0], ['ben', 29, 36864], ['cy', 36, 367]]}, {}), ('normal control', {'receipts': 325470, 'staff': [['ana', 24, 0], ['dee', 18, 39572]]}, {})], [('regression', {'receipts': 1122488, 'staff': [['ben', 2, 31588], ['eli', 0, 0], ['dee', 15, 0]]}, {'dee': 58211}), ('regression', {'receipts': 751513, 'staff': [['dee', 11, 23705], ['ana', 0, 0], ['cy', 8, 0]]}, {'dee': 11102, 'cy': 25314}), ('partial-repair probe', {'receipts': 1043666, 'staff': [['dee', 21, 0], ['eli', 31, 46444]]}, {'dee': 33718, 'eli': 3331}), ('partial-repair probe', {'receipts': 2921186, 'staff': [['cy', 25, 21684], ['dee', 15, 2874], ['eli', 3, 0], ['ana', 20, 0]]}, {'cy': 71052, 'dee': 52768, 'eli': 11128, 'ana': 74189}), ('normal control', {'receipts': 1844273, 'staff': [['ben', 6, 9908], ['cy', 2, 35253], ['dee', 0, 47647], ['eli', 24, 54448], ['ana', 19, 60962]]}, {}), ('normal control', {'receipts': 305915, 'staff': [['ben', 17, 0], ['cy', 35, 49832], ['dee', 14, 0]]}, {}), ('normal control', {'receipts': 97470, 'staff': [['ana', 8, 0], ['eli', 19, 14113], ['dee', 6, 49117], ['ben', 0, 0], ['cy', 33, 9103]]}, {}), ('normal control', {'receipts': 1562647, 'staff': [['dee', 25, 0], ['ana', 2, 45159], ['ben', 28, 79991], ['eli', 7, 0], ['cy', 29, 0]]}, {})], [('regression', {'receipts': 751513, 'staff': [['dee', 11, 23705], ['ana', 0, 0], ['cy', 8, 0]]}, {'dee': 11102, 'cy': 25314}), ('regression', {'receipts': 2167152, 'staff': [['ana', 0, 0], ['ben', 8, 8970], ['dee', 8, 0]]}, {'ben': 77716, 'dee': 86686}), ('partial-repair probe', {'receipts': 588846, 'staff': [['ana', 19, 0], ['cy', 28, 19233], ['eli', 8, 0]]}, {'ana': 16274, 'cy': 4749, 'eli': 6852}), ('partial-repair probe', {'receipts': 1019554, 'staff': [['dee', 11, 0]]}, {'dee': 81564}), ('normal control', {'receipts': 498706, 'staff': [['dee', 17, 44639], ['ana', 25, 0], ['cy', 9, 0]]}, {}), ('normal control', {'receipts': 937562, 'staff': [['eli', 3, 44205], ['ana', 5, 63945], ['dee', 2, 72206], ['cy', 27, 6437]]}, {}), ('normal control', {'receipts': 1576485, 'staff': [['ben', 34, 8023], ['dee', 32, 3525]]}, {'ben': 56947, 'dee': 57624}), ('normal control', {'receipts': 2072929, 'staff': [['dee', 16, 65338]]}, {'dee': 100496})]]
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 who reported exactly their share are listed with zero-cent allocations.

Input {receipts, staff: [[name, hours, reported_tips]]} with positive total hours. Target = 8% of receipts. Shortfall = target - total reported; none -> {}. Each employee's share = target*hours/total_hours; employees reporting less than their share get deficit = share - reported. Shortfall is allocated in proportion to deficits, each rounded half-up. Return {name: cents}.

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):
    target = Fraction(x['receipts'] * 8, 100)
    reported = sum(e[2] for e in x['staff'])
    short = target - reported
    if short <= 0:
        return {}
    hours_total = sum(e[1] for e in x['staff'])
    deficits = {}
    for name, hrs, rep in x['staff']:
        share = short * hrs / hours_total
        if rep < share:
            deficits[name] = share - rep
    dsum = sum(deficits.values())
    out = {}
    for name, d in deficits.items():
        out[name] = math.floor(short * d / dsum + Fraction(1, 2))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'receipts': 1926229, 'staff': [['dee', 20, 0], ['eli', 23, 0], ['ben', 15, 23516], ['ana', 9, 0]]}, {'dee': 45999, 'eli': 52899, 'ben': 10984, 'ana': 20700}), ('regression', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('partial-repair probe', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('normal control', {'receipts': 296732, 'staff': [['cy', 31, 25635], ['ben', 23, 0], ['ana', 23, 0]]}, {}), ('normal control', {'receipts': 550244, 'staff': [['cy', 19, 57024]]}, {}), ('normal control', {'receipts': 831709, 'staff': [['eli', 25, 0], ['dee', 27, 33872], ['cy', 8, 38931], ['ben', 2, 0]]}, {}), ('normal control', {'receipts': 1484874, 'staff': [['cy', 38, 0], ['dee', 4, 11025], ['eli', 23, 61900], ['ana', 1, 55590]]}, {})], [('regression', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('regression', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('normal control', {'receipts': 414394, 'staff': [['ben', 30, 72971], ['dee', 11, 50779], ['cy', 12, 57744], ['ana', 33, 0], ['eli', 37, 0]]}, {}), ('normal control', {'receipts': 15877, 'staff': [['dee', 2, 0], ['ben', 29, 36864], ['cy', 36, 367]]}, {}), ('normal control', {'receipts': 1019554, 'staff': [['dee', 11, 0]]}, {'dee': 81564}), ('normal control', {'receipts': 325470, 'staff': [['ana', 24, 0], ['dee', 18, 39572]]}, {})], [('regression', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('regression', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('partial-repair probe', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('normal control', {'receipts': 1844273, 'staff': [['ben', 6, 9908], ['cy', 2, 35253], ['dee', 0, 47647], ['eli', 24, 54448], ['ana', 19, 60962]]}, {}), ('normal control', {'receipts': 985969, 'staff': [['dee', 16, 0]]}, {'dee': 78878}), ('normal control', {'receipts': 2260421, 'staff': [['cy', 25, 0]]}, {'cy': 180834}), ('normal control', {'receipts': 305915, 'staff': [['ben', 17, 0], ['cy', 35, 49832], ['dee', 14, 0]]}, {})], [('regression', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('regression', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('partial-repair probe', {'receipts': 377533, 'staff': [['ben', 14, 0], ['eli', 20, 18063], ['dee', 33, 0]]}, {'ben': 3616, 'dee': 8524}), ('partial-repair probe', {'receipts': 789350, 'staff': [['dee', 24, 0], ['ben', 32, 0], ['cy', 33, 0], ['ana', 25, 0]]}, {'dee': 13294, 'ben': 17726, 'cy': 18280, 'ana': 13848}), ('normal control', {'receipts': 97470, 'staff': [['ana', 8, 0], ['eli', 19, 14113], ['dee', 6, 49117], ['ben', 0, 0], ['cy', 33, 9103]]}, {}), ('normal control', {'receipts': 1562647, 'staff': [['dee', 25, 0], ['ana', 2, 45159], ['ben', 28, 79991], ['eli', 7, 0], ['cy', 29, 0]]}, {}), ('normal control', {'receipts': 498706, 'staff': [['dee', 17, 44639], ['ana', 25, 0], ['cy', 9, 0]]}, {}), ('normal control', {'receipts': 937562, 'staff': [['eli', 3, 44205], ['ana', 5, 63945], ['dee', 2, 72206], ['cy', 27, 6437]]}, {})], [('regression', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('regression', {'receipts': 2458851, 'staff': [['cy', 31, 15683], ['ben', 27, 76376]]}, {'cy': 89454, 'ben': 15195}), ('partial-repair probe', {'receipts': 2589131, 'staff': [['cy', 0, 9383], ['ana', 9, 74166], ['dee', 1, 54844]]}, {'ana': 68737}), ('partial-repair probe', {'receipts': 2640630, 'staff': [['eli', 21, 16955], ['dee', 0, 76011]]}, {'eli': 118284}), ('normal control', {'receipts': 2072929, 'staff': [['dee', 16, 65338]]}, {'dee': 100496}), ('normal control', {'receipts': 2549094, 'staff': [['ben', 25, 0]]}, {'ben': 203928}), ('normal control', {'receipts': 1079780, 'staff': [['eli', 13, 55620], ['dee', 20, 0]]}, {'dee': 30762}), ('normal control', {'receipts': 207036, 'staff': [['ben', 34, 0], ['ana', 23, 0], ['dee', 36, 46201], ['cy', 28, 10127], ['eli', 18, 74356]]}, {})]]
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):
    target = Fraction(x['receipts'] * 8, 100)
    reported = sum(e[2] for e in x['staff'])
    short = target - reported
    if short <= 0:
        return {}
    hours_total = sum(e[1] for e in x['staff'])
    deficits = {}
    for name, hrs, rep in x['staff']:
        share = target / len(x['staff'])
        if rep < share:
            deficits[name] = share - rep
    dsum = sum(deficits.values())
    out = {}
    for name, d in deficits.items():
        out[name] = math.floor(short * d / dsum + Fraction(1, 2))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'receipts': 1926229, 'staff': [['dee', 20, 0], ['eli', 23, 0], ['ben', 15, 23516], ['ana', 9, 0]]}, {'dee': 45999, 'eli': 52899, 'ben': 10984, 'ana': 20700}), ('regression', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('partial-repair probe', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('normal control', {'receipts': 296732, 'staff': [['cy', 31, 25635], ['ben', 23, 0], ['ana', 23, 0]]}, {}), ('normal control', {'receipts': 550244, 'staff': [['cy', 19, 57024]]}, {}), ('normal control', {'receipts': 831709, 'staff': [['eli', 25, 0], ['dee', 27, 33872], ['cy', 8, 38931], ['ben', 2, 0]]}, {}), ('normal control', {'receipts': 1484874, 'staff': [['cy', 38, 0], ['dee', 4, 11025], ['eli', 23, 61900], ['ana', 1, 55590]]}, {})], [('regression', {'receipts': 1565828, 'staff': [['eli', 40, 65745], ['cy', 29, 58626]]}, {'eli': 895}), ('regression', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('partial-repair probe', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('normal control', {'receipts': 414394, 'staff': [['ben', 30, 72971], ['dee', 11, 50779], ['cy', 12, 57744], ['ana', 33, 0], ['eli', 37, 0]]}, {}), ('normal control', {'receipts': 15877, 'staff': [['dee', 2, 0], ['ben', 29, 36864], ['cy', 36, 367]]}, {}), ('normal control', {'receipts': 1019554, 'staff': [['dee', 11, 0]]}, {'dee': 81564}), ('normal control', {'receipts': 325470, 'staff': [['ana', 24, 0], ['dee', 18, 39572]]}, {})], [('regression', {'receipts': 580998, 'staff': [['ana', 8, 0], ['ben', 25, 18228]]}, {'ana': 11268, 'ben': 16984}), ('regression', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('partial-repair probe', {'receipts': 213918, 'staff': [['ben', 40, 0], ['dee', 37, 0]]}, {'ben': 8890, 'dee': 8223}), ('partial-repair probe', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('normal control', {'receipts': 1844273, 'staff': [['ben', 6, 9908], ['cy', 2, 35253], ['dee', 0, 47647], ['eli', 24, 54448], ['ana', 19, 60962]]}, {}), ('normal control', {'receipts': 985969, 'staff': [['dee', 16, 0]]}, {'dee': 78878}), ('normal control', {'receipts': 2260421, 'staff': [['cy', 25, 0]]}, {'cy': 180834}), ('normal control', {'receipts': 305915, 'staff': [['ben', 17, 0], ['cy', 35, 49832], ['dee', 14, 0]]}, {})], [('regression', {'receipts': 2678857, 'staff': [['ana', 8, 35721], ['ben', 20, 0]]}, {'ana': 25510, 'ben': 153078}), ('regression', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('partial-repair probe', {'receipts': 377533, 'staff': [['ben', 14, 0], ['eli', 20, 18063], ['dee', 33, 0]]}, {'ben': 3616, 'dee': 8524}), ('partial-repair probe', {'receipts': 789350, 'staff': [['dee', 24, 0], ['ben', 32, 0], ['cy', 33, 0], ['ana', 25, 0]]}, {'dee': 13294, 'ben': 17726, 'cy': 18280, 'ana': 13848}), ('normal control', {'receipts': 97470, 'staff': [['ana', 8, 0], ['eli', 19, 14113], ['dee', 6, 49117], ['ben', 0, 0], ['cy', 33, 9103]]}, {}), ('normal control', {'receipts': 1562647, 'staff': [['dee', 25, 0], ['ana', 2, 45159], ['ben', 28, 79991], ['eli', 7, 0], ['cy', 29, 0]]}, {}), ('normal control', {'receipts': 498706, 'staff': [['dee', 17, 44639], ['ana', 25, 0], ['cy', 9, 0]]}, {}), ('normal control', {'receipts': 937562, 'staff': [['eli', 3, 44205], ['ana', 5, 63945], ['dee', 2, 72206], ['cy', 27, 6437]]}, {})], [('regression', {'receipts': 2631747, 'staff': [['eli', 6, 73067], ['ana', 26, 49452], ['cy', 10, 52106]]}, {'ana': 35915}), ('regression', {'receipts': 2458851, 'staff': [['cy', 31, 15683], ['ben', 27, 76376]]}, {'cy': 89454, 'ben': 15195}), ('partial-repair probe', {'receipts': 2589131, 'staff': [['cy', 0, 9383], ['ana', 9, 74166], ['dee', 1, 54844]]}, {'ana': 68737}), ('partial-repair probe', {'receipts': 2640630, 'staff': [['eli', 21, 16955], ['dee', 0, 76011]]}, {'eli': 118284}), ('normal control', {'receipts': 2072929, 'staff': [['dee', 16, 65338]]}, {'dee': 100496}), ('normal control', {'receipts': 2549094, 'staff': [['ben', 25, 0]]}, {'ben': 203928}), ('normal control', {'receipts': 1079780, 'staff': [['eli', 13, 55620], ['dee', 20, 0]]}, {'dee': 30762}), ('normal control', {'receipts': 207036, 'staff': [['ben', 34, 0], ['ana', 23, 0], ['dee', 36, 46201], ['cy', 28, 10127], ['eli', 18, 74356]]}, {})]]
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:
The wrong employees are selected for allocation because shares are too small.

Input {receipts, staff: [[name, hours, reported_tips]]} with positive total hours. Target = 8% of receipts. Shortfall = target - total reported; none -> {}. Each employee's share = target*hours/total_hours; employees reporting less than their share get deficit = share - reported. Shortfall is allocated in proportion to deficits, each rounded half-up. Return {name: cents}.

split: open-access


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

N = 1
observations = []
def solve(x):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else fit
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('regression', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('partial-repair probe', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530])], [('regression', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('regression', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('partial-repair probe', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005])], [('regression', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('regression', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124]), ('partial-repair probe', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('partial-repair probe', {'wage': 244355, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 5}, [309755, 244355]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051]), ('normal control', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0])], [('regression', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('regression', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('partial-repair probe', {'wage': 55206, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [120606, 55206]), ('partial-repair probe', {'wage': 486395, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [519095, 486395]), ('normal control', {'wage': 135055, 'freq': 'monthly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [135055, 135055]), ('normal control', {'wage': 146242, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'F', 'years_present': 4}, [237072, 0]), ('normal control', {'wage': 474591, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [520011, 0]), ('normal control', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401])], [('regression', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('regression', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('partial-repair probe', {'wage': 176371, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': None, 'years_present': 5}, [206571, 176371]), ('partial-repair probe', {'wage': 485186, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [500286, 485186]), ('normal control', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('normal control', {'wage': 62573, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'F', 'years_present': 6}, [62573, 62573]), ('normal control', {'wage': 54168, 'freq': 'weekly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [69268, 0]), ('normal control', {'wage': 287286, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 1}, [287286, 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):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else (fit if x['w4_year'] < 2020 else x['wage'])
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('regression', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('partial-repair probe', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530])], [('regression', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('regression', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('partial-repair probe', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005])], [('regression', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('regression', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124]), ('partial-repair probe', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('partial-repair probe', {'wage': 244355, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 5}, [309755, 244355]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051]), ('normal control', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0])], [('regression', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('regression', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('partial-repair probe', {'wage': 55206, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [120606, 55206]), ('partial-repair probe', {'wage': 486395, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [519095, 486395]), ('normal control', {'wage': 135055, 'freq': 'monthly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [135055, 135055]), ('normal control', {'wage': 146242, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'F', 'years_present': 4}, [237072, 0]), ('normal control', {'wage': 474591, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [520011, 0]), ('normal control', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401])], [('regression', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('regression', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('partial-repair probe', {'wage': 176371, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': None, 'years_present': 5}, [206571, 176371]), ('partial-repair probe', {'wage': 485186, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [500286, 485186]), ('normal control', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('normal control', {'wage': 62573, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'F', 'years_present': 6}, [62573, 62573]), ('normal control', {'wage': 54168, 'freq': 'weekly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [69268, 0]), ('normal control', {'wage': 287286, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 1}, [287286, 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:
Nonresident employees have social security and Medicare withheld on money they never earned.

Input {wage, freq, nra, w4_year, visa, years_present}. Nonresident aliens add a per-period amount to wages for income-tax withholding only (2020+ forms: weekly 209.60, biweekly 419.20, semimonthly 454.20, monthly 908.30; older forms: 151.00, 302.00, 327.00, 654.00). FICA wages are the actual wages, or 0 for F and J visa holders present 5 years or fewer. Return [fit_wages, fica_wages].

split: open-access


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

N = 1
observations = []
def solve(x):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] < 5
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('regression', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('partial-repair probe', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154])], [('regression', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('regression', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('partial-repair probe', {'wage': 474591, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [520011, 0]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('normal control', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984])], [('regression', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('regression', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('partial-repair probe', {'wage': 54168, 'freq': 'weekly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [69268, 0]), ('partial-repair probe', {'wage': 419635, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [452335, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051]), ('normal control', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523])], [('regression', {'wage': 464578, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'J', 'years_present': 5}, [464578, 0]), ('regression', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('partial-repair probe', {'wage': 76351, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 1}, [76351, 0]), ('partial-repair probe', {'wage': 367989, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [409909, 0]), ('normal control', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085])], [('regression', {'wage': 64348, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [64348, 0]), ('regression', {'wage': 148120, 'freq': 'monthly', 'nra': False, 'w4_year': 2019, 'visa': 'F', 'years_present': 5}, [148120, 0]), ('partial-repair probe', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('partial-repair probe', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('normal control', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0]), ('normal control', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322])]]
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):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5 and x['visa'] == 'F'
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('regression', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('partial-repair probe', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154])], [('regression', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('regression', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('partial-repair probe', {'wage': 474591, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [520011, 0]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('normal control', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984])], [('regression', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('regression', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('partial-repair probe', {'wage': 54168, 'freq': 'weekly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [69268, 0]), ('partial-repair probe', {'wage': 419635, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2018, 'visa': 'J', 'years_present': 4}, [452335, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051]), ('normal control', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523])], [('regression', {'wage': 464578, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'J', 'years_present': 5}, [464578, 0]), ('regression', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('partial-repair probe', {'wage': 76351, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 1}, [76351, 0]), ('partial-repair probe', {'wage': 367989, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 4}, [409909, 0]), ('normal control', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085])], [('regression', {'wage': 64348, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [64348, 0]), ('regression', {'wage': 148120, 'freq': 'monthly', 'nra': False, 'w4_year': 2019, 'visa': 'F', 'years_present': 5}, [148120, 0]), ('partial-repair probe', {'wage': 217618, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [217618, 0]), ('partial-repair probe', {'wage': 310614, 'freq': 'weekly', 'nra': False, 'w4_year': 2019, 'visa': 'J', 'years_present': 5}, [310614, 0]), ('normal control', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0]), ('normal control', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322])]]
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:
Students in their fifth year lose their FICA exemption early.

Input {wage, freq, nra, w4_year, visa, years_present}. Nonresident aliens add a per-period amount to wages for income-tax withholding only (2020+ forms: weekly 209.60, biweekly 419.20, semimonthly 454.20, monthly 908.30; older forms: 151.00, 302.00, 327.00, 654.00). FICA wages are the actual wages, or 0 for F and J visa holders present 5 years or fewer. Return [fit_wages, fica_wages].

split: open-access


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

N = 1
observations = []
def solve(x):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] > 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523]), ('regression', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('partial-repair probe', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('partial-repair probe', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124])], [('regression', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('regression', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0])], [('regression', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('regression', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('partial-repair probe', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('partial-repair probe', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051])], [('regression', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('regression', {'wage': 73846, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [94806, 73846]), ('partial-repair probe', {'wage': 244355, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 5}, [309755, 244355]), ('partial-repair probe', {'wage': 55206, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [120606, 55206]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0])], [('regression', {'wage': 73846, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [94806, 73846]), ('regression', {'wage': 131463, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [176883, 131463]), ('partial-repair probe', {'wage': 486395, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [519095, 486395]), ('partial-repair probe', {'wage': 485186, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [500286, 485186]), ('normal control', {'wage': 295891, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [386721, 295891]), ('normal control', {'wage': 411503, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 6}, [502333, 411503]), ('normal control', {'wage': 487495, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 6}, [529415, 487495]), ('normal control', {'wage': 135055, 'freq': 'monthly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [135055, 135055])]]
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):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2019 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523]), ('regression', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('partial-repair probe', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('partial-repair probe', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124])], [('regression', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('regression', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('partial-repair probe', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('partial-repair probe', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555]), ('normal control', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('normal control', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0])], [('regression', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('regression', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('partial-repair probe', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672]), ('partial-repair probe', {'wage': 2221, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 5}, [34921, 2221]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0]), ('normal control', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('normal control', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('normal control', {'wage': 328051, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': None, 'years_present': 5}, [328051, 328051])], [('regression', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('regression', {'wage': 73846, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [94806, 73846]), ('partial-repair probe', {'wage': 244355, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 5}, [309755, 244355]), ('partial-repair probe', {'wage': 55206, 'freq': 'monthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [120606, 55206]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568]), ('normal control', {'wage': 434085, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 6}, [434085, 434085]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0])], [('regression', {'wage': 73846, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [94806, 73846]), ('regression', {'wage': 131463, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [176883, 131463]), ('partial-repair probe', {'wage': 486395, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [519095, 486395]), ('partial-repair probe', {'wage': 485186, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [500286, 485186]), ('normal control', {'wage': 295891, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [386721, 295891]), ('normal control', {'wage': 411503, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 6}, [502333, 411503]), ('normal control', {'wage': 487495, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 6}, [529415, 487495]), ('normal control', {'wage': 135055, 'freq': 'monthly', 'nra': False, 'w4_year': 2020, 'visa': None, 'years_present': 8}, [135055, 135055])]]
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 with a 2020 form get the pre-2020 add-on amount.

Input {wage, freq, nra, w4_year, visa, years_present}. Nonresident aliens add a per-period amount to wages for income-tax withholding only (2020+ forms: weekly 209.60, biweekly 419.20, semimonthly 454.20, monthly 908.30; older forms: 151.00, 302.00, 327.00, 654.00). FICA wages are the actual wages, or 0 for F and J visa holders present 5 years or fewer. Return [fit_wages, fica_wages].

split: open-access


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

N = 1
observations = []
def solve(x):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + add
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('regression', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('partial-repair probe', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124])], [('regression', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('regression', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('partial-repair probe', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('normal control', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0])], [('regression', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('regression', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('partial-repair probe', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('partial-repair probe', {'wage': 62573, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'F', 'years_present': 6}, [62573, 62573]), ('normal control', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523]), ('normal control', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568])], [('regression', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('regression', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('partial-repair probe', {'wage': 287286, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 1}, [287286, 0]), ('partial-repair probe', {'wage': 102873, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'H', 'years_present': 8}, [102873, 102873]), ('normal control', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0]), ('normal control', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555])], [('regression', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('regression', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 325245, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [325245, 325245]), ('partial-repair probe', {'wage': 458461, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [458461, 458461]), ('normal control', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('normal control', {'wage': 295891, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [386721, 295891]), ('normal control', {'wage': 411503, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 6}, [502333, 411503]), ('normal control', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672])]]
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):
    new = {'weekly': 20960, 'biweekly': 41920, 'semimonthly': 45420, 'monthly': 90830}
    old = {'weekly': 15100, 'biweekly': 30200, 'semimonthly': 32700, 'monthly': 65400}
    add = new[x['freq']] if x['w4_year'] >= 2020 else old[x['freq']]
    fit = x['wage'] + (add if x['nra'] or x['visa'] else 0)
    exempt = x['visa'] in ('F', 'J') and x['years_present'] <= 5
    fica = 0 if exempt else x['wage']
    return [fit, fica]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 245306, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 6}, [245306, 245306]), ('regression', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('partial-repair probe', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('normal control', {'wage': 392169, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'F', 'years_present': 1}, [424869, 0]), ('normal control', {'wage': 252469, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': None, 'years_present': 8}, [273429, 252469]), ('normal control', {'wage': 286154, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 1}, [376984, 286154]), ('normal control', {'wage': 2124, 'freq': 'monthly', 'nra': True, 'w4_year': 2024, 'visa': 'H', 'years_present': 6}, [92954, 2124])], [('regression', {'wage': 314655, 'freq': 'monthly', 'nra': False, 'w4_year': 2024, 'visa': 'J', 'years_present': 1}, [314655, 0]), ('regression', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('partial-repair probe', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('normal control', {'wage': 210010, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': None, 'years_present': 1}, [240210, 210010]), ('normal control', {'wage': 436984, 'freq': 'biweekly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [478904, 436984]), ('normal control', {'wage': 40274, 'freq': 'monthly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 5}, [105674, 0]), ('normal control', {'wage': 179956, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 5}, [270786, 0])], [('regression', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('regression', {'wage': 350530, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': None, 'years_present': 1}, [350530, 350530]), ('partial-repair probe', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('partial-repair probe', {'wage': 62573, 'freq': 'monthly', 'nra': False, 'w4_year': 2018, 'visa': 'F', 'years_present': 6}, [62573, 62573]), ('normal control', {'wage': 162523, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [207943, 162523]), ('normal control', {'wage': 181833, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 1}, [227253, 181833]), ('normal control', {'wage': 141591, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'H', 'years_present': 4}, [171791, 141591]), ('normal control', {'wage': 416568, 'freq': 'weekly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 8}, [437528, 416568])], [('regression', {'wage': 345401, 'freq': 'weekly', 'nra': False, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [345401, 345401]), ('regression', {'wage': 279817, 'freq': 'biweekly', 'nra': False, 'w4_year': 2019, 'visa': None, 'years_present': 8}, [279817, 279817]), ('partial-repair probe', {'wage': 287286, 'freq': 'weekly', 'nra': False, 'w4_year': 2020, 'visa': 'F', 'years_present': 1}, [287286, 0]), ('partial-repair probe', {'wage': 102873, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'H', 'years_present': 8}, [102873, 102873]), ('normal control', {'wage': 437685, 'freq': 'weekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 4}, [452785, 0]), ('normal control', {'wage': 114598, 'freq': 'weekly', 'nra': True, 'w4_year': 2020, 'visa': 'H', 'years_present': 5}, [135558, 114598]), ('normal control', {'wage': 178971, 'freq': 'biweekly', 'nra': True, 'w4_year': 2018, 'visa': 'F', 'years_present': 1}, [209171, 0]), ('normal control', {'wage': 21555, 'freq': 'biweekly', 'nra': True, 'w4_year': 2019, 'visa': 'J', 'years_present': 6}, [51755, 21555])], [('regression', {'wage': 356715, 'freq': 'weekly', 'nra': False, 'w4_year': 2024, 'visa': 'F', 'years_present': 6}, [356715, 356715]), ('regression', {'wage': 352005, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [352005, 352005]), ('partial-repair probe', {'wage': 325245, 'freq': 'weekly', 'nra': False, 'w4_year': 2018, 'visa': 'H', 'years_present': 5}, [325245, 325245]), ('partial-repair probe', {'wage': 458461, 'freq': 'semimonthly', 'nra': False, 'w4_year': 2019, 'visa': 'H', 'years_present': 1}, [458461, 458461]), ('normal control', {'wage': 498322, 'freq': 'biweekly', 'nra': True, 'w4_year': 2020, 'visa': None, 'years_present': 5}, [540242, 498322]), ('normal control', {'wage': 295891, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'J', 'years_present': 8}, [386721, 295891]), ('normal control', {'wage': 411503, 'freq': 'monthly', 'nra': True, 'w4_year': 2021, 'visa': 'H', 'years_present': 6}, [502333, 411503]), ('normal control', {'wage': 89672, 'freq': 'semimonthly', 'nra': True, 'w4_year': 2019, 'visa': 'H', 'years_present': 4}, [122372, 89672])]]
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:
Citizens and resident aliens are over-withheld by the nonresident add-on.

Input {wage, freq, nra, w4_year, visa, years_present}. Nonresident aliens add a per-period amount to wages for income-tax withholding only (2020+ forms: weekly 209.60, biweekly 419.20, semimonthly 454.20, monthly 908.30; older forms: 151.00, 302.00, 327.00, 654.00). FICA wages are the actual wages, or 0 for F and J visa holders present 5 years or fewer. Return [fit_wages, fica_wages].

split: open-access


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

N = 1
observations = []
def solve(x):
    fit = x['fit']
    if x['whole_dollar']:
        fit = (fit + 50) // 100 * 100
    fit += x['extra']
    return [fit, fit + x['fica']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'fit': 9156, 'extra': 2251, 'whole_dollar': True, 'fica': 25269}, [11400, 36669]), ('regression', {'fit': 8185, 'extra': 1110, 'whole_dollar': True, 'fica': 28304}, [9300, 37604]), ('partial-repair probe', {'fit': 90104, 'extra': 2500, 'whole_dollar': True, 'fica': 8194}, [92600, 100794]), ('partial-repair probe', {'fit': 132638, 'extra': 2500, 'whole_dollar': True, 'fica': 46802}, [135100, 181902]), ('normal control', {'fit': 69591, 'extra': 0, 'whole_dollar': False, 'fica': 14775}, [69591, 84366]), ('normal control', {'fit': 154831, 'extra': 3634, 'whole_dollar': False, 'fica': 44615}, [158465, 203080]), ('normal control', {'fit': 77351, 'extra': 0, 'whole_dollar': False, 'fica': 12610}, [77351, 89961]), ('normal control', {'fit': 88332, 'extra': 0, 'whole_dollar': True, 'fica': 8166}, [88300, 96466])], [('regression', {'fit': 8185, 'extra': 1110, 'whole_dollar': True, 'fica': 28304}, [9300, 37604]), ('regression', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('partial-repair probe', {'fit': 132638, 'extra': 2500, 'whole_dollar': True, 'fica': 46802}, [135100, 181902]), ('partial-repair probe', {'fit': 39742, 'extra': 2500, 'whole_dollar': True, 'fica': 2719}, [42200, 44919]), ('normal control', {'fit': 87258, 'extra': 0, 'whole_dollar': False, 'fica': 46798}, [87258, 134056]), ('normal control', {'fit': 118865, 'extra': 0, 'whole_dollar': False, 'fica': 28601}, [118865, 147466]), ('normal control', {'fit': 16677, 'extra': 0, 'whole_dollar': False, 'fica': 47905}, [16677, 64582]), ('normal control', {'fit': 72176, 'extra': 8810, 'whole_dollar': False, 'fica': 17211}, [80986, 98197])], [('regression', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('regression', {'fit': 71043, 'extra': 1719, 'whole_dollar': True, 'fica': 19074}, [72800, 91874]), ('partial-repair probe', {'fit': 39742, 'extra': 2500, 'whole_dollar': True, 'fica': 2719}, [42200, 44919]), ('partial-repair probe', {'fit': 46034, 'extra': 2500, 'whole_dollar': True, 'fica': 26997}, [48500, 75497]), ('normal control', {'fit': 53286, 'extra': 0, 'whole_dollar': False, 'fica': 40551}, [53286, 93837]), ('normal control', {'fit': 76409, 'extra': 0, 'whole_dollar': False, 'fica': 47429}, [76409, 123838]), ('normal control', {'fit': 158877, 'extra': 0, 'whole_dollar': False, 'fica': 16786}, [158877, 175663]), ('normal control', {'fit': 83141, 'extra': 0, 'whole_dollar': True, 'fica': 11931}, [83100, 95031])], [('regression', {'fit': 71043, 'extra': 1719, 'whole_dollar': True, 'fica': 19074}, [72800, 91874]), ('regression', {'fit': 187550, 'extra': 8476, 'whole_dollar': True, 'fica': 45605}, [196000, 241605]), ('partial-repair probe', {'fit': 160110, 'extra': 2500, 'whole_dollar': True, 'fica': 47818}, [162600, 210418]), ('partial-repair probe', {'fit': 117866, 'extra': 2500, 'whole_dollar': True, 'fica': 44243}, [120400, 164643]), ('normal control', {'fit': 77435, 'extra': 0, 'whole_dollar': True, 'fica': 39916}, [77400, 117316]), ('normal control', {'fit': 16947, 'extra': 0, 'whole_dollar': True, 'fica': 9583}, [16900, 26483]), ('normal control', {'fit': 45654, 'extra': 0, 'whole_dollar': True, 'fica': 24238}, [45700, 69938]), ('normal control', {'fit': 69043, 'extra': 0, 'whole_dollar': True, 'fica': 38706}, [69000, 107706])], [('regression', {'fit': 187550, 'extra': 8476, 'whole_dollar': True, 'fica': 45605}, [196000, 241605]), ('regression', {'fit': 144230, 'extra': 9285, 'whole_dollar': True, 'fica': 21550}, [153500, 175050]), ('partial-repair probe', {'fit': 151775, 'extra': 2500, 'whole_dollar': True, 'fica': 42505}, [154300, 196805]), ('partial-repair probe', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('normal control', {'fit': 12373, 'extra': 1118, 'whole_dollar': False, 'fica': 16260}, [13491, 29751]), ('normal control', {'fit': 31187, 'extra': 0, 'whole_dollar': False, 'fica': 13316}, [31187, 44503]), ('normal control', {'fit': 15705, 'extra': 0, 'whole_dollar': True, 'fica': 2352}, [15700, 18052]), ('normal control', {'fit': 91543, 'extra': 0, 'whole_dollar': True, 'fica': 21661}, [91500, 113161])]]
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):
    fit = x['fit'] + x['extra']
    if x['whole_dollar'] and x['extra'] == 0:
        fit = (fit + 50) // 100 * 100
    return [fit, fit + x['fica']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'fit': 9156, 'extra': 2251, 'whole_dollar': True, 'fica': 25269}, [11400, 36669]), ('regression', {'fit': 8185, 'extra': 1110, 'whole_dollar': True, 'fica': 28304}, [9300, 37604]), ('partial-repair probe', {'fit': 90104, 'extra': 2500, 'whole_dollar': True, 'fica': 8194}, [92600, 100794]), ('partial-repair probe', {'fit': 132638, 'extra': 2500, 'whole_dollar': True, 'fica': 46802}, [135100, 181902]), ('normal control', {'fit': 69591, 'extra': 0, 'whole_dollar': False, 'fica': 14775}, [69591, 84366]), ('normal control', {'fit': 154831, 'extra': 3634, 'whole_dollar': False, 'fica': 44615}, [158465, 203080]), ('normal control', {'fit': 77351, 'extra': 0, 'whole_dollar': False, 'fica': 12610}, [77351, 89961]), ('normal control', {'fit': 88332, 'extra': 0, 'whole_dollar': True, 'fica': 8166}, [88300, 96466])], [('regression', {'fit': 8185, 'extra': 1110, 'whole_dollar': True, 'fica': 28304}, [9300, 37604]), ('regression', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('partial-repair probe', {'fit': 132638, 'extra': 2500, 'whole_dollar': True, 'fica': 46802}, [135100, 181902]), ('partial-repair probe', {'fit': 39742, 'extra': 2500, 'whole_dollar': True, 'fica': 2719}, [42200, 44919]), ('normal control', {'fit': 87258, 'extra': 0, 'whole_dollar': False, 'fica': 46798}, [87258, 134056]), ('normal control', {'fit': 118865, 'extra': 0, 'whole_dollar': False, 'fica': 28601}, [118865, 147466]), ('normal control', {'fit': 16677, 'extra': 0, 'whole_dollar': False, 'fica': 47905}, [16677, 64582]), ('normal control', {'fit': 72176, 'extra': 8810, 'whole_dollar': False, 'fica': 17211}, [80986, 98197])], [('regression', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('regression', {'fit': 71043, 'extra': 1719, 'whole_dollar': True, 'fica': 19074}, [72800, 91874]), ('partial-repair probe', {'fit': 39742, 'extra': 2500, 'whole_dollar': True, 'fica': 2719}, [42200, 44919]), ('partial-repair probe', {'fit': 46034, 'extra': 2500, 'whole_dollar': True, 'fica': 26997}, [48500, 75497]), ('normal control', {'fit': 53286, 'extra': 0, 'whole_dollar': False, 'fica': 40551}, [53286, 93837]), ('normal control', {'fit': 76409, 'extra': 0, 'whole_dollar': False, 'fica': 47429}, [76409, 123838]), ('normal control', {'fit': 158877, 'extra': 0, 'whole_dollar': False, 'fica': 16786}, [158877, 175663]), ('normal control', {'fit': 83141, 'extra': 0, 'whole_dollar': True, 'fica': 11931}, [83100, 95031])], [('regression', {'fit': 71043, 'extra': 1719, 'whole_dollar': True, 'fica': 19074}, [72800, 91874]), ('regression', {'fit': 187550, 'extra': 8476, 'whole_dollar': True, 'fica': 45605}, [196000, 241605]), ('partial-repair probe', {'fit': 160110, 'extra': 2500, 'whole_dollar': True, 'fica': 47818}, [162600, 210418]), ('partial-repair probe', {'fit': 117866, 'extra': 2500, 'whole_dollar': True, 'fica': 44243}, [120400, 164643]), ('normal control', {'fit': 77435, 'extra': 0, 'whole_dollar': True, 'fica': 39916}, [77400, 117316]), ('normal control', {'fit': 16947, 'extra': 0, 'whole_dollar': True, 'fica': 9583}, [16900, 26483]), ('normal control', {'fit': 45654, 'extra': 0, 'whole_dollar': True, 'fica': 24238}, [45700, 69938]), ('normal control', {'fit': 69043, 'extra': 0, 'whole_dollar': True, 'fica': 38706}, [69000, 107706])], [('regression', {'fit': 187550, 'extra': 8476, 'whole_dollar': True, 'fica': 45605}, [196000, 241605]), ('regression', {'fit': 144230, 'extra': 9285, 'whole_dollar': True, 'fica': 21550}, [153500, 175050]), ('partial-repair probe', {'fit': 151775, 'extra': 2500, 'whole_dollar': True, 'fica': 42505}, [154300, 196805]), ('partial-repair probe', {'fit': 15510, 'extra': 5992, 'whole_dollar': True, 'fica': 2377}, [21500, 23877]), ('normal control', {'fit': 12373, 'extra': 1118, 'whole_dollar': False, 'fica': 16260}, [13491, 29751]), ('normal control', {'fit': 31187, 'extra': 0, 'whole_dollar': False, 'fica': 13316}, [31187, 44503]), ('normal control', {'fit': 15705, 'extra': 0, 'whole_dollar': True, 'fica': 2352}, [15700, 18052]), ('normal control', {'fit': 91543, 'extra': 0, 'whole_dollar': True, 'fica': 21661}, [91500, 113161])]]
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 with additional withholding end up with odd-cent income tax despite electing whole dollars.

Input {fit, extra, whole_dollar, fica}. Income tax withholding = fit + extra; when whole_dollar is elected, that sum is rounded to the nearest dollar (half-up). FICA is never rounded. Return [income_tax, income_tax + fica].

split: open-access


prompt:
Total tax withheld does not equal income tax plus FICA.

Input {fit, extra, whole_dollar, fica}. Income tax withholding = fit + extra; when whole_dollar is elected, that sum is rounded to the nearest dollar (half-up). FICA is never rounded. Return [income_tax, income_tax + fica].

split: open-access


prompt:
Customers who upgrade are charged and credited for one day fewer than remain in the period.

Input {old, new prices per period, start, end (exclusive), change} dates with start <= change < end. Remaining days = end - change; period days = end - start. Credit = old*remaining/period and charge = new*remaining/period, each rounded half-up. Net = charge - credit; a positive net is due now, a negative net becomes a credit balance. Return [credit, charge, amount_due, credit_balance].

split: open-access


prompt:
Proration amounts are skewed in 31-day months and February, and exceed the plan price on annual plans.

Input {old, new prices per period, start, end (exclusive), change} dates with start <= change < end. Remaining days = end - change; period days = end - start. Credit = old*remaining/period and charge = new*remaining/period, each rounded half-up. Net = charge - credit; a positive net is due now, a negative net becomes a credit balance. Return [credit, charge, amount_due, credit_balance].

split: open-access


prompt:
The amount due differs by a cent from the printed charge minus the printed credit.

Input {old, new prices per period, start, end (exclusive), change} dates with start <= change < end. Remaining days = end - change; period days = end - start. Credit = old*remaining/period and charge = new*remaining/period, each rounded half-up. Net = charge - credit; a positive net is due now, a negative net becomes a credit balance. Return [credit, charge, amount_due, credit_balance].

split: open-access


prompt:
Downgrades produce a negative amount due on the invoice.

Input {old, new prices per period, start, end (exclusive), change} dates with start <= change < end. Remaining days = end - change; period days = end - start. Credit = old*remaining/period and charge = new*remaining/period, each rounded half-up. Net = charge - credit; a positive net is due now, a negative net becomes a credit balance. Return [credit, charge, amount_due, credit_balance].

split: open-access