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 - 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': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('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': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('partial-repair probe', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('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': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('partial-repair probe', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('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': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [49950, 50, 0])], [('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('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': 1, 'days_into_month': 16, 'month_days': 30, 'monthly': 1000}, [10000, 10, 0]), ('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': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0])], [('regression', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 13, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 24842}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 1000}, [2000, 2, 0])], [('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('partial-repair probe', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 11, 'days_into_month': 16, 'month_days': 30, 'monthly': 1000}, [0, 0, 0]), ('normal control', {'annual': 46896, 'months_used': 11, 'days_into_month': 1, 'month_days': 30, 'monthly': 1000}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 11, 'days_into_month': 14, 'month_days': 30, 'monthly': 12155}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 12, 'days_into_month': 0, 'month_days': 31, 'monthly': 16372}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    started = x['months_used'] + (1 if x['days_into_month'] > 0 else 0)
    started = min(started, 12)
    credit = x['annual'] * (12 - started) // 12
    covered = round(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': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('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': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('partial-repair probe', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('normal control', {'annual': 119900, 'months_used': 11, 'days_into_month': 15, 'month_days': 28, 'monthly': 999}, [0, 0, 0]), ('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': 99900, 'months_used': 0, 'days_into_month': 0, 'month_days': 30, 'monthly': 38952}, [99900, 2, 21996]), ('regression', {'annual': 119900, 'months_used': 4, 'days_into_month': 1, 'month_days': 30, 'monthly': 999}, [69941, 70, 11]), ('partial-repair probe', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('partial-repair probe', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('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': 119900, 'months_used': 11, 'days_into_month': 16, 'month_days': 31, 'monthly': 1512}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 6, 'days_into_month': 0, 'month_days': 30, 'monthly': 999}, [49950, 50, 0])], [('regression', {'annual': 119900, 'months_used': 0, 'days_into_month': 16, 'month_days': 28, 'monthly': 1000}, [109908, 109, 908]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [66600, 5, 2100]), ('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': 1, 'days_into_month': 16, 'month_days': 30, 'monthly': 1000}, [10000, 10, 0]), ('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': 12, 'days_into_month': 16, 'month_days': 28, 'monthly': 12900}, [0, 0, 0])], [('regression', {'annual': 99900, 'months_used': 6, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [41625, 41, 625]), ('regression', {'annual': 99900, 'months_used': 3, 'days_into_month': 1, 'month_days': 31, 'monthly': 16870}, [66600, 3, 15990]), ('partial-repair probe', {'annual': 422066, 'months_used': 1, 'days_into_month': 1, 'month_days': 31, 'monthly': 1000}, [351721, 351, 721]), ('partial-repair probe', {'annual': 228567, 'months_used': 5, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [114283, 8, 11083]), ('normal control', {'annual': 99900, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 119900, 'months_used': 13, 'days_into_month': 1, 'month_days': 31, 'monthly': 12900}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 13, 'days_into_month': 15, 'month_days': 30, 'monthly': 24842}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 10, 'days_into_month': 0, 'month_days': 30, 'monthly': 1000}, [2000, 2, 0])], [('regression', {'annual': 477658, 'months_used': 2, 'days_into_month': 16, 'month_days': 31, 'monthly': 999}, [358243, 358, 601]), ('regression', {'annual': 99900, 'months_used': 10, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [8325, 8, 325]), ('partial-repair probe', {'annual': 99900, 'months_used': 2, 'days_into_month': 15, 'month_days': 31, 'monthly': 1000}, [74925, 74, 925]), ('partial-repair probe', {'annual': 99900, 'months_used': 9, 'days_into_month': 15, 'month_days': 28, 'monthly': 1000}, [16650, 16, 650]), ('normal control', {'annual': 12000, 'months_used': 11, 'days_into_month': 16, 'month_days': 30, 'monthly': 1000}, [0, 0, 0]), ('normal control', {'annual': 46896, 'months_used': 11, 'days_into_month': 1, 'month_days': 30, 'monthly': 1000}, [0, 0, 0]), ('normal control', {'annual': 12000, 'months_used': 11, 'days_into_month': 14, 'month_days': 30, 'monthly': 12155}, [0, 0, 0]), ('normal control', {'annual': 99900, 'months_used': 12, 'days_into_month': 0, 'month_days': 31, 'monthly': 16372}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A partially funded monthly invoice is reported as covered and the leftover balance goes negative.

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):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance']
    use_bal = min(bal, due)
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('partial-repair probe', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('boundary control', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 18, 'credit_notes': [], 'balance': 23152, 'min_payment': 0}, [0, 23134, 0]), ('normal control', {'total': 1, 'credit_notes': [], 'balance': 25350, 'min_payment': 50}, [0, 25349, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 18849, 'credit_notes': [], 'balance': 21401, 'min_payment': 50}, [0, 2552, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('partial-repair probe', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('boundary control', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 82, 'credit_notes': [], 'balance': 29441, 'min_payment': 50}, [0, 29359, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('partial-repair probe', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('partial-repair probe', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('normal control', {'total': 83, 'credit_notes': [], 'balance': 9256, 'min_payment': 50}, [0, 9173, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 3623, 'min_payment': 100}, [0, 3487, 0]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + cn
    use_bal = min(bal, due)
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('partial-repair probe', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('boundary control', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 18, 'credit_notes': [], 'balance': 23152, 'min_payment': 0}, [0, 23134, 0]), ('normal control', {'total': 1, 'credit_notes': [], 'balance': 25350, 'min_payment': 50}, [0, 25349, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 18849, 'credit_notes': [], 'balance': 21401, 'min_payment': 50}, [0, 2552, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('partial-repair probe', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('boundary control', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 82, 'credit_notes': [], 'balance': 29441, 'min_payment': 50}, [0, 29359, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('partial-repair probe', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('partial-repair probe', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('normal control', {'total': 83, 'credit_notes': [], 'balance': 9256, 'min_payment': 50}, [0, 9173, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 3623, 'min_payment': 100}, [0, 3487, 0]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Credit notes larger than the invoice lose their excess value.

Input {total, credit_notes, balance, min_payment}. Credit notes apply first, capped at the total; any excess credit-note value joins the customer balance. The balance then applies up to the remaining due. A remaining due above 0 but below min_payment is carried to the next invoice instead of charged. Return [due, balance_after, carried].

split: open-access


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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = bal
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('normal control', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('boundary control', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('normal control', {'total': 27004, 'credit_notes': [11844, 8578], 'balance': 0, 'min_payment': 0}, [6582, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 32368, 'credit_notes': [17289, 13095], 'balance': 0, 'min_payment': 0}, [1984, 0, 0]), ('normal control', {'total': 36798, 'credit_notes': [1788], 'balance': 11576, 'min_payment': 50}, [23434, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 34021, 'credit_notes': [12282], 'balance': 0, 'min_payment': 100}, [21739, 0, 0]), ('normal control', {'total': 14007, 'credit_notes': [8643], 'balance': 0, 'min_payment': 50}, [5364, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('partial-repair probe', {'total': 9414, 'credit_notes': [5208], 'balance': 5543, 'min_payment': 50}, [0, 1337, 0]), ('boundary control', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 43066, 'credit_notes': [366, 14060, 1522], 'balance': 2601, 'min_payment': 100}, [24517, 0, 0]), ('normal control', {'total': 38060, 'credit_notes': [14975, 2846], 'balance': 13326, 'min_payment': 50}, [6913, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0])], [('regression', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0]), ('normal control', {'total': 48418, 'credit_notes': [6075], 'balance': 0, 'min_payment': 100}, [42343, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = min(bal, x['total'])
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('normal control', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('boundary control', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('normal control', {'total': 27004, 'credit_notes': [11844, 8578], 'balance': 0, 'min_payment': 0}, [6582, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 32368, 'credit_notes': [17289, 13095], 'balance': 0, 'min_payment': 0}, [1984, 0, 0]), ('normal control', {'total': 36798, 'credit_notes': [1788], 'balance': 11576, 'min_payment': 50}, [23434, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('partial-repair probe', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 34021, 'credit_notes': [12282], 'balance': 0, 'min_payment': 100}, [21739, 0, 0]), ('normal control', {'total': 14007, 'credit_notes': [8643], 'balance': 0, 'min_payment': 50}, [5364, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('partial-repair probe', {'total': 9414, 'credit_notes': [5208], 'balance': 5543, 'min_payment': 50}, [0, 1337, 0]), ('boundary control', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 43066, 'credit_notes': [366, 14060, 1522], 'balance': 2601, 'min_payment': 100}, [24517, 0, 0]), ('normal control', {'total': 38060, 'credit_notes': [14975, 2846], 'balance': 13326, 'min_payment': 50}, [6913, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0])], [('regression', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0]), ('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0]), ('normal control', {'total': 48418, 'credit_notes': [6075], 'balance': 0, 'min_payment': 100}, [42343, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Customers with large balances see negative amounts due and a drained balance.

Input {total, credit_notes, balance, min_payment}. Credit notes apply first, capped at the total; any excess credit-note value joins the customer balance. The balance then applies up to the remaining due. A remaining due above 0 but below min_payment is carried to the next invoice instead of charged. Return [due, balance_after, carried].

split: open-access


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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = min(bal, due)
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due <= x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('normal control', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('normal control', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0])], [('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('regression (boundary)', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('partial-repair probe (boundary)', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0])], [('regression (boundary)', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('partial-repair probe (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('normal control', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0]), ('normal control', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('normal control', {'total': 27004, 'credit_notes': [11844, 8578], 'balance': 0, 'min_payment': 0}, [6582, 0, 0])], [('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe (boundary)', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 32368, 'credit_notes': [17289, 13095], 'balance': 0, 'min_payment': 0}, [1984, 0, 0]), ('normal control', {'total': 36798, 'credit_notes': [1788], 'balance': 11576, 'min_payment': 50}, [23434, 0, 0]), ('normal control', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0])], [('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 9414, 'credit_notes': [5208], 'balance': 5543, 'min_payment': 50}, [0, 1337, 0]), ('normal control', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('normal control', {'total': 18, 'credit_notes': [], 'balance': 23152, 'min_payment': 0}, [0, 23134, 0]), ('normal control', {'total': 34021, 'credit_notes': [12282], 'balance': 0, 'min_payment': 100}, [21739, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = min(bal, due)
    due -= use_bal
    bal -= use_bal
    carried = 0
    if 0 < due < x['min_payment'] and x['balance'] == 0:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression (boundary)', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('normal control', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('normal control', {'total': 136, 'credit_notes': [], 'balance': 13171, 'min_payment': 0}, [0, 13035, 0]), ('normal control', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0])], [('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('regression (boundary)', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('partial-repair probe (boundary)', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 16956, 'credit_notes': [7744], 'balance': 26482, 'min_payment': 0}, [0, 17270, 0])], [('regression (boundary)', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('partial-repair probe (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 43465, 'credit_notes': [15608, 701], 'balance': 0, 'min_payment': 100}, [27156, 0, 0]), ('normal control', {'total': 25597, 'credit_notes': [2793, 18362], 'balance': 0, 'min_payment': 0}, [4442, 0, 0]), ('normal control', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('normal control', {'total': 27004, 'credit_notes': [11844, 8578], 'balance': 0, 'min_payment': 0}, [6582, 0, 0])], [('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe (boundary)', {'total': 190, 'credit_notes': [], 'balance': 100, 'min_payment': 100}, [0, 0, 90]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 32368, 'credit_notes': [17289, 13095], 'balance': 0, 'min_payment': 0}, [1984, 0, 0]), ('normal control', {'total': 36798, 'credit_notes': [1788], 'balance': 11576, 'min_payment': 50}, [23434, 0, 0]), ('normal control', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0])], [('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('regression (boundary)', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe (boundary)', {'total': 75, 'credit_notes': [], 'balance': 30, 'min_payment': 50}, [0, 0, 45]), ('partial-repair probe (boundary)', {'total': 520, 'credit_notes': [300], 'balance': 199, 'min_payment': 50}, [0, 0, 21]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 9414, 'credit_notes': [5208], 'balance': 5543, 'min_payment': 50}, [0, 1337, 0]), ('normal control', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('normal control', {'total': 18, 'credit_notes': [], 'balance': 23152, 'min_payment': 0}, [0, 23134, 0]), ('normal control', {'total': 34021, 'credit_notes': [12282], 'balance': 0, 'min_payment': 100}, [21739, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Amounts exactly equal to the minimum payment are deferred.

Input {total, credit_notes, balance, min_payment}. Credit notes apply first, capped at the total; any excess credit-note value joins the customer balance. The balance then applies up to the remaining due. A remaining due above 0 but below min_payment is carried to the next invoice instead of charged. Return [due, balance_after, carried].

split: open-access


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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = min(bal, due)
    due -= use_bal
    bal -= use_cn
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [192, 0, 0]), ('normal control', {'total': 291, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [291, 0, 0]), ('normal control', {'total': 237, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [237, 0, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 10727, 'credit_notes': [13715], 'balance': 0, 'min_payment': 100}, [0, 2988, 0]), ('partial-repair probe', {'total': 211, 'credit_notes': [560, 8068, 6056], 'balance': 0, 'min_payment': 50}, [0, 14473, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 57, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [57, 0, 0]), ('normal control', {'total': 11, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 11]), ('normal control', {'total': 103, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [103, 0, 0]), ('normal control', {'total': 18761, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [18761, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    due = x['total']
    cn = sum(x['credit_notes'])
    use_cn = min(cn, due)
    due -= use_cn
    bal = x['balance'] + (cn - use_cn)
    use_bal = min(bal, due)
    due -= use_bal
    bal = x['balance'] - use_bal
    carried = 0
    if 0 < due < x['min_payment']:
        carried = due
        due = 0
    return [due, bal, carried]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'total': 53, 'credit_notes': [2302], 'balance': 0, 'min_payment': 50}, [0, 2249, 0]), ('regression (boundary)', {'total': 1050, 'credit_notes': [1000], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('partial-repair probe', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 294, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [294, 0, 0]), ('normal control', {'total': 36738, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [36738, 0, 0]), ('normal control', {'total': 2985, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [2985, 0, 0]), ('normal control', {'total': 79, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [79, 0, 0])], [('regression', {'total': 249, 'credit_notes': [6921, 1078, 7518], 'balance': 0, 'min_payment': 100}, [0, 15268, 0]), ('regression (boundary)', {'total': 80, 'credit_notes': [], 'balance': 10, 'min_payment': 100}, [0, 0, 70]), ('partial-repair probe', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('partial-repair probe', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [192, 0, 0]), ('normal control', {'total': 107, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [107, 0, 0]), ('normal control', {'total': 123, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [123, 0, 0]), ('normal control', {'total': 228, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [228, 0, 0])], [('regression', {'total': 299, 'credit_notes': [19966], 'balance': 0, 'min_payment': 0}, [0, 19667, 0]), ('regression (boundary)', {'total': 130, 'credit_notes': [], 'balance': 50, 'min_payment': 100}, [0, 0, 80]), ('partial-repair probe', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('partial-repair probe', {'total': 46, 'credit_notes': [8883, 761], 'balance': 0, 'min_payment': 50}, [0, 9598, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('normal control', {'total': 288, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [288, 0, 0]), ('normal control', {'total': 38150, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [38150, 0, 0]), ('normal control', {'total': 165, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [165, 0, 0]), ('normal control', {'total': 141, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [141, 0, 0])], [('regression', {'total': 7761, 'credit_notes': [6395, 18359, 7009], 'balance': 11062, 'min_payment': 100}, [0, 35064, 0]), ('regression (boundary)', {'total': 1200, 'credit_notes': [1100], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 14659, 'credit_notes': [16457, 12670], 'balance': 0, 'min_payment': 50}, [0, 14468, 0]), ('partial-repair probe', {'total': 62, 'credit_notes': [3609], 'balance': 0, 'min_payment': 0}, [0, 3547, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('boundary control', {'total': 40, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 40]), ('normal control', {'total': 42819, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [42819, 0, 0]), ('normal control', {'total': 192, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [192, 0, 0]), ('normal control', {'total': 291, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [291, 0, 0]), ('normal control', {'total': 237, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [237, 0, 0])], [('regression', {'total': 164, 'credit_notes': [3853, 15350, 168], 'balance': 6958, 'min_payment': 100}, [0, 26165, 0]), ('regression (boundary)', {'total': 160, 'credit_notes': [], 'balance': 60, 'min_payment': 100}, [100, 0, 0]), ('partial-repair probe', {'total': 10727, 'credit_notes': [13715], 'balance': 0, 'min_payment': 100}, [0, 2988, 0]), ('partial-repair probe', {'total': 211, 'credit_notes': [560, 8068, 6056], 'balance': 0, 'min_payment': 50}, [0, 14473, 0]), ('boundary control', {'total': 100, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [100, 0, 0]), ('boundary control', {'total': 50, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [50, 0, 0]), ('normal control', {'total': 57, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [57, 0, 0]), ('normal control', {'total': 11, 'credit_notes': [], 'balance': 0, 'min_payment': 50}, [0, 0, 11]), ('normal control', {'total': 103, 'credit_notes': [], 'balance': 0, 'min_payment': 0}, [103, 0, 0]), ('normal control', {'total': 18761, 'credit_notes': [], 'balance': 0, 'min_payment': 100}, [18761, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Customer balances after invoicing are wrong whenever credit notes were applied.

Input {total, credit_notes, balance, min_payment}. Credit notes apply first, capped at the total; any excess credit-note value joins the customer balance. The balance then applies up to the remaining due. A remaining due above 0 but below min_payment is carried to the next invoice instead of charged. Return [due, balance_after, carried].

split: open-access


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

N = 1
observations = []
def solve(x):
    status = 'active'
    fails = 0
    nxt = None
    for day, kind in sorted(x['events'], key=lambda e: e[0]):
        if day > x['today']:
            break
        if status in ('canceled', 'unpaid'):
            break
        if kind == 'pay':
            status = 'active'; nxt = None; break
        fails += 1
        if fails >= len(x['retry']):
            status = x['final']; nxt = None
        else:
            status = 'past_due'; nxt = x['due'] + x['retry'][fails - 1]
    return [status, nxt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[19, 'fail'], [32, 'fail'], [37, 'fail'], [29, 'fail'], [33, 'pay'], [42, 'fail']], 'due': 19, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 34}, ['active', None]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[18, 'pay'], [16, 'fail'], [28, 'fail'], [22, 'fail']], 'due': 7, 'retry': [1, 3], 'final': 'unpaid', 'today': 37}, ['active', None]), ('partial-repair probe', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('normal control', {'events': [], 'due': 2, 'retry': [5], 'final': 'unpaid', 'today': 4}, ['active', None]), ('normal control', {'events': [[21, 'fail'], [8, 'fail'], [4, 'fail'], [23, 'fail']], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 15}, ['past_due', 5]), ('normal control', {'events': [[18, 'fail'], [12, 'fail'], [21, 'fail'], [19, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 23}, ['unpaid', None]), ('normal control', {'events': [[24, 'pay'], [14, 'fail'], [13, 'pay'], [21, 'pay'], [16, 'fail'], [6, 'fail']], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 35}, ['active', None])], [('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[30, 'pay'], [23, 'pay'], [19, 'fail']], 'due': 6, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 21}, ['past_due', 9]), ('partial-repair probe', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('normal control', {'events': [], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 24}, ['active', None]), ('normal control', {'events': [[15, 'pay'], [8, 'pay'], [23, 'fail'], [23, 'fail']], 'due': 2, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 9}, ['active', None]), ('normal control', {'events': [[5, 'pay']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 18}, ['active', None]), ('normal control', {'events': [[17, 'fail'], [31, 'pay']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 16}, ['active', None])], [('regression', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('regression', {'events': [[21, 'fail'], [22, 'pay'], [30, 'fail'], [27, 'fail']], 'due': 16, 'retry': [5], 'final': 'canceled', 'today': 32}, ['active', None]), ('partial-repair probe', {'events': [[32, 'fail']], 'due': 20, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 23]), ('partial-repair probe', {'events': [[34, 'fail'], [29, 'fail'], [21, 'fail'], [38, 'fail'], [34, 'fail'], [33, 'fail']], 'due': 16, 'retry': [1, 3], 'final': 'unpaid', 'today': 25}, ['past_due', 17]), ('normal control', {'events': [[5, 'pay'], [15, 'fail']], 'due': 0, 'retry': [1, 3], 'final': 'unpaid', 'today': 2}, ['active', None]), ('normal control', {'events': [[15, 'fail']], 'due': 1, 'retry': [1, 3], 'final': 'canceled', 'today': 14}, ['active', None]), ('normal control', {'events': [], 'due': 13, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 26}, ['active', None]), ('normal control', {'events': [[22, 'fail'], [10, 'pay'], [11, 'fail'], [25, 'fail'], [15, 'fail'], [16, 'fail']], 'due': 10, 'retry': [1, 3], 'final': 'unpaid', 'today': 39}, ['active', None])], [('regression', {'events': [[27, 'fail'], [36, 'fail']], 'due': 15, 'retry': [5], 'final': 'unpaid', 'today': 32}, ['past_due', 20]), ('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('partial-repair probe', {'events': [[34, 'fail'], [29, 'fail'], [21, 'fail'], [38, 'fail'], [34, 'fail'], [33, 'fail']], 'due': 16, 'retry': [1, 3], 'final': 'unpaid', 'today': 25}, ['past_due', 17]), ('partial-repair probe', {'events': [[28, 'fail'], [27, 'fail'], [40, 'fail']], 'due': 16, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 21]), ('normal control', {'events': [[28, 'fail']], 'due': 17, 'retry': [1, 3], 'final': 'unpaid', 'today': 21}, ['active', None]), ('normal control', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('normal control', {'events': [[27, 'pay'], [21, 'fail'], [28, 'fail'], [31, 'fail'], [19, 'pay'], [21, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 39}, ['active', None]), ('normal control', {'events': [], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 30}, ['active', None])], [('regression', {'events': [[20, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 20}, ['past_due', 8]), ('regression', {'events': [[16, 'fail'], [19, 'pay'], [40, 'fail'], [35, 'pay']], 'due': 16, 'retry': [5], 'final': 'unpaid', 'today': 21}, ['active', None]), ('partial-repair probe', {'events': [[27, 'fail'], [36, 'fail']], 'due': 15, 'retry': [5], 'final': 'unpaid', 'today': 32}, ['past_due', 20]), ('partial-repair probe', {'events': [[22, 'fail'], [33, 'fail'], [32, 'fail'], [29, 'fail'], [18, 'fail'], [21, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 19}, ['past_due', 13]), ('normal control', {'events': [[8, 'fail'], [9, 'fail'], [33, 'pay']], 'due': 8, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 8}, ['past_due', 11]), ('normal control', {'events': [[33, 'pay'], [13, 'fail']], 'due': 12, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 22}, ['past_due', 15]), ('normal control', {'events': [[20, 'fail'], [17, 'fail'], [24, 'pay'], [6, 'pay'], [7, 'fail'], [27, 'fail']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 16}, ['active', None]), ('normal control', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12])]]
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):
    status = 'active'
    fails = 0
    nxt = None
    for day, kind in sorted(x['events'], key=lambda e: e[0]):
        if day > x['today']:
            break
        if status in ('canceled', 'unpaid'):
            break
        if kind == 'pay':
            status = 'active'; nxt = None; break
        fails += 1
        if fails > len(x['retry']) or day > x['due'] + x['retry'][-1]:
            status = x['final']; nxt = None
        else:
            status = 'past_due'; nxt = x['due'] + x['retry'][fails - 1]
    return [status, nxt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[19, 'fail'], [32, 'fail'], [37, 'fail'], [29, 'fail'], [33, 'pay'], [42, 'fail']], 'due': 19, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 34}, ['active', None]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[18, 'pay'], [16, 'fail'], [28, 'fail'], [22, 'fail']], 'due': 7, 'retry': [1, 3], 'final': 'unpaid', 'today': 37}, ['active', None]), ('partial-repair probe', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('normal control', {'events': [], 'due': 2, 'retry': [5], 'final': 'unpaid', 'today': 4}, ['active', None]), ('normal control', {'events': [[21, 'fail'], [8, 'fail'], [4, 'fail'], [23, 'fail']], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 15}, ['past_due', 5]), ('normal control', {'events': [[18, 'fail'], [12, 'fail'], [21, 'fail'], [19, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 23}, ['unpaid', None]), ('normal control', {'events': [[24, 'pay'], [14, 'fail'], [13, 'pay'], [21, 'pay'], [16, 'fail'], [6, 'fail']], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 35}, ['active', None])], [('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[30, 'pay'], [23, 'pay'], [19, 'fail']], 'due': 6, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 21}, ['past_due', 9]), ('partial-repair probe', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('normal control', {'events': [], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 24}, ['active', None]), ('normal control', {'events': [[15, 'pay'], [8, 'pay'], [23, 'fail'], [23, 'fail']], 'due': 2, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 9}, ['active', None]), ('normal control', {'events': [[5, 'pay']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 18}, ['active', None]), ('normal control', {'events': [[17, 'fail'], [31, 'pay']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 16}, ['active', None])], [('regression', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('regression', {'events': [[21, 'fail'], [22, 'pay'], [30, 'fail'], [27, 'fail']], 'due': 16, 'retry': [5], 'final': 'canceled', 'today': 32}, ['active', None]), ('partial-repair probe', {'events': [[32, 'fail']], 'due': 20, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 23]), ('partial-repair probe', {'events': [[34, 'fail'], [29, 'fail'], [21, 'fail'], [38, 'fail'], [34, 'fail'], [33, 'fail']], 'due': 16, 'retry': [1, 3], 'final': 'unpaid', 'today': 25}, ['past_due', 17]), ('normal control', {'events': [[5, 'pay'], [15, 'fail']], 'due': 0, 'retry': [1, 3], 'final': 'unpaid', 'today': 2}, ['active', None]), ('normal control', {'events': [[15, 'fail']], 'due': 1, 'retry': [1, 3], 'final': 'canceled', 'today': 14}, ['active', None]), ('normal control', {'events': [], 'due': 13, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 26}, ['active', None]), ('normal control', {'events': [[22, 'fail'], [10, 'pay'], [11, 'fail'], [25, 'fail'], [15, 'fail'], [16, 'fail']], 'due': 10, 'retry': [1, 3], 'final': 'unpaid', 'today': 39}, ['active', None])], [('regression', {'events': [[27, 'fail'], [36, 'fail']], 'due': 15, 'retry': [5], 'final': 'unpaid', 'today': 32}, ['past_due', 20]), ('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('partial-repair probe', {'events': [[34, 'fail'], [29, 'fail'], [21, 'fail'], [38, 'fail'], [34, 'fail'], [33, 'fail']], 'due': 16, 'retry': [1, 3], 'final': 'unpaid', 'today': 25}, ['past_due', 17]), ('partial-repair probe', {'events': [[28, 'fail'], [27, 'fail'], [40, 'fail']], 'due': 16, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 21]), ('normal control', {'events': [[28, 'fail']], 'due': 17, 'retry': [1, 3], 'final': 'unpaid', 'today': 21}, ['active', None]), ('normal control', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('normal control', {'events': [[27, 'pay'], [21, 'fail'], [28, 'fail'], [31, 'fail'], [19, 'pay'], [21, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 39}, ['active', None]), ('normal control', {'events': [], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 30}, ['active', None])], [('regression', {'events': [[20, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 20}, ['past_due', 8]), ('regression', {'events': [[16, 'fail'], [19, 'pay'], [40, 'fail'], [35, 'pay']], 'due': 16, 'retry': [5], 'final': 'unpaid', 'today': 21}, ['active', None]), ('partial-repair probe', {'events': [[27, 'fail'], [36, 'fail']], 'due': 15, 'retry': [5], 'final': 'unpaid', 'today': 32}, ['past_due', 20]), ('partial-repair probe', {'events': [[22, 'fail'], [33, 'fail'], [32, 'fail'], [29, 'fail'], [18, 'fail'], [21, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 19}, ['past_due', 13]), ('normal control', {'events': [[8, 'fail'], [9, 'fail'], [33, 'pay']], 'due': 8, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 8}, ['past_due', 11]), ('normal control', {'events': [[33, 'pay'], [13, 'fail']], 'due': 12, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 22}, ['past_due', 15]), ('normal control', {'events': [[20, 'fail'], [17, 'fail'], [24, 'pay'], [6, 'pay'], [7, 'fail'], [27, 'fail']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 16}, ['active', None]), ('normal control', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12])]]
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:
Subscriptions are canceled before the last scheduled retry runs.

Input {events: [[day, fail|pay]], due, retry: offsets from due for retries, final canceled|unpaid, today}. Events up to today are processed by day (stable). Payment settles: status active, no retry, stop. Each failure increments a counter; after more failures than scheduled retries the status becomes final and processing stops; otherwise past_due with next retry at due + retry[failures-1]. Return [status, next_retry].

split: open-access


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

N = 1
observations = []
def solve(x):
    status = 'active'
    fails = 0
    nxt = None
    for day, kind in sorted(x['events'], key=lambda e: e[0]):
        if day > x['today']:
            break
        if status in ('canceled', 'unpaid'):
            break
        if kind == 'pay':
            status = 'active'; nxt = None; break
        fails += 1
        if fails > len(x['retry']):
            status = x['final']; nxt = None
        else:
            status = 'past_due'; nxt = day + x['retry'][fails - 1]
    return [status, nxt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[21, 'fail'], [8, 'fail'], [4, 'fail'], [23, 'fail']], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 15}, ['past_due', 5]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('partial-repair probe', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('normal control', {'events': [], 'due': 2, 'retry': [5], 'final': 'unpaid', 'today': 4}, ['active', None]), ('normal control', {'events': [[19, 'fail'], [32, 'fail'], [37, 'fail'], [29, 'fail'], [33, 'pay'], [42, 'fail']], 'due': 19, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 34}, ['active', None]), ('normal control', {'events': [[18, 'fail'], [12, 'fail'], [21, 'fail'], [19, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 23}, ['unpaid', None]), ('normal control', {'events': [[24, 'pay'], [14, 'fail'], [13, 'pay'], [21, 'pay'], [16, 'fail'], [6, 'fail']], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 35}, ['active', None])], [('regression', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('partial-repair probe', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('normal control', {'events': [], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 24}, ['active', None]), ('normal control', {'events': [[15, 'pay'], [8, 'pay'], [23, 'fail'], [23, 'fail']], 'due': 2, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 9}, ['active', None]), ('normal control', {'events': [[5, 'pay']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 18}, ['active', None]), ('normal control', {'events': [[17, 'fail'], [31, 'pay']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 16}, ['active', None])], [('regression', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('regression', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('partial-repair probe', {'events': [[20, 'fail'], [31, 'fail'], [11, 'fail']], 'due': 10, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 24}, ['past_due', 14]), ('partial-repair probe', {'events': [[16, 'fail'], [13, 'fail']], 'due': 0, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 23}, ['past_due', 4]), ('normal control', {'events': [[5, 'pay'], [15, 'fail']], 'due': 0, 'retry': [1, 3], 'final': 'unpaid', 'today': 2}, ['active', None]), ('normal control', {'events': [[15, 'fail']], 'due': 1, 'retry': [1, 3], 'final': 'canceled', 'today': 14}, ['active', None]), ('normal control', {'events': [], 'due': 13, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 26}, ['active', None]), ('normal control', {'events': [[22, 'fail'], [10, 'pay'], [11, 'fail'], [25, 'fail'], [15, 'fail'], [16, 'fail']], 'due': 10, 'retry': [1, 3], 'final': 'unpaid', 'today': 39}, ['active', None])], [('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('regression', {'events': [[33, 'pay'], [13, 'fail']], 'due': 12, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 22}, ['past_due', 15]), ('partial-repair probe', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('partial-repair probe', {'events': [[28, 'fail'], [27, 'fail'], [40, 'fail']], 'due': 16, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 21]), ('normal control', {'events': [[21, 'fail'], [22, 'pay'], [30, 'fail'], [27, 'fail']], 'due': 16, 'retry': [5], 'final': 'canceled', 'today': 32}, ['active', None]), ('normal control', {'events': [[28, 'fail']], 'due': 17, 'retry': [1, 3], 'final': 'unpaid', 'today': 21}, ['active', None]), ('normal control', {'events': [[27, 'pay'], [21, 'fail'], [28, 'fail'], [31, 'fail'], [19, 'pay'], [21, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 39}, ['active', None]), ('normal control', {'events': [], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 30}, ['active', None])], [('regression', {'events': [[20, 'fail'], [31, 'fail'], [11, 'fail']], 'due': 10, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 24}, ['past_due', 14]), ('regression', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('partial-repair probe', {'events': [[24, 'fail'], [30, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 38}, ['past_due', 19]), ('partial-repair probe', {'events': [[34, 'fail'], [14, 'fail']], 'due': 11, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 35}, ['past_due', 16]), ('normal control', {'events': [[8, 'fail'], [9, 'fail'], [33, 'pay']], 'due': 8, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 8}, ['past_due', 11]), ('normal control', {'events': [[20, 'fail'], [17, 'fail'], [24, 'pay'], [6, 'pay'], [7, 'fail'], [27, 'fail']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 16}, ['active', None]), ('normal control', {'events': [[18, 'pay'], [16, 'fail'], [28, 'fail'], [22, 'fail']], 'due': 7, 'retry': [1, 3], 'final': 'unpaid', 'today': 37}, ['active', None]), ('normal control', {'events': [[21, 'fail'], [30, 'fail'], [22, 'fail']], 'due': 15, 'retry': [5], 'final': 'canceled', 'today': 37}, ['canceled', None])]]
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):
    status = 'active'
    fails = 0
    nxt = None
    for day, kind in sorted(x['events'], key=lambda e: e[0]):
        if day > x['today']:
            break
        if status in ('canceled', 'unpaid'):
            break
        if kind == 'pay':
            status = 'active'; nxt = None; break
        fails += 1
        if fails > len(x['retry']):
            status = x['final']; nxt = None
        else:
            status = 'past_due'; nxt = x['due'] + sum(x['retry'][:fails])
    return [status, nxt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'events': [[21, 'fail'], [8, 'fail'], [4, 'fail'], [23, 'fail']], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 15}, ['past_due', 5]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('partial-repair probe', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('normal control', {'events': [], 'due': 2, 'retry': [5], 'final': 'unpaid', 'today': 4}, ['active', None]), ('normal control', {'events': [[19, 'fail'], [32, 'fail'], [37, 'fail'], [29, 'fail'], [33, 'pay'], [42, 'fail']], 'due': 19, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 34}, ['active', None]), ('normal control', {'events': [[18, 'fail'], [12, 'fail'], [21, 'fail'], [19, 'fail']], 'due': 10, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 23}, ['unpaid', None]), ('normal control', {'events': [[24, 'pay'], [14, 'fail'], [13, 'pay'], [21, 'pay'], [16, 'fail'], [6, 'fail']], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 35}, ['active', None])], [('regression', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('regression', {'events': [[4, 'fail'], [11, 'fail']], 'due': 3, 'retry': [5], 'final': 'canceled', 'today': 8}, ['past_due', 8]), ('partial-repair probe', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('partial-repair probe', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('normal control', {'events': [], 'due': 5, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 24}, ['active', None]), ('normal control', {'events': [[15, 'pay'], [8, 'pay'], [23, 'fail'], [23, 'fail']], 'due': 2, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 9}, ['active', None]), ('normal control', {'events': [[5, 'pay']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 18}, ['active', None]), ('normal control', {'events': [[17, 'fail'], [31, 'pay']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 16}, ['active', None])], [('regression', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('regression', {'events': [[25, 'fail'], [22, 'fail']], 'due': 19, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 41}, ['past_due', 23]), ('partial-repair probe', {'events': [[20, 'fail'], [31, 'fail'], [11, 'fail']], 'due': 10, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 24}, ['past_due', 14]), ('partial-repair probe', {'events': [[16, 'fail'], [13, 'fail']], 'due': 0, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 23}, ['past_due', 4]), ('normal control', {'events': [[5, 'pay'], [15, 'fail']], 'due': 0, 'retry': [1, 3], 'final': 'unpaid', 'today': 2}, ['active', None]), ('normal control', {'events': [[15, 'fail']], 'due': 1, 'retry': [1, 3], 'final': 'canceled', 'today': 14}, ['active', None]), ('normal control', {'events': [], 'due': 13, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 26}, ['active', None]), ('normal control', {'events': [[22, 'fail'], [10, 'pay'], [11, 'fail'], [25, 'fail'], [15, 'fail'], [16, 'fail']], 'due': 10, 'retry': [1, 3], 'final': 'unpaid', 'today': 39}, ['active', None])], [('regression', {'events': [[25, 'fail'], [23, 'fail']], 'due': 2, 'retry': [1, 3], 'final': 'unpaid', 'today': 28}, ['past_due', 5]), ('regression', {'events': [[33, 'pay'], [13, 'fail']], 'due': 12, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 22}, ['past_due', 15]), ('partial-repair probe', {'events': [[28, 'fail'], [26, 'fail']], 'due': 13, 'retry': [1, 3], 'final': 'canceled', 'today': 38}, ['past_due', 16]), ('partial-repair probe', {'events': [[28, 'fail'], [27, 'fail'], [40, 'fail']], 'due': 16, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 33}, ['past_due', 21]), ('normal control', {'events': [[21, 'fail'], [22, 'pay'], [30, 'fail'], [27, 'fail']], 'due': 16, 'retry': [5], 'final': 'canceled', 'today': 32}, ['active', None]), ('normal control', {'events': [[28, 'fail']], 'due': 17, 'retry': [1, 3], 'final': 'unpaid', 'today': 21}, ['active', None]), ('normal control', {'events': [[27, 'pay'], [21, 'fail'], [28, 'fail'], [31, 'fail'], [19, 'pay'], [21, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 39}, ['active', None]), ('normal control', {'events': [], 'due': 1, 'retry': [2, 4, 8, 16], 'final': 'canceled', 'today': 30}, ['active', None])], [('regression', {'events': [[20, 'fail'], [31, 'fail'], [11, 'fail']], 'due': 10, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 24}, ['past_due', 14]), ('regression', {'events': [[15, 'fail'], [21, 'fail']], 'due': 8, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 31}, ['past_due', 12]), ('partial-repair probe', {'events': [[24, 'fail'], [30, 'fail']], 'due': 15, 'retry': [2, 4, 8, 16], 'final': 'unpaid', 'today': 38}, ['past_due', 19]), ('partial-repair probe', {'events': [[34, 'fail'], [14, 'fail']], 'due': 11, 'retry': [3, 5, 7], 'final': 'canceled', 'today': 35}, ['past_due', 16]), ('normal control', {'events': [[8, 'fail'], [9, 'fail'], [33, 'pay']], 'due': 8, 'retry': [3, 5, 7], 'final': 'unpaid', 'today': 8}, ['past_due', 11]), ('normal control', {'events': [[20, 'fail'], [17, 'fail'], [24, 'pay'], [6, 'pay'], [7, 'fail'], [27, 'fail']], 'due': 3, 'retry': [1, 3], 'final': 'canceled', 'today': 16}, ['active', None]), ('normal control', {'events': [[18, 'pay'], [16, 'fail'], [28, 'fail'], [22, 'fail']], 'due': 7, 'retry': [1, 3], 'final': 'unpaid', 'today': 37}, ['active', None]), ('normal control', {'events': [[21, 'fail'], [30, 'fail'], [22, 'fail']], 'due': 15, 'retry': [5], 'final': 'canceled', 'today': 37}, ['canceled', None])]]
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:
Retries drift later with every failure.

Input {events: [[day, fail|pay]], due, retry: offsets from due for retries, final canceled|unpaid, today}. Events up to today are processed by day (stable). Payment settles: status active, no retry, stop. Each failure increments a counter; after more failures than scheduled retries the status becomes final and processing stops; otherwise past_due with next retry at due + retry[failures-1]. Return [status, next_retry].

split: open-access