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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:1]:
        alloc[s] += left
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('regression', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('partial-repair probe', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3}), ('partial-repair probe', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22})], [('regression', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('regression', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('partial-repair probe', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('partial-repair probe', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711})], [('regression', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('regression', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('partial-repair probe', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('partial-repair probe', {'wage': 802876, 'days': {'NJ': 10, 'MA': 0, 'NY': 0, 'PA': 1}, 'resident': 'CT'}, {'NJ': 729887, 'PA': 72989}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356})], [('regression', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('regression', {'wage': 15, 'days': {'NY': 2, 'MA': 0, 'PA': 2, 'NJ': 13}, 'resident': 'CT'}, {'NJ': 11, 'NY': 2, 'PA': 2}), ('partial-repair probe', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('partial-repair probe', {'wage': 254323, 'days': {'NY': 1, 'PA': 8, 'NJ': 15, 'MA': 0}, 'resident': 'NY'}, {'NJ': 158952, 'PA': 84774, 'NY': 10597}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 10, 'days': {'CT': 19, 'MA': 0}, 'resident': 'NJ'}, {'CT': 10})], [('regression', {'wage': 15, 'days': {'NY': 2, 'MA': 0, 'PA': 2, 'NJ': 13}, 'resident': 'CT'}, {'NJ': 11, 'NY': 2, 'PA': 2}), ('regression', {'wage': 4, 'days': {'NJ': 3, 'CT': 1, 'MA': 3}, 'resident': 'CT'}, {'MA': 2, 'NJ': 2}), ('partial-repair probe', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('partial-repair probe', {'wage': 22, 'days': {'PA': 0, 'CT': 1, 'MA': 2, 'NJ': 1}, 'resident': 'NY'}, {'MA': 11, 'CT': 6, 'NJ': 5}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 200160, 'days': {'CT': 0, 'NJ': 3, 'NY': 17, 'PA': 0}, 'resident': 'CT'}, {'NY': 170136, 'NJ': 30024}), ('normal control', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27}), ('normal control', {'wage': 29, 'days': {'PA': 2}, 'resident': 'NJ'}, {'PA': 29}), ('normal control', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522})]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

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

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

split: open-access


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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: -days[s])
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('regression', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('partial-repair probe', {'wage': 406634, 'days': {'CT': 1, 'MA': 0, 'NJ': 3}, 'resident': 'CT'}, {'NJ': 304976, 'CT': 101658}), ('partial-repair probe', {'wage': 443052, 'days': {'NJ': 16, 'PA': 1, 'CT': 3}, 'resident': 'CT'}, {'NJ': 354442, 'CT': 66458, 'PA': 22152}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3})], [('regression', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('regression', {'wage': 371633, 'days': {'PA': 2, 'NJ': 2}, 'resident': 'NJ'}, {'NJ': 185817, 'PA': 185816}), ('partial-repair probe', {'wage': 13027, 'days': {'NY': 13, 'NJ': 1}, 'resident': 'NY'}, {'NY': 12097, 'NJ': 930}), ('partial-repair probe', {'wage': 595862, 'days': {'MA': 1, 'PA': 3}, 'resident': 'NY'}, {'PA': 446897, 'MA': 148965}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545})], [('regression', {'wage': 371633, 'days': {'PA': 2, 'NJ': 2}, 'resident': 'NJ'}, {'NJ': 185817, 'PA': 185816}), ('regression', {'wage': 546744, 'days': {'CT': 2, 'PA': 2, 'MA': 2, 'NJ': 1}, 'resident': 'CT'}, {'CT': 156213, 'MA': 156213, 'PA': 156212, 'NJ': 78106}), ('partial-repair probe', {'wage': 292812, 'days': {'NY': 15, 'MA': 12, 'CT': 1}, 'resident': 'NJ'}, {'NY': 156864, 'MA': 125491, 'CT': 10457}), ('partial-repair probe', {'wage': 15, 'days': {'NJ': 1, 'MA': 21, 'PA': 3}, 'resident': 'NJ'}, {'MA': 13, 'PA': 2}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('normal control', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573})], [('regression', {'wage': 546744, 'days': {'CT': 2, 'PA': 2, 'MA': 2, 'NJ': 1}, 'resident': 'CT'}, {'CT': 156213, 'MA': 156213, 'PA': 156212, 'NJ': 78106}), ('regression', {'wage': 664779, 'days': {'PA': 2, 'NY': 0, 'NJ': 2}, 'resident': 'CT'}, {'NJ': 332390, 'PA': 332389}), ('partial-repair probe', {'wage': 18, 'days': {'NJ': 0, 'CT': 2, 'NY': 6}, 'resident': 'CT'}, {'NY': 14, 'CT': 4}), ('partial-repair probe', {'wage': 524878, 'days': {'PA': 1, 'MA': 0, 'CT': 3}, 'resident': 'CT'}, {'CT': 393659, 'PA': 131219}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('normal control', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2})], [('regression', {'wage': 664779, 'days': {'PA': 2, 'NY': 0, 'NJ': 2}, 'resident': 'CT'}, {'NJ': 332390, 'PA': 332389}), ('regression', {'wage': 517125, 'days': {'MA': 4, 'NJ': 0, 'CT': 4}, 'resident': 'NY'}, {'CT': 258563, 'MA': 258562}), ('partial-repair probe', {'wage': 377067, 'days': {'MA': 2, 'NY': 0, 'CT': 0, 'PA': 10}, 'resident': 'CT'}, {'PA': 314223, 'MA': 62844}), ('partial-repair probe', {'wage': 30, 'days': {'MA': 3, 'NJ': 0, 'NY': 4, 'PA': 15}, 'resident': 'CT'}, {'PA': 21, 'NY': 5, 'MA': 4}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14}), ('normal control', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('normal control', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4})]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: (days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() if v}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('regression', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('partial-repair probe', {'wage': 406634, 'days': {'CT': 1, 'MA': 0, 'NJ': 3}, 'resident': 'CT'}, {'NJ': 304976, 'CT': 101658}), ('partial-repair probe', {'wage': 443052, 'days': {'NJ': 16, 'PA': 1, 'CT': 3}, 'resident': 'CT'}, {'NJ': 354442, 'CT': 66458, 'PA': 22152}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('normal control', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3})], [('regression', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('regression', {'wage': 371633, 'days': {'PA': 2, 'NJ': 2}, 'resident': 'NJ'}, {'NJ': 185817, 'PA': 185816}), ('partial-repair probe', {'wage': 13027, 'days': {'NY': 13, 'NJ': 1}, 'resident': 'NY'}, {'NY': 12097, 'NJ': 930}), ('partial-repair probe', {'wage': 595862, 'days': {'MA': 1, 'PA': 3}, 'resident': 'NY'}, {'PA': 446897, 'MA': 148965}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545})], [('regression', {'wage': 371633, 'days': {'PA': 2, 'NJ': 2}, 'resident': 'NJ'}, {'NJ': 185817, 'PA': 185816}), ('regression', {'wage': 546744, 'days': {'CT': 2, 'PA': 2, 'MA': 2, 'NJ': 1}, 'resident': 'CT'}, {'CT': 156213, 'MA': 156213, 'PA': 156212, 'NJ': 78106}), ('partial-repair probe', {'wage': 292812, 'days': {'NY': 15, 'MA': 12, 'CT': 1}, 'resident': 'NJ'}, {'NY': 156864, 'MA': 125491, 'CT': 10457}), ('partial-repair probe', {'wage': 15, 'days': {'NJ': 1, 'MA': 21, 'PA': 3}, 'resident': 'NJ'}, {'MA': 13, 'PA': 2}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711}), ('normal control', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573})], [('regression', {'wage': 546744, 'days': {'CT': 2, 'PA': 2, 'MA': 2, 'NJ': 1}, 'resident': 'CT'}, {'CT': 156213, 'MA': 156213, 'PA': 156212, 'NJ': 78106}), ('regression', {'wage': 664779, 'days': {'PA': 2, 'NY': 0, 'NJ': 2}, 'resident': 'CT'}, {'NJ': 332390, 'PA': 332389}), ('partial-repair probe', {'wage': 18, 'days': {'NJ': 0, 'CT': 2, 'NY': 6}, 'resident': 'CT'}, {'NY': 14, 'CT': 4}), ('partial-repair probe', {'wage': 524878, 'days': {'PA': 1, 'MA': 0, 'CT': 3}, 'resident': 'CT'}, {'CT': 393659, 'PA': 131219}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('normal control', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('normal control', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2})], [('regression', {'wage': 664779, 'days': {'PA': 2, 'NY': 0, 'NJ': 2}, 'resident': 'CT'}, {'NJ': 332390, 'PA': 332389}), ('regression', {'wage': 517125, 'days': {'MA': 4, 'NJ': 0, 'CT': 4}, 'resident': 'NY'}, {'CT': 258563, 'MA': 258562}), ('partial-repair probe', {'wage': 377067, 'days': {'MA': 2, 'NY': 0, 'CT': 0, 'PA': 10}, 'resident': 'CT'}, {'PA': 314223, 'MA': 62844}), ('partial-repair probe', {'wage': 30, 'days': {'MA': 3, 'NJ': 0, 'NY': 4, 'PA': 15}, 'resident': 'CT'}, {'PA': 21, 'NY': 5, 'MA': 4}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14}), ('normal control', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('normal control', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4})]]
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:
Which state receives a tied leftover cent depends on dictionary insertion order.

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

split: open-access


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

N = 1
observations = []
def solve(x):
    days = x['days']
    total = sum(days.values())
    if total == 0:
        return {x['resident']: x['wage']}
    order = sorted(days, key=lambda s: (-days[s], s))
    alloc = {s: x['wage'] * days[s] // total for s in order}
    rema = sorted(order, key=lambda s: (-(x['wage'] * days[s] % total), order.index(s)))
    left = x['wage'] - sum(alloc.values())
    for s in rema[:left]:
        alloc[s] += 1
    return {s: v for s, v in alloc.items() }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'wage': 2, 'days': {'NJ': 2, 'PA': 2, 'NY': 0, 'MA': 1}, 'resident': 'CT'}, {'NJ': 1, 'PA': 1}), ('regression', {'wage': 61318, 'days': {'CT': 0, 'MA': 0, 'PA': 12, 'NJ': 19}, 'resident': 'NY'}, {'NJ': 37582, 'PA': 23736}), ('partial-repair probe', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('partial-repair probe', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 410311, 'days': {'PA': 10}, 'resident': 'CT'}, {'PA': 410311}), ('normal control', {'wage': 9, 'days': {'PA': 1, 'CT': 8}, 'resident': 'NY'}, {'CT': 8, 'PA': 1}), ('normal control', {'wage': 17, 'days': {'NJ': 1, 'PA': 3, 'NY': 3}, 'resident': 'NY'}, {'NY': 7, 'PA': 7, 'NJ': 3}), ('normal control', {'wage': 22, 'days': {'CT': 0}, 'resident': 'NY'}, {'NY': 22})], [('regression', {'wage': 5, 'days': {'MA': 17, 'NY': 2, 'PA': 9}, 'resident': 'NJ'}, {'MA': 3, 'PA': 2}), ('regression', {'wage': 273177, 'days': {'PA': 0, 'NY': 1, 'NJ': 3}, 'resident': 'NJ'}, {'NJ': 204883, 'NY': 68294}), ('partial-repair probe', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('partial-repair probe', {'wage': 4, 'days': {'NJ': 3, 'CT': 1, 'MA': 3}, 'resident': 'CT'}, {'MA': 2, 'NJ': 2}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 231015, 'days': {'PA': 0}, 'resident': 'CT'}, {'CT': 231015}), ('normal control', {'wage': 874754, 'days': {'PA': 19}, 'resident': 'CT'}, {'PA': 874754}), ('normal control', {'wage': 315271, 'days': {'PA': 2, 'NY': 3, 'CT': 1}, 'resident': 'NJ'}, {'NY': 157636, 'PA': 105090, 'CT': 52545}), ('normal control', {'wage': 761711, 'days': {'MA': 0}, 'resident': 'NJ'}, {'NJ': 761711})], [('regression', {'wage': 3, 'days': {'NJ': 2, 'MA': 2, 'PA': 13, 'CT': 2}, 'resident': 'NJ'}, {'PA': 2, 'CT': 1}), ('regression', {'wage': 424602, 'days': {'PA': 2, 'CT': 0, 'NJ': 7, 'NY': 0}, 'resident': 'CT'}, {'NJ': 330246, 'PA': 94356}), ('partial-repair probe', {'wage': 1, 'days': {'NJ': 1, 'MA': 11}, 'resident': 'CT'}, {'MA': 1}), ('partial-repair probe', {'wage': 4, 'days': {'NY': 21, 'PA': 0, 'CT': 0, 'MA': 2}, 'resident': 'CT'}, {'NY': 4}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 1, 'days': {'NJ': 15}, 'resident': 'NY'}, {'NJ': 1}), ('normal control', {'wage': 399573, 'days': {'CT': 0}, 'resident': 'CT'}, {'CT': 399573}), ('normal control', {'wage': 172162, 'days': {'MA': 6, 'CT': 3, 'PA': 11}, 'resident': 'NJ'}, {'PA': 94689, 'MA': 51649, 'CT': 25824}), ('normal control', {'wage': 2, 'days': {'NJ': 0}, 'resident': 'NJ'}, {'NJ': 2})], [('regression', {'wage': 4, 'days': {'NJ': 3, 'CT': 1, 'MA': 3}, 'resident': 'CT'}, {'MA': 2, 'NJ': 2}), ('regression', {'wage': 179374, 'days': {'PA': 20, 'NJ': 2, 'MA': 0}, 'resident': 'NY'}, {'PA': 163067, 'NJ': 16307}), ('partial-repair probe', {'wage': 0, 'days': {'MA': 15, 'NY': 9, 'PA': 0, 'CT': 3}, 'resident': 'CT'}, {}), ('partial-repair probe', {'wage': 1, 'days': {'CT': 20, 'NJ': 3, 'PA': 3}, 'resident': 'NY'}, {'CT': 1}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 525270, 'days': {'MA': 2, 'PA': 11, 'NJ': 22}, 'resident': 'NJ'}, {'NJ': 330170, 'PA': 165085, 'MA': 30015}), ('normal control', {'wage': 16, 'days': {'CT': 3, 'PA': 1}, 'resident': 'CT'}, {'CT': 12, 'PA': 4}), ('normal control', {'wage': 27, 'days': {'NY': 0}, 'resident': 'NY'}, {'NY': 27}), ('normal control', {'wage': 29, 'days': {'PA': 2}, 'resident': 'NJ'}, {'PA': 29})], [('regression', {'wage': 1, 'days': {'NJ': 1, 'MA': 11}, 'resident': 'CT'}, {'MA': 1}), ('regression', {'wage': 14, 'days': {'PA': 0, 'MA': 2}, 'resident': 'CT'}, {'MA': 14}), ('partial-repair probe', {'wage': 0, 'days': {'NJ': 0, 'CT': 8}, 'resident': 'NY'}, {}), ('partial-repair probe', {'wage': 1, 'days': {'CT': 15, 'PA': 21, 'NY': 0, 'MA': 2}, 'resident': 'CT'}, {'PA': 1}), ('boundary control', {'wage': 100, 'days': {'NY': 1, 'NJ': 1, 'CT': 1}, 'resident': 'NJ'}, {'CT': 34, 'NJ': 33, 'NY': 33}), ('boundary control', {'wage': 5000, 'days': {'NY': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 5000}), ('normal control', {'wage': 646558, 'days': {'NY': 15, 'CT': 3, 'MA': 3, 'NJ': 2}, 'resident': 'NJ'}, {'NY': 421668, 'CT': 84334, 'MA': 84334, 'NJ': 56222}), ('normal control', {'wage': 455522, 'days': {'MA': 0, 'CT': 0}, 'resident': 'NY'}, {'NY': 455522}), ('normal control', {'wage': 794041, 'days': {'NY': 20, 'PA': 1}, 'resident': 'NY'}, {'NY': 756230, 'PA': 37811}), ('normal control', {'wage': 402912, 'days': {'CT': 0, 'NJ': 0}, 'resident': 'NJ'}, {'NJ': 402912})]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

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

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    anchor = datetime.date(*x['anchor'])
    lo = datetime.date(x['year'], 1, 1)
    hi = datetime.date(x['year'], 12, 31)
    off = (lo - anchor).days
    k = off // x['step']
    first = anchor + datetime.timedelta(days=k * x['step'])
    count = (hi - first).days // x['step'] + 1
    periods = 26 if x['step'] == 14 else 52
    return [count, first.isoformat(), count > periods]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe (boundary)', {'anchor': [2026, 1, 1], 'step': 14, 'year': 2026}, [27, '2026-01-01', True]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('partial-repair probe', {'anchor': [2024, 10, 14], 'step': 7, 'year': 2024}, [53, '2024-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('partial-repair probe', {'anchor': [2019, 8, 28], 'step': 14, 'year': 2020}, [27, '2020-01-01', True]), ('partial-repair probe', {'anchor': [2025, 3, 13], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False])], [('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('regression', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('partial-repair probe', {'anchor': [2024, 10, 27], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2018, 3, 28], 'step': 14, 'year': 2020}, [27, '2020-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False])], [('regression', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('regression', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('partial-repair probe', {'anchor': [2021, 5, 2], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2025, 9, 4], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False]), ('additional oracle', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True])]]
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
import datetime
N = 1
observations = []
def solve(x):
    anchor = datetime.date(*x['anchor'])
    lo = datetime.date(x['year'], 1, 1)
    hi = datetime.date(x['year'], 12, 31)
    off = (lo - anchor).days
    k = off // x['step'] + 1
    first = anchor + datetime.timedelta(days=k * x['step'])
    count = (hi - first).days // x['step'] + 1
    periods = 26 if x['step'] == 14 else 52
    return [count, first.isoformat(), count > periods]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe (boundary)', {'anchor': [2026, 1, 1], 'step': 14, 'year': 2026}, [27, '2026-01-01', True]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('partial-repair probe', {'anchor': [2024, 10, 14], 'step': 7, 'year': 2024}, [53, '2024-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('partial-repair probe', {'anchor': [2019, 8, 28], 'step': 14, 'year': 2020}, [27, '2020-01-01', True]), ('partial-repair probe', {'anchor': [2025, 3, 13], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False])], [('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('regression', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('partial-repair probe', {'anchor': [2024, 10, 27], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2018, 3, 28], 'step': 14, 'year': 2020}, [27, '2020-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False])], [('regression', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('regression', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('partial-repair probe', {'anchor': [2021, 5, 2], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2025, 9, 4], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False]), ('additional oracle', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True])]]
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 first pay date reported for a year falls in December of the prior year.

Input {anchor [y,m,d] (any pay date), step 7|14 days, year}. Pay dates are anchor + k*step for all integers k. Return [count of pay dates within Jan 1..Dec 31 of year inclusive, ISO date of the first one, whether the count exceeds the nominal periods (26 biweekly, 52 weekly)].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import datetime
N = 1
observations = []
def solve(x):
    anchor = datetime.date(*x['anchor'])
    lo = datetime.date(x['year'], 1, 1)
    hi = datetime.date(x['year'], 12, 31)
    off = (lo - anchor).days
    k = -(-off // x['step'])
    first = anchor + datetime.timedelta(days=k * x['step'])
    count = (hi - first).days // x['step']
    periods = 26 if x['step'] == 14 else 52
    return [count, first.isoformat(), count > periods]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2026, 1, 1], 'step': 14, 'year': 2026}, [27, '2026-01-01', True]), ('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False])], [('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe', {'anchor': [2022, 8, 16], 'step': 7, 'year': 2024}, [53, '2024-01-02', True]), ('partial-repair probe', {'anchor': [2025, 3, 13], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('partial-repair probe', {'anchor': [2020, 3, 26], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('partial-repair probe', {'anchor': [2024, 10, 27], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False])], [('regression', {'anchor': [2022, 8, 16], 'step': 7, 'year': 2024}, [53, '2024-01-02', True]), ('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('partial-repair probe', {'anchor': [2023, 3, 28], 'step': 14, 'year': 2024}, [27, '2024-01-02', True]), ('partial-repair probe', {'anchor': [2021, 5, 2], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False])]]
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
import datetime
N = 1
observations = []
def solve(x):
    anchor = datetime.date(*x['anchor'])
    lo = datetime.date(x['year'], 1, 1)
    hi = datetime.date(x['year'], 12, 31)
    off = (lo - anchor).days
    k = -(-off // x['step'])
    first = anchor + datetime.timedelta(days=k * x['step'])
    count = (hi - first).days // x['step'] + (1 if (hi - first).days % x['step'] else 0)
    periods = 26 if x['step'] == 14 else 52
    return [count, first.isoformat(), count > periods]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'anchor': [2026, 1, 1], 'step': 14, 'year': 2026}, [27, '2026-01-01', True]), ('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False])], [('regression (boundary)', {'anchor': [2020, 12, 31], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('partial-repair probe', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2021, 6, 20], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('regression (boundary)', {'anchor': [2024, 1, 5], 'step': 14, 'year': 2024}, [26, '2024-01-05', False]), ('partial-repair probe', {'anchor': [2022, 8, 16], 'step': 7, 'year': 2024}, [53, '2024-01-02', True]), ('partial-repair probe', {'anchor': [2025, 3, 13], 'step': 7, 'year': 2026}, [53, '2026-01-01', True]), ('additional oracle', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False])], [('regression', {'anchor': [2021, 1, 17], 'step': 14, 'year': 2023}, [27, '2023-01-01', True]), ('regression', {'anchor': [2023, 8, 10], 'step': 14, 'year': 2024}, [26, '2024-01-11', False]), ('partial-repair probe', {'anchor': [2020, 3, 26], 'step': 14, 'year': 2020}, [27, '2020-01-02', True]), ('partial-repair probe', {'anchor': [2024, 10, 27], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('additional oracle', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False])], [('regression', {'anchor': [2022, 8, 16], 'step': 7, 'year': 2024}, [53, '2024-01-02', True]), ('regression', {'anchor': [2024, 3, 10], 'step': 14, 'year': 2024}, [26, '2024-01-14', False]), ('partial-repair probe', {'anchor': [2023, 3, 28], 'step': 14, 'year': 2024}, [27, '2024-01-02', True]), ('partial-repair probe', {'anchor': [2021, 5, 2], 'step': 7, 'year': 2023}, [53, '2023-01-01', True]), ('additional oracle', {'anchor': [2020, 3, 23], 'step': 14, 'year': 2020}, [26, '2020-01-13', False]), ('additional oracle', {'anchor': [2019, 7, 21], 'step': 7, 'year': 2020}, [52, '2020-01-05', False]), ('additional oracle', {'anchor': [2021, 6, 11], 'step': 7, 'year': 2023}, [52, '2023-01-06', False])]]
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:
Every year shows one pay date fewer than the payroll calendar.

Input {anchor [y,m,d] (any pay date), step 7|14 days, year}. Pay dates are anchor + k*step for all integers k. Return [count of pay dates within Jan 1..Dec 31 of year inclusive, ISO date of the first one, whether the count exceeds the nominal periods (26 biweekly, 52 weekly)].

split: open-access


prompt:
In leap years a December 31 pay date is left out of the count.

Input {anchor [y,m,d] (any pay date), step 7|14 days, year}. Pay dates are anchor + k*step for all integers k. Return [count of pay dates within Jan 1..Dec 31 of year inclusive, ISO date of the first one, whether the count exceeds the nominal periods (26 biweekly, 52 weekly)].

split: open-access


prompt:
Normal years are flagged as having an extra pay period.

Input {anchor [y,m,d] (any pay date), step 7|14 days, year}. Pay dates are anchor + k*step for all integers k. Return [count of pay dates within Jan 1..Dec 31 of year inclusive, ISO date of the first one, whether the count exceeds the nominal periods (26 biweekly, 52 weekly)].

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    std = {'single': 1460000, 'mfj': 2920000, 'hoh': 2190000}[x['status']]
    annual = std + 505000 * x['dependents']
    exempt = (annual * 2 + periods) // (2 * periods)
    take_home = x['gross'] - x['taxes'] - x['pre_levy_ded'] - x['post_levy_ded']
    levy = max(0, take_home - exempt)
    return [exempt, levy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('partial-repair probe', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('normal control', {'gross': 367596, 'taxes': 19999, 'pre_levy_ded': 20821, 'post_levy_ded': 35382, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 0]), ('normal control', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('normal control', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('normal control', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722])], [('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('partial-repair probe', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('normal control', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('normal control', {'gross': 577739, 'taxes': 20404, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'biweekly'}, [114423, 442912]), ('normal control', {'gross': 63591, 'taxes': 13599, 'pre_levy_ded': 16434, 'post_levy_ded': 21975, 'status': 'single', 'dependents': 1, 'freq': 'monthly'}, [163750, 0]), ('normal control', {'gross': 395451, 'taxes': 34942, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 3, 'freq': 'monthly'}, [369583, 0])], [('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('regression', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('partial-repair probe', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('partial-repair probe', {'gross': 531960, 'taxes': 121383, 'pre_levy_ded': 0, 'post_levy_ded': 49273, 'status': 'mfj', 'dependents': 2, 'freq': 'monthly'}, [327500, 83077]), ('normal control', {'gross': 305137, 'taxes': 19564, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'semimonthly'}, [123958, 161615]), ('normal control', {'gross': 635528, 'taxes': 132531, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 3, 'freq': 'semimonthly'}, [184792, 318205]), ('normal control', {'gross': 366618, 'taxes': 60829, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'semimonthly'}, [123958, 181831]), ('normal control', {'gross': 8853, 'taxes': 59, 'pre_levy_ded': 24787, 'post_levy_ded': 28519, 'status': 'hoh', 'dependents': 4, 'freq': 'weekly'}, [80962, 0])], [('regression', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('regression', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('partial-repair probe', {'gross': 269535, 'taxes': 50302, 'pre_levy_ded': 0, 'post_levy_ded': 6956, 'status': 'mfj', 'dependents': 5, 'freq': 'weekly'}, [104712, 114521]), ('normal control', {'gross': 779132, 'taxes': 128015, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 613329]), ('normal control', {'gross': 69342, 'taxes': 11860, 'pre_levy_ded': 41829, 'post_levy_ded': 14623, 'status': 'mfj', 'dependents': 5, 'freq': 'weekly'}, [104712, 0]), ('normal control', {'gross': 6064, 'taxes': 1426, 'pre_levy_ded': 22874, 'post_levy_ded': 33677, 'status': 'hoh', 'dependents': 3, 'freq': 'monthly'}, [308750, 0]), ('normal control', {'gross': 33043, 'taxes': 265, 'pre_levy_ded': 23066, 'post_levy_ded': 21163, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 0])], [('regression', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('regression', {'gross': 531960, 'taxes': 121383, 'pre_levy_ded': 0, 'post_levy_ded': 49273, 'status': 'mfj', 'dependents': 2, 'freq': 'monthly'}, [327500, 83077]), ('partial-repair probe', {'gross': 725985, 'taxes': 84896, 'pre_levy_ded': 30943, 'post_levy_ded': 0, 'status': 'single', 'dependents': 4, 'freq': 'weekly'}, [66923, 543223]), ('partial-repair probe', {'gross': 477116, 'taxes': 107625, 'pre_levy_ded': 42879, 'post_levy_ded': 0, 'status': 'single', 'dependents': 2, 'freq': 'monthly'}, [205833, 120779]), ('normal control', {'gross': 151095, 'taxes': 31116, 'pre_levy_ded': 0, 'post_levy_ded': 34683, 'status': 'hoh', 'dependents': 2, 'freq': 'semimonthly'}, [133333, 0]), ('normal control', {'gross': 203821, 'taxes': 29456, 'pre_levy_ded': 8462, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'monthly'}, [247917, 0]), ('normal control', {'gross': 537193, 'taxes': 28810, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 54633]), ('normal control', {'gross': 311681, 'taxes': 23321, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 5, 'freq': 'biweekly'}, [209423, 78937])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    std = {'single': 1460000, 'mfj': 2920000, 'hoh': 2190000}[x['status']]
    annual = std + 505000 * x['dependents']
    exempt = (annual * 2 + periods) // (2 * periods)
    take_home = x['gross'] - x['taxes'] - x['post_levy_ded']
    levy = max(0, take_home - exempt)
    return [exempt, levy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('partial-repair probe', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('normal control', {'gross': 367596, 'taxes': 19999, 'pre_levy_ded': 20821, 'post_levy_ded': 35382, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 0]), ('normal control', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('normal control', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('normal control', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722])], [('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('partial-repair probe', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('normal control', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('normal control', {'gross': 577739, 'taxes': 20404, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'biweekly'}, [114423, 442912]), ('normal control', {'gross': 63591, 'taxes': 13599, 'pre_levy_ded': 16434, 'post_levy_ded': 21975, 'status': 'single', 'dependents': 1, 'freq': 'monthly'}, [163750, 0]), ('normal control', {'gross': 395451, 'taxes': 34942, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 3, 'freq': 'monthly'}, [369583, 0])], [('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('regression', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('partial-repair probe', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('partial-repair probe', {'gross': 531960, 'taxes': 121383, 'pre_levy_ded': 0, 'post_levy_ded': 49273, 'status': 'mfj', 'dependents': 2, 'freq': 'monthly'}, [327500, 83077]), ('normal control', {'gross': 305137, 'taxes': 19564, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'semimonthly'}, [123958, 161615]), ('normal control', {'gross': 635528, 'taxes': 132531, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 3, 'freq': 'semimonthly'}, [184792, 318205]), ('normal control', {'gross': 366618, 'taxes': 60829, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'semimonthly'}, [123958, 181831]), ('normal control', {'gross': 8853, 'taxes': 59, 'pre_levy_ded': 24787, 'post_levy_ded': 28519, 'status': 'hoh', 'dependents': 4, 'freq': 'weekly'}, [80962, 0])], [('regression', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906]), ('regression', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('partial-repair probe', {'gross': 269535, 'taxes': 50302, 'pre_levy_ded': 0, 'post_levy_ded': 6956, 'status': 'mfj', 'dependents': 5, 'freq': 'weekly'}, [104712, 114521]), ('normal control', {'gross': 779132, 'taxes': 128015, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 613329]), ('normal control', {'gross': 69342, 'taxes': 11860, 'pre_levy_ded': 41829, 'post_levy_ded': 14623, 'status': 'mfj', 'dependents': 5, 'freq': 'weekly'}, [104712, 0]), ('normal control', {'gross': 6064, 'taxes': 1426, 'pre_levy_ded': 22874, 'post_levy_ded': 33677, 'status': 'hoh', 'dependents': 3, 'freq': 'monthly'}, [308750, 0]), ('normal control', {'gross': 33043, 'taxes': 265, 'pre_levy_ded': 23066, 'post_levy_ded': 21163, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 0])], [('regression', {'gross': 558221, 'taxes': 118600, 'pre_levy_ded': 0, 'post_levy_ded': 47539, 'status': 'hoh', 'dependents': 2, 'freq': 'biweekly'}, [123077, 316544]), ('regression', {'gross': 531960, 'taxes': 121383, 'pre_levy_ded': 0, 'post_levy_ded': 49273, 'status': 'mfj', 'dependents': 2, 'freq': 'monthly'}, [327500, 83077]), ('partial-repair probe', {'gross': 725985, 'taxes': 84896, 'pre_levy_ded': 30943, 'post_levy_ded': 0, 'status': 'single', 'dependents': 4, 'freq': 'weekly'}, [66923, 543223]), ('partial-repair probe', {'gross': 477116, 'taxes': 107625, 'pre_levy_ded': 42879, 'post_levy_ded': 0, 'status': 'single', 'dependents': 2, 'freq': 'monthly'}, [205833, 120779]), ('normal control', {'gross': 151095, 'taxes': 31116, 'pre_levy_ded': 0, 'post_levy_ded': 34683, 'status': 'hoh', 'dependents': 2, 'freq': 'semimonthly'}, [133333, 0]), ('normal control', {'gross': 203821, 'taxes': 29456, 'pre_levy_ded': 8462, 'post_levy_ded': 0, 'status': 'single', 'dependents': 3, 'freq': 'monthly'}, [247917, 0]), ('normal control', {'gross': 537193, 'taxes': 28810, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 54633]), ('normal control', {'gross': 311681, 'taxes': 23321, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 5, 'freq': 'biweekly'}, [209423, 78937])]]
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 enroll in new deductions after a levy shrink the levy payment.

Input {gross, taxes, pre_levy_ded, post_levy_ded, status, dependents, freq}. Annual exempt = standard amount (single 14,600, mfj 29,200, hoh 21,900 dollars) + 5,050.00 per dependent (the taxpayer is not a dependent); per-period exempt = annual/periods half-up (weekly 52, biweekly 26, semimonthly 24, monthly 12). Take-home counts only deductions in place before the levy. Levy = max(0, take-home - exempt). Return [exempt, levy].

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    std = {'single': 1460000, 'mfj': 2920000, 'hoh': 2190000}[x['status']]
    annual = std + 505000 * (x['dependents'] + 1)
    exempt = (annual * 2 + periods) // (2 * periods)
    take_home = x['gross'] - x['taxes'] - x['pre_levy_ded']
    levy = max(0, take_home - exempt)
    return [exempt, levy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('regression', {'gross': 367596, 'taxes': 19999, 'pre_levy_ded': 20821, 'post_levy_ded': 35382, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 0]), ('partial-repair probe', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('additional oracle', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121])], [('regression', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('partial-repair probe', {'gross': 739109, 'taxes': 142864, 'pre_levy_ded': 16360, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'biweekly'}, [112308, 467577]), ('additional oracle', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121])], [('regression', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('partial-repair probe', {'gross': 635842, 'taxes': 140017, 'pre_levy_ded': 49330, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'biweekly'}, [56154, 390341]), ('partial-repair probe', {'gross': 527478, 'taxes': 67598, 'pre_levy_ded': 40974, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'weekly'}, [56154, 362752]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664])], [('regression', {'gross': 739109, 'taxes': 142864, 'pre_levy_ded': 16360, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'biweekly'}, [112308, 467577]), ('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 347956, 'taxes': 39116, 'pre_levy_ded': 0, 'post_levy_ded': 15819, 'status': 'hoh', 'dependents': 0, 'freq': 'monthly'}, [182500, 126340]), ('partial-repair probe', {'gross': 219759, 'taxes': 9593, 'pre_levy_ded': 11439, 'post_levy_ded': 17732, 'status': 'hoh', 'dependents': 0, 'freq': 'monthly'}, [182500, 16227]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('additional oracle', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722])], [('regression', {'gross': 635842, 'taxes': 140017, 'pre_levy_ded': 49330, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'biweekly'}, [56154, 390341]), ('regression', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('partial-repair probe', {'gross': 426686, 'taxes': 44919, 'pre_levy_ded': 7768, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 282749]), ('partial-repair probe', {'gross': 245308, 'taxes': 551, 'pre_levy_ded': 0, 'post_levy_ded': 5125, 'status': 'mfj', 'dependents': 0, 'freq': 'monthly'}, [243333, 1424]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('additional oracle', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722]), ('additional oracle', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = {'weekly': 52, 'biweekly': 26, 'semimonthly': 24, 'monthly': 12}[x['freq']]
    std = {'single': 1460000, 'mfj': 2920000, 'hoh': 2190000}[x['status']]
    annual = std + 505000 * max(1, x['dependents'])
    exempt = (annual * 2 + periods) // (2 * periods)
    take_home = x['gross'] - x['taxes'] - x['pre_levy_ded']
    levy = max(0, take_home - exempt)
    return [exempt, levy]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('regression', {'gross': 367596, 'taxes': 19999, 'pre_levy_ded': 20821, 'post_levy_ded': 35382, 'status': 'mfj', 'dependents': 5, 'freq': 'monthly'}, [453750, 0]), ('partial-repair probe', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('additional oracle', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121])], [('regression', {'gross': 138753, 'taxes': 7542, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'weekly'}, [28077, 103134]), ('regression', {'gross': 314207, 'taxes': 9435, 'pre_levy_ded': 16283, 'post_levy_ded': 19170, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 197239]), ('partial-repair probe', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('partial-repair probe', {'gross': 739109, 'taxes': 142864, 'pre_levy_ded': 16360, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'biweekly'}, [112308, 467577]), ('additional oracle', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121])], [('regression', {'gross': 714333, 'taxes': 49017, 'pre_levy_ded': 0, 'post_levy_ded': 19873, 'status': 'single', 'dependents': 0, 'freq': 'monthly'}, [121667, 543649]), ('regression', {'gross': 375806, 'taxes': 85086, 'pre_levy_ded': 17388, 'post_levy_ded': 18649, 'status': 'mfj', 'dependents': 1, 'freq': 'semimonthly'}, [142708, 130624]), ('partial-repair probe', {'gross': 635842, 'taxes': 140017, 'pre_levy_ded': 49330, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'biweekly'}, [56154, 390341]), ('partial-repair probe', {'gross': 527478, 'taxes': 67598, 'pre_levy_ded': 40974, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'weekly'}, [56154, 362752]), ('additional oracle', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664])], [('regression', {'gross': 739109, 'taxes': 142864, 'pre_levy_ded': 16360, 'post_levy_ded': 0, 'status': 'mfj', 'dependents': 0, 'freq': 'biweekly'}, [112308, 467577]), ('regression', {'gross': 662079, 'taxes': 145163, 'pre_levy_ded': 13433, 'post_levy_ded': 24210, 'status': 'mfj', 'dependents': 4, 'freq': 'monthly'}, [411667, 91816]), ('partial-repair probe', {'gross': 347956, 'taxes': 39116, 'pre_levy_ded': 0, 'post_levy_ded': 15819, 'status': 'hoh', 'dependents': 0, 'freq': 'monthly'}, [182500, 126340]), ('partial-repair probe', {'gross': 219759, 'taxes': 9593, 'pre_levy_ded': 11439, 'post_levy_ded': 17732, 'status': 'hoh', 'dependents': 0, 'freq': 'monthly'}, [182500, 16227]), ('additional oracle', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('additional oracle', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722])], [('regression', {'gross': 635842, 'taxes': 140017, 'pre_levy_ded': 49330, 'post_levy_ded': 0, 'status': 'single', 'dependents': 0, 'freq': 'biweekly'}, [56154, 390341]), ('regression', {'gross': 85343, 'taxes': 8434, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'weekly'}, [37788, 39121]), ('partial-repair probe', {'gross': 426686, 'taxes': 44919, 'pre_levy_ded': 7768, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 0, 'freq': 'semimonthly'}, [91250, 282749]), ('partial-repair probe', {'gross': 245308, 'taxes': 551, 'pre_levy_ded': 0, 'post_levy_ded': 5125, 'status': 'mfj', 'dependents': 0, 'freq': 'monthly'}, [243333, 1424]), ('additional oracle', {'gross': 776186, 'taxes': 132647, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'single', 'dependents': 1, 'freq': 'semimonthly'}, [81875, 561664]), ('additional oracle', {'gross': 563938, 'taxes': 31966, 'pre_levy_ded': 0, 'post_levy_ded': 0, 'status': 'hoh', 'dependents': 3, 'freq': 'weekly'}, [71250, 460722]), ('additional oracle', {'gross': 479258, 'taxes': 23759, 'pre_levy_ded': 40016, 'post_levy_ded': 17364, 'status': 'mfj', 'dependents': 2, 'freq': 'weekly'}, [75577, 339906])]]
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:
Every levied employee receives one extra dependent exemption.

Input {gross, taxes, pre_levy_ded, post_levy_ded, status, dependents, freq}. Annual exempt = standard amount (single 14,600, mfj 29,200, hoh 21,900 dollars) + 5,050.00 per dependent (the taxpayer is not a dependent); per-period exempt = annual/periods half-up (weekly 52, biweekly 26, semimonthly 24, monthly 12). Take-home counts only deductions in place before the levy. Levy = max(0, take-home - exempt). Return [exempt, levy].

split: open-access