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

N = 1
observations = []
def solve(x):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if x['currency'] == 'JPY':
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 77, 'currency': 'CLP', 'num': 12, 'den': 365}, {'minor': 3, 'display': '3 CLP'}), ('regression', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'}), ('partial-repair probe', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'})], [('regression', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'}), ('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('partial-repair probe', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('boundary control', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'})], [('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('regression', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('partial-repair probe', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('partial-repair probe', {'price': -45, 'currency': 'CLP', 'num': 496, 'den': 1000}, {'minor': -22, 'display': '-22 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'})], [('regression', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('regression', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('partial-repair probe', {'price': 388537, 'currency': 'CLP', 'num': 201, 'den': 365}, {'minor': 213961, 'display': '213961 CLP'}), ('partial-repair probe', {'price': -1, 'currency': 'CLP', 'num': 27, 'den': 31}, {'minor': -1, 'display': '-1 CLP'}), ('boundary control', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': -29, 'currency': 'USD', 'num': 316, 'den': 1000}, {'minor': -9, 'display': '-0.09 USD'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'})], [('regression', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('regression', {'price': -45, 'currency': 'CLP', 'num': 496, 'den': 1000}, {'minor': -22, 'display': '-22 CLP'}), ('partial-repair probe', {'price': 791156, 'currency': 'CLP', 'num': 1, 'den': 2}, {'minor': 395578, 'display': '395578 CLP'}), ('partial-repair probe', {'price': 830593, 'currency': 'CLP', 'num': 569, 'den': 1000}, {'minor': 472607, 'display': '472607 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'})]]
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):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if exp == 0 and x['currency'] != 'CLP':
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': 77, 'currency': 'CLP', 'num': 12, 'den': 365}, {'minor': 3, 'display': '3 CLP'}), ('regression', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'}), ('partial-repair probe', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'})], [('regression', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'}), ('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('partial-repair probe', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('boundary control', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'})], [('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('regression', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('partial-repair probe', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('partial-repair probe', {'price': -45, 'currency': 'CLP', 'num': 496, 'den': 1000}, {'minor': -22, 'display': '-22 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'})], [('regression', {'price': 771210, 'currency': 'CLP', 'num': 250, 'den': 365}, {'minor': 528226, 'display': '528226 CLP'}), ('regression', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('partial-repair probe', {'price': 388537, 'currency': 'CLP', 'num': 201, 'den': 365}, {'minor': 213961, 'display': '213961 CLP'}), ('partial-repair probe', {'price': -1, 'currency': 'CLP', 'num': 27, 'den': 31}, {'minor': -1, 'display': '-1 CLP'}), ('boundary control', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': -29, 'currency': 'USD', 'num': 316, 'den': 1000}, {'minor': -9, 'display': '-0.09 USD'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'})], [('regression', {'price': 705318, 'currency': 'CLP', 'num': 206, 'den': 365}, {'minor': 398070, 'display': '398070 CLP'}), ('regression', {'price': -45, 'currency': 'CLP', 'num': 496, 'den': 1000}, {'minor': -22, 'display': '-22 CLP'}), ('partial-repair probe', {'price': 791156, 'currency': 'CLP', 'num': 1, 'den': 2}, {'minor': 395578, 'display': '395578 CLP'}), ('partial-repair probe', {'price': 830593, 'currency': 'CLP', 'num': 569, 'den': 1000}, {'minor': 472607, 'display': '472607 CLP'}), ('boundary control', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'})]]
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:
Chilean peso invoices print a decimal point and a stray digit.

Input {price (signed minor units), currency, num, den}. Exponents: USD 2, EUR 2, JPY 0, KWD 3, CLP 0. Amount = price*num/den rounded half away from zero. Display: zero-exponent currencies show an integer; others show sign, major units, a dot and exactly exponent digits, then a space and the code. Return {minor, display}.

split: open-access


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

N = 1
observations = []
def solve(x):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%d' % (sign, q, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('partial-repair probe', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'})], [('regression', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('partial-repair probe', {'price': 96, 'currency': 'KWD', 'num': 19, 'den': 31}, {'minor': 59, 'display': '0.059 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'})], [('regression', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('regression', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': 79, 'currency': 'KWD', 'num': 2, 'den': 2}, {'minor': 79, 'display': '0.079 KWD'}), ('partial-repair probe', {'price': -147, 'currency': 'KWD', 'num': 546, 'den': 1000}, {'minor': -80, 'display': '-0.080 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'})], [('regression', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('regression', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('partial-repair probe', {'price': 48, 'currency': 'KWD', 'num': 269, 'den': 1000}, {'minor': 13, 'display': '0.013 KWD'}), ('partial-repair probe', {'price': 140, 'currency': 'KWD', 'num': 661, 'den': 1000}, {'minor': 93, 'display': '0.093 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'}), ('normal control', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('normal control', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'}), ('normal control', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'})]]
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):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%02d' % (sign, q, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('partial-repair probe', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'})], [('regression', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('partial-repair probe', {'price': 96, 'currency': 'KWD', 'num': 19, 'den': 31}, {'minor': 59, 'display': '0.059 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'})], [('regression', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('regression', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': 79, 'currency': 'KWD', 'num': 2, 'den': 2}, {'minor': 79, 'display': '0.079 KWD'}), ('partial-repair probe', {'price': -147, 'currency': 'KWD', 'num': 546, 'den': 1000}, {'minor': -80, 'display': '-0.080 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'})], [('regression', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('regression', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('partial-repair probe', {'price': 48, 'currency': 'KWD', 'num': 269, 'den': 1000}, {'minor': 13, 'display': '0.013 KWD'}), ('partial-repair probe', {'price': 140, 'currency': 'KWD', 'num': 661, 'den': 1000}, {'minor': 93, 'display': '0.093 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('boundary control', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('normal control', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'}), ('normal control', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('normal control', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'}), ('normal control', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'})]]
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:
Amounts like 12.05 display as 12.5.

Input {price (signed minor units), currency, num, den}. Exponents: USD 2, EUR 2, JPY 0, KWD 3, CLP 0. Amount = price*num/den rounded half away from zero. Display: zero-exponent currencies show an integer; others show sign, major units, a dot and exactly exponent digits, then a space and the code. Return {minor, display}.

split: open-access


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

N = 1
observations = []
def solve(x):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (n * 2 + x['den']) // (2 * x['den'])
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe (boundary)', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('partial-repair probe', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'})], [('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('regression', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('partial-repair probe', {'price': -29, 'currency': 'USD', 'num': 316, 'den': 1000}, {'minor': -9, 'display': '-0.09 USD'}), ('partial-repair probe', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'})], [('regression', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('partial-repair probe', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'}), ('normal control', {'price': 86, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'})], [('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('regression', {'price': -25, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -13, 'display': '-0.13 EUR'}), ('partial-repair probe', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('partial-repair probe', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'}), ('normal control', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('normal control', {'price': 8, 'currency': 'EUR', 'num': 25, 'den': 31}, {'minor': 6, 'display': '0.06 EUR'}), ('normal control', {'price': -19, 'currency': 'EUR', 'num': 0, 'den': 31}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'})]]
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):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = n // x['den']
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(abs(v), 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe (boundary)', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('partial-repair probe', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('normal control', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('partial-repair probe', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('partial-repair probe', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -88, 'currency': 'KWD', 'num': 15, 'den': 31}, {'minor': -43, 'display': '-0.043 KWD'}), ('normal control', {'price': -20, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -10, 'display': '-0.10 USD'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'})], [('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('regression', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('partial-repair probe', {'price': -29, 'currency': 'USD', 'num': 316, 'den': 1000}, {'minor': -9, 'display': '-0.09 USD'}), ('partial-repair probe', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': -28, 'currency': 'EUR', 'num': 30, 'den': 30}, {'minor': -28, 'display': '-0.28 EUR'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'})], [('regression', {'price': -51, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -26, 'display': '-0.26 EUR'}), ('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('partial-repair probe', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('partial-repair probe', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'}), ('normal control', {'price': 86, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'})], [('regression', {'price': -98, 'currency': 'CLP', 'num': 3, 'den': 4}, {'minor': -74, 'display': '-74 CLP'}), ('regression', {'price': -25, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -13, 'display': '-0.13 EUR'}), ('partial-repair probe', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('partial-repair probe', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'}), ('normal control', {'price': -74, 'currency': 'KWD', 'num': 111, 'den': 365}, {'minor': -23, 'display': '-0.023 KWD'}), ('normal control', {'price': 8, 'currency': 'EUR', 'num': 25, 'den': 31}, {'minor': 6, 'display': '0.06 EUR'}), ('normal control', {'price': -19, 'currency': 'EUR', 'num': 0, 'den': 31}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 441137, 'currency': 'CLP', 'num': 2, 'den': 2}, {'minor': 441137, 'display': '441137 CLP'})]]
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:
Credit prorations of exactly half a minor unit round toward zero while debits round away.

Input {price (signed minor units), currency, num, den}. Exponents: USD 2, EUR 2, JPY 0, KWD 3, CLP 0. Amount = price*num/den rounded half away from zero. Display: zero-exponent currencies show an integer; others show sign, major units, a dot and exactly exponent digits, then a space and the code. Return {minor, display}.

split: open-access


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

N = 1
observations = []
def solve(x):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(v, 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('partial-repair probe', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('partial-repair probe', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('partial-repair probe', {'price': -70708, 'currency': 'EUR', 'num': 787, 'den': 1000}, {'minor': -55647, 'display': '-556.47 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'})], [('regression', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('partial-repair probe', {'price': -686147, 'currency': 'EUR', 'num': 2, 'den': 31}, {'minor': -44268, 'display': '-442.68 EUR'}), ('partial-repair probe', {'price': -272855, 'currency': 'KWD', 'num': 798, 'den': 1000}, {'minor': -217738, 'display': '-217.738 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'})], [('regression', {'price': -70708, 'currency': 'EUR', 'num': 787, 'den': 1000}, {'minor': -55647, 'display': '-556.47 EUR'}), ('regression', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('partial-repair probe', {'price': -940440, 'currency': 'EUR', 'num': 894, 'den': 1000}, {'minor': -840753, 'display': '-8407.53 EUR'}), ('partial-repair probe', {'price': -345259, 'currency': 'EUR', 'num': 4, 'den': 4}, {'minor': -345259, 'display': '-3452.59 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 86, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'})], [('regression', {'price': -686147, 'currency': 'EUR', 'num': 2, 'den': 31}, {'minor': -44268, 'display': '-442.68 EUR'}), ('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': -799709, 'currency': 'USD', 'num': 177, 'den': 365}, {'minor': -387804, 'display': '-3878.04 USD'}), ('partial-repair probe', {'price': -45094, 'currency': 'EUR', 'num': 282, 'den': 365}, {'minor': -34840, 'display': '-348.40 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 8, 'currency': 'EUR', 'num': 25, 'den': 31}, {'minor': 6, 'display': '0.06 EUR'}), ('normal control', {'price': -19, 'currency': 'EUR', 'num': 0, 'den': 31}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('normal control', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'})]]
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):
    exp = {'USD': 2, 'EUR': 2, 'JPY': 0, 'KWD': 3, 'CLP': 0}[x['currency']]
    n = x['price'] * x['num']
    v = (abs(n) * 2 + x['den']) // (2 * x['den'])
    v = v if n >= 0 else -v
    if exp == 0:
        disp = str(v)
    else:
        sign = '-' if v < 0 else ''
        q, r = divmod(v, 10 ** exp) if v >= 0 else (-(abs(v) // 10 ** exp), abs(v) % 10 ** exp)
        disp = '%s%d.%0*d' % (sign, q, exp, r)
    return {'minor': v, 'display': disp + ' ' + x['currency']}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('regression (boundary)', {'price': -3, 'currency': 'USD', 'num': 1, 'den': 2}, {'minor': -2, 'display': '-0.02 USD'}), ('partial-repair probe', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('partial-repair probe', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 63, 'currency': 'JPY', 'num': 925, 'den': 1000}, {'minor': 58, 'display': '58 JPY'}), ('normal control', {'price': 59, 'currency': 'JPY', 'num': 2, 'den': 4}, {'minor': 30, 'display': '30 JPY'}), ('normal control', {'price': 26, 'currency': 'KWD', 'num': 3, 'den': 31}, {'minor': 3, 'display': '0.003 KWD'}), ('normal control', {'price': -18, 'currency': 'JPY', 'num': 81, 'den': 365}, {'minor': -4, 'display': '-4 JPY'})], [('regression', {'price': -357324, 'currency': 'USD', 'num': 19, 'den': 30}, {'minor': -226305, 'display': '-2263.05 USD'}), ('regression (boundary)', {'price': -7, 'currency': 'KWD', 'num': 1, 'den': 2}, {'minor': -4, 'display': '-0.004 KWD'}), ('partial-repair probe', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('partial-repair probe', {'price': -70708, 'currency': 'EUR', 'num': 787, 'den': 1000}, {'minor': -55647, 'display': '-556.47 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': -48, 'currency': 'JPY', 'num': 0, 'den': 4}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': -79, 'currency': 'JPY', 'num': 200, 'den': 365}, {'minor': -43, 'display': '-43 JPY'}), ('normal control', {'price': -93, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 464209, 'currency': 'EUR', 'num': 10, 'den': 30}, {'minor': 154736, 'display': '1547.36 EUR'})], [('regression', {'price': -927642, 'currency': 'KWD', 'num': 9, 'den': 31}, {'minor': -269315, 'display': '-269.315 KWD'}), ('regression (boundary)', {'price': -105, 'currency': 'EUR', 'num': 1, 'den': 2}, {'minor': -53, 'display': '-0.53 EUR'}), ('partial-repair probe', {'price': -686147, 'currency': 'EUR', 'num': 2, 'den': 31}, {'minor': -44268, 'display': '-442.68 EUR'}), ('partial-repair probe', {'price': -272855, 'currency': 'KWD', 'num': 798, 'den': 1000}, {'minor': -217738, 'display': '-217.738 KWD'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 61, 'currency': 'JPY', 'num': 50, 'den': 365}, {'minor': 8, 'display': '8 JPY'}), ('normal control', {'price': 675691, 'currency': 'KWD', 'num': 214, 'den': 365}, {'minor': 396159, 'display': '396.159 KWD'}), ('normal control', {'price': 95, 'currency': 'USD', 'num': 25, 'den': 30}, {'minor': 79, 'display': '0.79 USD'}), ('normal control', {'price': 553663, 'currency': 'USD', 'num': 138, 'den': 365}, {'minor': 209330, 'display': '2093.30 USD'})], [('regression', {'price': -70708, 'currency': 'EUR', 'num': 787, 'den': 1000}, {'minor': -55647, 'display': '-556.47 EUR'}), ('regression', {'price': -6310, 'currency': 'EUR', 'num': 23, 'den': 31}, {'minor': -4682, 'display': '-46.82 EUR'}), ('partial-repair probe', {'price': -940440, 'currency': 'EUR', 'num': 894, 'den': 1000}, {'minor': -840753, 'display': '-8407.53 EUR'}), ('partial-repair probe', {'price': -345259, 'currency': 'EUR', 'num': 4, 'den': 4}, {'minor': -345259, 'display': '-3452.59 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 86, 'currency': 'EUR', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': 21, 'currency': 'JPY', 'num': 3, 'den': 30}, {'minor': 2, 'display': '2 JPY'}), ('normal control', {'price': 127, 'currency': 'JPY', 'num': 0, 'den': 2}, {'minor': 0, 'display': '0 JPY'}), ('normal control', {'price': 248141, 'currency': 'EUR', 'num': 187, 'den': 365}, {'minor': 127130, 'display': '1271.30 EUR'})], [('regression', {'price': -686147, 'currency': 'EUR', 'num': 2, 'den': 31}, {'minor': -44268, 'display': '-442.68 EUR'}), ('regression', {'price': -35, 'currency': 'KWD', 'num': 30, 'den': 30}, {'minor': -35, 'display': '-0.035 KWD'}), ('partial-repair probe', {'price': -799709, 'currency': 'USD', 'num': 177, 'den': 365}, {'minor': -387804, 'display': '-3878.04 USD'}), ('partial-repair probe', {'price': -45094, 'currency': 'EUR', 'num': 282, 'den': 365}, {'minor': -34840, 'display': '-348.40 EUR'}), ('boundary control', {'price': 5, 'currency': 'JPY', 'num': 1, 'den': 2}, {'minor': 3, 'display': '3 JPY'}), ('normal control', {'price': 8, 'currency': 'EUR', 'num': 25, 'den': 31}, {'minor': 6, 'display': '0.06 EUR'}), ('normal control', {'price': -19, 'currency': 'EUR', 'num': 0, 'den': 31}, {'minor': 0, 'display': '0.00 EUR'}), ('normal control', {'price': -70, 'currency': 'JPY', 'num': 209, 'den': 365}, {'minor': -40, 'display': '-40 JPY'}), ('normal control', {'price': 26512, 'currency': 'USD', 'num': 248, 'den': 365}, {'minor': 18014, 'display': '180.14 USD'})]]
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:
Negative prorations display garbled amounts such as --2.50.

Input {price (signed minor units), currency, num, den}. Exponents: USD 2, EUR 2, JPY 0, KWD 3, CLP 0. Amount = price*num/den rounded half away from zero. Display: zero-exponent currencies show an integer; others show sign, major units, a dot and exactly exponent digits, then a space and the code. Return {minor, display}.

split: open-access


prompt:
Downgrade invoices over-collect tax because unused-time credits carry no tax reversal.

Input {lines: [[signed cents, taxable]], rate_bp}. Tax is computed per taxable line, including negative credit lines (negative tax), each rounded half away from zero, then summed. Subtotal is the sum of all lines. Return [subtotal, tax, subtotal + tax].

split: open-access


prompt:
Invoice tax differs by a cent from the sum of the per-line tax amounts shown.

Input {lines: [[signed cents, taxable]], rate_bp}. Tax is computed per taxable line, including negative credit lines (negative tax), each rounded half away from zero, then summed. Subtotal is the sum of all lines. Return [subtotal, tax, subtotal + tax].

split: open-access


prompt:
Non-taxable lines disappear from the invoice subtotal.

Input {lines: [[signed cents, taxable]], rate_bp}. Tax is computed per taxable line, including negative credit lines (negative tax), each rounded half away from zero, then summed. Subtotal is the sum of all lines. Return [subtotal, tax, subtotal + tax].

split: open-access


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

N = 1
observations = []
def solve(x):
    started = x['months_used'] + 0
    started = min(started, 12)
    credit = x['annual'] * (12 - started) // 12
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('regression', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('partial-repair probe', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('normal control', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0])], [('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('partial-repair probe', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 4, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [8000, 8, 8])], [('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('partial-repair probe', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 7, 'days_into_month': 0, 'month_days': 30, 'monthly': 39814}, [49958, 1, 10144]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [49950, 50, 0]), ('normal control', {'annual': 177114, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [29519, 29, 548]), ('normal control', {'annual': 238019, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [138844, 138, 982])], [('regression', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 30, 'monthly': 23011}, [16650, 0, 16650]), ('partial-repair probe', {'annual': 12000, 'months_used': 6, 'days_into_month': 2, 'month_days': 31, 'monthly': 12900}, [5000, 0, 5000]), ('normal control', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 10366}, [69941, 6, 7745]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0])], [('regression', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 119900, 'months_used': 5, 'days_into_month': 1, 'month_days': 28, 'monthly': 999}, [59950, 60, 10]), ('partial-repair probe', {'annual': 68414, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 999}, [5701, 5, 706]), ('normal control', {'annual': 135833, 'months_used': 9, 'days_into_month': 0, 'month_days': 28, 'monthly': 12900}, [33958, 2, 8158]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 425201, 'months_used': 11, 'days_into_month': 0, 'month_days': 31, 'monthly': 12900}, [35433, 2, 9633]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [9991, 10, 1])]]
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):
    started = x['months_used'] + (1 if x['days_into_month'] > x['month_days'] // 2 else 0)
    started = min(started, 12)
    credit = x['annual'] * (12 - started) // 12
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('regression', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('partial-repair probe', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('normal control', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0])], [('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('partial-repair probe', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 4, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [8000, 8, 8])], [('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('partial-repair probe', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 7, 'days_into_month': 0, 'month_days': 30, 'monthly': 39814}, [49958, 1, 10144]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [49950, 50, 0]), ('normal control', {'annual': 177114, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [29519, 29, 548]), ('normal control', {'annual': 238019, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [138844, 138, 982])], [('regression', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 30, 'monthly': 23011}, [16650, 0, 16650]), ('partial-repair probe', {'annual': 12000, 'months_used': 6, 'days_into_month': 2, 'month_days': 31, 'monthly': 12900}, [5000, 0, 5000]), ('normal control', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 10366}, [69941, 6, 7745]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0])], [('regression', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 119900, 'months_used': 5, 'days_into_month': 1, 'month_days': 28, 'monthly': 999}, [59950, 60, 10]), ('partial-repair probe', {'annual': 68414, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 999}, [5701, 5, 706]), ('normal control', {'annual': 135833, 'months_used': 9, 'days_into_month': 0, 'month_days': 28, 'monthly': 12900}, [33958, 2, 8158]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 425201, 'months_used': 11, 'days_into_month': 0, 'month_days': 31, 'monthly': 12900}, [35433, 2, 9633]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [9991, 10, 1])]]
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:
Customers switching mid-month are credited for the month they are already using.

Input {annual, months_used, days_into_month, month_days, monthly}. Months started = months_used plus one if the current month has begun (days_into_month > 0), capped at 12. Credit = annual*(12 - started)//12. The credit pays whole future monthly invoices; the remainder stays as balance. Return [credit, covered_invoices, leftover].

split: open-access


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

N = 1
observations = []
def solve(x):
    started = x['months_used'] + (1 if x['days_into_month'] > 0 else 0)
    started = max(started, 0)
    credit = x['annual'] * (12 - started) // 12
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 23283, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('normal control', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990])], [('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('partial-repair probe', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 409273, 'months_used': 9, 'days_into_month': 16, 'month_days': 30, 'monthly': 999}, [68212, 68, 280]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996])], [('regression', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('normal control', {'annual': 423149, 'months_used': 6, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [176312, 176, 312]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('normal control', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601])], [('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('partial-repair probe', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('normal control', {'annual': 427427, 'months_used': 3, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [284951, 22, 1151]), ('normal control', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083])], [('regression', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0]), ('partial-repair probe', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 3, 'days_into_month': 23, 'month_days': 28, 'monthly': 12900}, [79933, 6, 2533]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 8, 'days_into_month': 16, 'month_days': 30, 'monthly': 10436}, [3000, 0, 3000])]]
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):
    started = x['months_used'] + (1 if x['days_into_month'] > 0 else 0)
    started = min(started, 11)
    credit = x['annual'] * (12 - started) // 12
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 23283, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('normal control', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990])], [('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('partial-repair probe', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 409273, 'months_used': 9, 'days_into_month': 16, 'month_days': 30, 'monthly': 999}, [68212, 68, 280]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996])], [('regression', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('normal control', {'annual': 423149, 'months_used': 6, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [176312, 176, 312]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('normal control', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601])], [('regression', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('regression', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('partial-repair probe', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('normal control', {'annual': 427427, 'months_used': 3, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [284951, 22, 1151]), ('normal control', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083])], [('regression', {'annual': 119900, 'months_used': 13, 'days_into_month': 16, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('regression', {'annual': 12000, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 20303}, [0, 0, 0]), ('partial-repair probe', {'annual': 119900, 'months_used': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0]), ('partial-repair probe', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 3, 'days_into_month': 23, 'month_days': 28, 'monthly': 12900}, [79933, 6, 2533]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 8, 'days_into_month': 16, 'month_days': 30, 'monthly': 10436}, [3000, 0, 3000])]]
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:
Customers switching after the annual term produce a negative credit.

Input {annual, months_used, days_into_month, month_days, monthly}. Months started = months_used plus one if the current month has begun (days_into_month > 0), capped at 12. Credit = annual*(12 - started)//12. The credit pays whole future monthly invoices; the remainder stays as balance. Return [credit, covered_invoices, leftover].

split: open-access


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

N = 1
observations = []
def solve(x):
    started = x['months_used'] + (1 if x['days_into_month'] > 0 else 0)
    started = min(started, 12)
    credit = x['annual'] // 12 * (12 - started)
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('partial-repair probe', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('normal control', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325])], [('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 409273, 'months_used': 9, 'days_into_month': 16, 'month_days': 30, 'monthly': 999}, [68212, 68, 280]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996])], [('regression', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('regression', {'annual': 423149, 'months_used': 6, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [176312, 176, 312]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('partial-repair probe', {'annual': 326637, 'months_used': 9, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [54439, 4, 2839]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('normal control', {'annual': 23283, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0])], [('regression', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('partial-repair probe', {'annual': 119900, 'months_used': 10, 'days_into_month': 1, 'month_days': 30, 'monthly': 3797}, [9991, 2, 2397]), ('partial-repair probe', {'annual': 119900, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 10366}, [69941, 6, 7745]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0])], [('regression', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('regression', {'annual': 427427, 'months_used': 3, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [284951, 22, 1151]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [9991, 10, 1]), ('partial-repair probe', {'annual': 78337, 'months_used': 2, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [58752, 4, 7152]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 8, 'days_into_month': 16, 'month_days': 30, 'monthly': 10436}, [3000, 0, 3000]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 30, 'monthly': 23011}, [16650, 0, 16650]), ('normal control', {'annual': 12000, 'months_used': 4, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [8000, 8, 8])]]
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):
    started = x['months_used'] + (1 if x['days_into_month'] > 0 else 0)
    started = min(started, 12)
    credit = (x['annual'] * (12 - started) + 6) // 12
    covered = credit // x['monthly']
    left = credit - covered * x['monthly']
    return [credit, covered, left]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('partial-repair probe', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('normal control', {'annual': 12000, 'months_used': 9, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [2000, 2, 2]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('normal control', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('normal control', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325])], [('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 12900}, [2000, 0, 2000]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 409273, 'months_used': 9, 'days_into_month': 16, 'month_days': 30, 'monthly': 999}, [68212, 68, 280]), ('normal control', {'annual': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996])], [('regression', {'annual': 119900, 'months_used': 2, 'days_into_month': 0, 'month_days': 31, 'monthly': 1000}, [99916, 99, 916]), ('regression', {'annual': 423149, 'months_used': 6, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [176312, 176, 312]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('partial-repair probe', {'annual': 326637, 'months_used': 9, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [54439, 4, 2839]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('normal control', {'annual': 23283, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 12, 'days_into_month': 15, 'month_days': 30, 'monthly': 999}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 26, 'month_days': 30, 'monthly': 999}, [0, 0, 0])], [('regression', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('partial-repair probe', {'annual': 119900, 'months_used': 10, 'days_into_month': 1, 'month_days': 30, 'monthly': 3797}, [9991, 2, 2397]), ('partial-repair probe', {'annual': 119900, 'months_used': 5, 'days_into_month': 0, 'month_days': 30, 'monthly': 10366}, [69941, 6, 7745]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 0, 'month_days': 30, 'monthly': 27694}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('normal control', {'annual': 119900, 'months_used': 12, 'days_into_month': 10, 'month_days': 28, 'monthly': 9029}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0])], [('regression', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('regression', {'annual': 427427, 'months_used': 3, 'days_into_month': 16, 'month_days': 31, 'monthly': 12900}, [284951, 22, 1151]), ('partial-repair probe', {'annual': 119900, 'months_used': 11, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [9991, 10, 1]), ('partial-repair probe', {'annual': 78337, 'months_used': 2, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [58752, 4, 7152]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 8, 'days_into_month': 16, 'month_days': 30, 'monthly': 10436}, [3000, 0, 3000]), ('normal control', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 30, 'monthly': 23011}, [16650, 0, 16650]), ('normal control', {'annual': 12000, 'months_used': 4, 'days_into_month': 0, 'month_days': 28, 'monthly': 999}, [8000, 8, 8])]]
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:
Credits for annual prices not divisible by twelve lose cents per month.

Input {annual, months_used, days_into_month, month_days, monthly}. Months started = months_used plus one if the current month has begun (days_into_month > 0), capped at 12. Credit = annual*(12 - started)//12. The credit pays whole future monthly invoices; the remainder stays as balance. Return [credit, covered_invoices, leftover].

split: open-access