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

N = 1
observations = []
def solve(x):
    acts = [a for a in x['activity'] if a[0] <= x['today']]
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = x['today']
    inactive = x['today'] - ref > x['window']
    if inactive and bal > 0:
        return {'expired': bal, 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[801, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 801}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[802, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 802}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[803, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 803}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[804, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 804}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[805, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 805}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    acts = [a for a in x['activity'] if a[0] <= x['today']]
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = 0
    inactive = x['today'] - ref > x['window']
    if inactive and bal > 0:
        return {'expired': bal, 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[801, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 801}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[802, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 802}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[803, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 803}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[804, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 804}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['recent adjust only', {'activity': [[805, 'adjust', 30]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 30, 'last_activity': 805}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Accounts that never earned or redeemed keep their adjustment points forever.

Input {activity:[[day,kind,signed pts]], today, window}. Only activity dated <= today counts. Qualifying kinds are earn, redeem and transfer_out; the reference day is the latest qualifying day, or the earliest activity day if none qualifies (today if no activity). The account is inactive when today - reference > window; an inactive account with a positive balance forfeits it all. Return {expired, balance, last_activity}.

split: open-access


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

N = 1
observations = []
def solve(x):
    acts = [a for a in x['activity'] if a[0] <= x['today']]
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = min([d for d, k, p in acts] or [x['today']])
    inactive = x['today'] - ref > x['window']
    if inactive and bal != 0:
        return {'expired': bal, 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    acts = [a for a in x['activity'] if a[0] <= x['today']]
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = min([d for d, k, p in acts] or [x['today']])
    inactive = x['today'] - ref > x['window']
    if inactive:
        return {'expired': max(bal, 0), 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Inactive accounts in debt report a negative expiry and have their debt wiped.

Input {activity:[[day,kind,signed pts]], today, window}. Only activity dated <= today counts. Qualifying kinds are earn, redeem and transfer_out; the reference day is the latest qualifying day, or the earliest activity day if none qualifies (today if no activity). The account is inactive when today - reference > window; an inactive account with a positive balance forfeits it all. Return {expired, balance, last_activity}.

split: open-access


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

N = 1
observations = []
def solve(x):
    acts = list(x['activity'])
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = min([d for d, k, p in acts] or [x['today']])
    inactive = x['today'] - ref > x['window']
    if inactive and bal > 0:
        return {'expired': bal, 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [701, 'earn', 5]], 'today': 701, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 701}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [702, 'earn', 5]], 'today': 702, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 702}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [703, 'earn', 5]], 'today': 703, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 703}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [704, 'earn', 5]], 'today': 704, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 704}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [705, 'earn', 5]], 'today': 705, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 705}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    acts = [a for a in x['activity'] if a[0] < x['today']]
    qual = [d for d, k, p in acts if k in ('earn', 'redeem', 'transfer_out')]
    bal = sum(p for d, k, p in acts)
    if qual:
        ref = max(qual)
    else:
        ref = min([d for d, k, p in acts] or [x['today']])
    inactive = x['today'] - ref > x['window']
    if inactive and bal > 0:
        return {'expired': bal, 'balance': 0, 'last_activity': ref}
    return {'expired': 0, 'balance': bal, 'last_activity': ref}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 51]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 351, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 301]], 'today': 700, 'window': 540}, {'expired': 801, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 101]], 'today': 600, 'window': 540}, {'expired': 501, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 251]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 251, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -101]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 799, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 101]], 'today': 600, 'window': 540}, {'expired': 101, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -151]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -51, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 71]], 'today': 950, 'window': 540}, {'expired': 76, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 21]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [701, 'earn', 5]], 'today': 701, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 701}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 52]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 352, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 302]], 'today': 700, 'window': 540}, {'expired': 802, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 102]], 'today': 600, 'window': 540}, {'expired': 502, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 252]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 252, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -102]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 798, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 102]], 'today': 600, 'window': 540}, {'expired': 102, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -152]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -52, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 72]], 'today': 950, 'window': 540}, {'expired': 77, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 22]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [702, 'earn', 5]], 'today': 702, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 702}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 53]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 353, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 303]], 'today': 700, 'window': 540}, {'expired': 803, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 103]], 'today': 600, 'window': 540}, {'expired': 503, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 253]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 253, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -103]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 797, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 103]], 'today': 600, 'window': 540}, {'expired': 103, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -153]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -53, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 73]], 'today': 950, 'window': 540}, {'expired': 78, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 23]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [703, 'earn', 5]], 'today': 703, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 703}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 54]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 354, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 304]], 'today': 700, 'window': 540}, {'expired': 804, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 104]], 'today': 600, 'window': 540}, {'expired': 504, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 254]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 254, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -104]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 796, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 104]], 'today': 600, 'window': 540}, {'expired': 104, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -154]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -54, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 74]], 'today': 950, 'window': 540}, {'expired': 79, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 24]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [704, 'earn', 5]], 'today': 704, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 704}]], [['active member', {'activity': [[10, 'earn', 500], [200, 'redeem', -200], [500, 'earn', 55]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': 355, 'last_activity': 500}], ['inactive', {'activity': [[10, 'earn', 500], [100, 'earn', 305]], 'today': 700, 'window': 540}, {'expired': 805, 'balance': 0, 'last_activity': 100}], ['bonus does not count', {'activity': [[0, 'earn', 400], [500, 'bonus_credit', 105]], 'today': 600, 'window': 540}, {'expired': 505, 'balance': 0, 'last_activity': 0}], ['window edge', {'activity': [[60, 'earn', 255]], 'today': 600, 'window': 540}, {'expired': 0, 'balance': 255, 'last_activity': 60}], ['transfer out counts', {'activity': [[0, 'earn', 900], [300, 'transfer_out', -105]], 'today': 800, 'window': 540}, {'expired': 0, 'balance': 795, 'last_activity': 300}], ['never qualified', {'activity': [[5, 'adjust', 105]], 'today': 600, 'window': 540}, {'expired': 105, 'balance': 0, 'last_activity': 5}], ['negative balance', {'activity': [[0, 'earn', 100], [10, 'adjust', -155]], 'today': 900, 'window': 540}, {'expired': 0, 'balance': -55, 'last_activity': 0}], ['unsorted list', {'activity': [[400, 'earn', 10], [20, 'redeem', -5], [30, 'earn', 75]], 'today': 950, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 400}], ['future dated', {'activity': [[10, 'earn', 80], [1000, 'earn', 25]], 'today': 900, 'window': 540}, {'expired': 80, 'balance': 0, 'last_activity': 10}], ['activity today', {'activity': [[0, 'earn', 50], [705, 'earn', 5]], 'today': 705, 'window': 540}, {'expired': 0, 'balance': 55, 'last_activity': 705}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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 pre-scheduled future earn keeps an inactive account from expiring.

Input {activity:[[day,kind,signed pts]], today, window}. Only activity dated <= today counts. Qualifying kinds are earn, redeem and transfer_out; the reference day is the latest qualifying day, or the earliest activity day if none qualifies (today if no activity). The account is inactive when today - reference > window; an inactive account with a positive balance forfeits it all. Return {expired, balance, last_activity}.

split: open-access


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

N = 1
observations = []
def solve(x):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] * x['breakage_bp'] // 10000
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = min(x['redeemed'], expected)
    recognized = deferred * used // expected
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] - x['breakage_bp']
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = min(x['redeemed'], expected)
    recognized = deferred * used // expected
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Revenue is recognized far too fast because expected redemptions are computed from the breakage rate itself.

Input {issued, redeemed, value_mc (millicents per point), breakage_bp}. Deferred revenue = floor(issued*value_mc/1000) cents. Expected redemptions = floor(issued*(10000-breakage_bp)/10000); if zero return {"error"}. Recognized = floor(deferred*min(redeemed, expected)/expected); liability = deferred - recognized. Return {deferred, expected, recognized, liability}.

split: open-access


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

N = 1
observations = []
def solve(x):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] * (10000 - x['breakage_bp']) // 10000
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = x['redeemed']
    recognized = deferred * used // expected
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] * (10000 - x['breakage_bp']) // 10000
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = min(x['redeemed'], x['issued'])
    recognized = deferred * used // expected
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Redemptions beyond the expected level recognize more revenue than was deferred and the liability turns negative.

Input {issued, redeemed, value_mc (millicents per point), breakage_bp}. Deferred revenue = floor(issued*value_mc/1000) cents. Expected redemptions = floor(issued*(10000-breakage_bp)/10000); if zero return {"error"}. Recognized = floor(deferred*min(redeemed, expected)/expected); liability = deferred - recognized. Return {deferred, expected, recognized, liability}.

split: open-access


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

N = 1
observations = []
def solve(x):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] * (10000 - x['breakage_bp']) // 10000
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = min(x['redeemed'], expected)
    recognized = used * x['value_mc'] // 1000
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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):
    deferred = x['issued'] * x['value_mc'] // 1000
    expected = x['issued'] * (10000 - x['breakage_bp']) // 10000
    if expected <= 0:
        return {'error': 'no expected redemptions'}
    used = min(x['redeemed'], expected)
    recognized = used * x['value_mc'] * (10000 + x['breakage_bp']) // 10000000
    return {'deferred': deferred, 'expected': expected, 'recognized': recognized, 'liability': deferred - recognized}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['mid program', {'issued': 100000, 'redeemed': 30001, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37501, 'liability': 62499}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1001}, {'deferred': 40000, 'expected': 44995, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1112, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1112, 'liability': 1387}], ['no breakage', {'issued': 700, 'redeemed': 351, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 351, 'liability': 349}], ['all breakage', {'issued': 700, 'redeemed': 1, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 4, 'breakage_bp': 3000}, {'deferred': 399, 'expected': 69999, 'recognized': 70, 'liability': 329}]], [['mid program', {'issued': 100000, 'redeemed': 30002, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37502, 'liability': 62498}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1002}, {'deferred': 40000, 'expected': 44990, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1113, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1113, 'liability': 1386}], ['no breakage', {'issued': 700, 'redeemed': 352, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 352, 'liability': 348}], ['all breakage', {'issued': 700, 'redeemed': 2, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 5, 'breakage_bp': 3000}, {'deferred': 499, 'expected': 69999, 'recognized': 88, 'liability': 411}]], [['mid program', {'issued': 100000, 'redeemed': 30003, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37503, 'liability': 62497}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1003}, {'deferred': 40000, 'expected': 44985, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1114, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1114, 'liability': 1385}], ['no breakage', {'issued': 700, 'redeemed': 353, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 353, 'liability': 347}], ['all breakage', {'issued': 700, 'redeemed': 3, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 6, 'breakage_bp': 3000}, {'deferred': 599, 'expected': 69999, 'recognized': 105, 'liability': 494}]], [['mid program', {'issued': 100000, 'redeemed': 30004, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37505, 'liability': 62495}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1004}, {'deferred': 40000, 'expected': 44980, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1115, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1115, 'liability': 1384}], ['no breakage', {'issued': 700, 'redeemed': 354, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 354, 'liability': 346}], ['all breakage', {'issued': 700, 'redeemed': 4, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 7, 'breakage_bp': 3000}, {'deferred': 699, 'expected': 69999, 'recognized': 123, 'liability': 576}]], [['mid program', {'issued': 100000, 'redeemed': 30005, 'value_mc': 1000, 'breakage_bp': 2000}, {'deferred': 100000, 'expected': 80000, 'recognized': 37506, 'liability': 62494}], ['fully redeemed', {'issued': 50000, 'redeemed': 45000, 'value_mc': 800, 'breakage_bp': 1005}, {'deferred': 40000, 'expected': 44975, 'recognized': 40000, 'liability': 0}], ['over redeemed', {'issued': 1000, 'redeemed': 950, 'value_mc': 1200, 'breakage_bp': 1500}, {'deferred': 1200, 'expected': 850, 'recognized': 1200, 'liability': 0}], ['fractional value', {'issued': 3333, 'redeemed': 1116, 'value_mc': 750, 'breakage_bp': 2500}, {'deferred': 2499, 'expected': 2499, 'recognized': 1116, 'liability': 1383}], ['no breakage', {'issued': 700, 'redeemed': 355, 'value_mc': 1000, 'breakage_bp': 0}, {'deferred': 700, 'expected': 700, 'recognized': 355, 'liability': 345}], ['all breakage', {'issued': 700, 'redeemed': 5, 'value_mc': 1000, 'breakage_bp': 10000}, {'error': 'no expected redemptions'}], ['tiny value', {'issued': 99999, 'redeemed': 12345, 'value_mc': 8, 'breakage_bp': 3000}, {'deferred': 799, 'expected': 69999, 'recognized': 140, 'liability': 659}]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Revenue is recognized only at face value per redeemed point, ignoring expected breakage.

Input {issued, redeemed, value_mc (millicents per point), breakage_bp}. Deferred revenue = floor(issued*value_mc/1000) cents. Expected redemptions = floor(issued*(10000-breakage_bp)/10000); if zero return {"error"}. Recognized = floor(deferred*min(redeemed, expected)/expected); liability = deferred - recognized. Return {deferred, expected, recognized, liability}.

split: open-access