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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    rev = []
    for eid, day, kind, acct, amt in x['entries']:
        if kind == 'accrual' and day <= end:
            rev.append(['R-' + eid, end + 1, kind, acct, -amt])
    bal = {}
    for eid, day, kind, acct, amt in x['entries'] + rev:
        if day < x['as_of']:
            bal[acct] = bal.get(acct, 0) + amt
    return {'reversals': [[r[0], r[1], r[4]] for r in rev], 'balances': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', 250], ['E1', 27, 'regular', 'rent', 250], ['E2', 30, 'accrual', 'cash', -100], ['E3', 30, 'deferral', 'accrued_interest', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -250]], 'balances': {'rent': 250}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'accrued_wages', 250], ['E1', 32, 'regular', 'cash', 100], ['E2', 27, 'accrual', 'rent', 100], ['E3', 5, 'regular', 'accrued_wages', 100], ['E4', 31, 'regular', 'accrued_interest', -40], ['E5', 32, 'regular', 'cash', -40]], 'as_of': 30}, {'reversals': [['R-E2', 31, -100]], 'balances': {'rent': 100, 'accrued_wages': 100}}], ['control 2', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 700], ['E1', 5, 'deferral', 'accrued_interest', -100], ['E2', 5, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': -100, 'cash': -40}}], ['control 3', {'period_end': 30, 'entries': [['E0', 29, 'regular', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'accrued_interest', -100]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100], ['R-E2', 31, 100]], 'balances': {'rent': 700, 'accrued_interest': 0}}], ['control 4', {'period_end': 31, 'entries': [['E0', 5, 'deferral', 'accrued_interest', -40], ['E1', 28, 'deferral', 'accrued_wages', -100], ['E2', 33, 'deferral', 'cash', 100], ['E3', 5, 'accrual', 'accrued_interest', -40], ['E4', 5, 'accrual', 'accrued_interest', 250], ['E5', 31, 'accrual', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [['R-E3', 32, 40], ['R-E4', 32, -250], ['R-E5', 32, -100]], 'balances': {'accrued_interest': 170, 'accrued_wages': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', -40], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 30, 'accrual', 'accrued_wages', -100], ['E3', 30, 'deferral', 'cash', 100], ['E4', 30, 'accrual', 'cash', -100]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100], ['R-E2', 31, 100], ['R-E4', 31, 100]], 'balances': {'accrued_wages': -40, 'accrued_interest': 0, 'cash': 100}}], ['control 6', {'period_end': 30, 'entries': [['E0', 27, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'accrued_interest', 700], ['E2', 27, 'regular', 'accrued_interest', -100], ['E3', 30, 'deferral', 'cash', -40], ['E4', 30, 'deferral', 'rent', 100], ['E5', 30, 'accrual', 'accrued_wages', -40]], 'as_of': 29}, {'reversals': [['R-E0', 31, 40], ['R-E1', 31, -700], ['R-E5', 31, 40]], 'balances': {'rent': -40, 'accrued_interest': 600}}]], [['regression: as-of inclusivity', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_wages', 250], ['E1', 28, 'accrual', 'cash', 100], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 31, 'regular', 'cash', 100], ['E4', 5, 'accrual', 'cash', -40], ['E5', 31, 'accrual', 'accrued_interest', 250], ['E6', 33, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E2', 32, 40], ['R-E4', 32, 40], ['R-E5', 32, -250]], 'balances': {'accrued_wages': 250, 'cash': 100, 'accrued_interest': -100}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_wages', 100], ['E1', 29, 'regular', 'accrued_wages', 100], ['E2', 32, 'deferral', 'accrued_wages', 700], ['E3', 27, 'deferral', 'rent', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -40}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'accrued_interest', -40], ['E1', 30, 'accrual', 'accrued_interest', 250], ['E2', 29, 'regular', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 27, 'deferral', 'rent', 250], ['E5', 29, 'accrual', 'accrued_interest', -100], ['E6', 27, 'deferral', 'rent', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'accrued_interest': -40, 'rent': 950}}], ['control 3', {'period_end': 28, 'entries': [['E0', 25, 'regular', 'accrued_interest', 100], ['E1', 29, 'accrual', 'cash', 100], ['E2', 30, 'accrual', 'rent', 100], ['E3', 29, 'regular', 'cash', 700], ['E4', 25, 'accrual', 'rent', 700]], 'as_of': 28}, {'reversals': [['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'rent': 700}}], ['control 4', {'period_end': 28, 'entries': [['E0', 29, 'deferral', 'cash', -40], ['E1', 5, 'accrual', 'accrued_interest', -100], ['E2', 25, 'deferral', 'accrued_interest', 250], ['E3', 25, 'accrual', 'accrued_wages', 700], ['E4', 28, 'accrual', 'rent', -100]], 'as_of': 27}, {'reversals': [['R-E1', 29, 100], ['R-E3', 29, -700], ['R-E4', 29, 100]], 'balances': {'accrued_interest': 150, 'accrued_wages': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'rent', 100], ['E1', 29, 'deferral', 'accrued_interest', 700], ['E2', 25, 'regular', 'accrued_wages', -40], ['E3', 28, 'accrual', 'accrued_wages', -100], ['E4', 25, 'accrual', 'accrued_interest', 100], ['E5', 28, 'deferral', 'accrued_wages', 100], ['E6', 30, 'regular', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E3', 29, 100], ['R-E4', 29, -100]], 'balances': {'rent': 100, 'accrued_wages': -40, 'accrued_interest': 100}}], ['control 6', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'cash', 700], ['E1', 32, 'deferral', 'cash', -40], ['E2', 5, 'accrual', 'accrued_wages', -40]], 'as_of': 33}, {'reversals': [['R-E0', 32, -700], ['R-E2', 32, 40]], 'balances': {'cash': -40, 'accrued_wages': 0}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_interest', 250], ['E2', 28, 'accrual', 'rent', -40], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 5, 'accrual', 'accrued_wages', 700]], 'as_of': 27}, {'reversals': [['R-E2', 29, 40], ['R-E3', 29, -100], ['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'accrued_wages': 700}}], ['regression: as-of inclusivity, partial-repair probe', {'period_end': 30, 'entries': [['E0', 27, 'regular', 'cash', 250], ['E1', 29, 'regular', 'rent', 100], ['E2', 29, 'accrual', 'accrued_wages', 250], ['E3', 30, 'accrual', 'rent', 100], ['E4', 5, 'accrual', 'cash', 250], ['E5', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -250], ['R-E3', 31, -100], ['R-E4', 31, -250]], 'balances': {'cash': 500, 'rent': 100, 'accrued_wages': 150}}], ['control 1', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'rent', -40], ['E1', 30, 'accrual', 'accrued_wages', 250], ['E2', 30, 'deferral', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_interest', 100], ['E4', 32, 'regular', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 31, -250], ['R-E3', 31, -100]], 'balances': {'rent': -40, 'accrued_interest': 100}}], ['control 2', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}], ['control 3', {'period_end': 31, 'entries': [['E0', 28, 'accrual', 'accrued_interest', 100], ['E1', 31, 'deferral', 'cash', 250], ['E2', 30, 'regular', 'cash', -100]], 'as_of': 33}, {'reversals': [['R-E0', 32, -100]], 'balances': {'accrued_interest': 0, 'cash': 150}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'accrued_interest', -40], ['E1', 29, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'accrued_interest', -40], ['E3', 28, 'accrual', 'accrued_wages', -40], ['E4', 28, 'accrual', 'cash', 100], ['E5', 5, 'accrual', 'rent', 250]], 'as_of': 27}, {'reversals': [['R-E3', 29, 40], ['R-E4', 29, -100], ['R-E5', 29, -250]], 'balances': {'accrued_interest': -40, 'rent': 250}}], ['control 5', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'cash', -100], ['E1', 31, 'deferral', 'accrued_interest', 700], ['E2', 30, 'accrual', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, 100]], 'balances': {}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'cash', 250], ['E2', 28, 'regular', 'cash', 100]], 'as_of': 27}, {'reversals': [['R-E1', 29, -250]], 'balances': {'accrued_wages': 700}}], ['control 1', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'cash', -100], ['E2', 5, 'accrual', 'cash', 100], ['E3', 27, 'regular', 'accrued_interest', 700]], 'as_of': 30}, {'reversals': [['R-E0', 29, 40], ['R-E1', 29, 100], ['R-E2', 29, -100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_interest': 700}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 29, 'accrual', 'accrued_interest', 700], ['E2', 28, 'deferral', 'rent', 250], ['E3', 29, 'regular', 'accrued_interest', 250]], 'as_of': 30}, {'reversals': [['R-E0', 29, -100]], 'balances': {'cash': 0, 'accrued_interest': 950, 'rent': 250}}], ['control 3', {'period_end': 30, 'entries': [['E0', 30, 'regular', 'cash', -40], ['E1', 30, 'accrual', 'cash', 700], ['E2', 30, 'deferral', 'accrued_wages', 700]], 'as_of': 32}, {'reversals': [['R-E1', 31, -700]], 'balances': {'cash': -40, 'accrued_wages': 700}}], ['control 4', {'period_end': 28, 'entries': [['E0', 29, 'regular', 'cash', 100], ['E1', 25, 'accrual', 'cash', 250], ['E2', 27, 'deferral', 'rent', -100], ['E3', 28, 'regular', 'cash', 100], ['E4', 28, 'regular', 'rent', 250], ['E5', 28, 'regular', 'rent', -40], ['E6', 28, 'accrual', 'rent', 250]], 'as_of': 30}, {'reversals': [['R-E1', 29, -250], ['R-E6', 29, -250]], 'balances': {'cash': 200, 'rent': 110}}], ['control 5', {'period_end': 31, 'entries': [['E0', 28, 'regular', 'cash', 100], ['E1', 33, 'accrual', 'accrued_wages', 100], ['E2', 5, 'deferral', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 30, 'accrual', 'accrued_wages', 100]], 'as_of': 31}, {'reversals': [['R-E3', 32, -700], ['R-E4', 32, -100]], 'balances': {'cash': 1500, 'accrued_wages': 100}}], ['control 6', {'period_end': 30, 'entries': [['E0', 31, 'deferral', 'cash', 100], ['E1', 31, 'accrual', 'accrued_wages', 100], ['E2', 30, 'deferral', 'accrued_interest', -100], ['E3', 5, 'deferral', 'accrued_interest', 250]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 100, 'accrued_wages': 100, 'accrued_interest': 150}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'cash', -40], ['E1', 27, 'accrual', 'accrued_interest', 100], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100]], 'balances': {'cash': -40, 'accrued_interest': 0}}], ['control 1', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', -100], ['E2', 29, 'deferral', 'cash', 100], ['E3', 28, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'cash', -40], ['E5', 30, 'regular', 'cash', 250]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700]], 'balances': {}}], ['control 2', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'deferral', 'cash', -100], ['E2', 32, 'regular', 'cash', 700], ['E3', 32, 'accrual', 'rent', 100], ['E4', 31, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 3', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'accrual', 'rent', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 30, 'deferral', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -100]], 'balances': {'cash': 100, 'rent': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 28, 'regular', 'cash', 100], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 28, 'deferral', 'accrued_wages', -100], ['E3', 31, 'accrual', 'cash', 250], ['E4', 30, 'deferral', 'accrued_wages', 250]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E3', 32, -250]], 'balances': {'cash': 100, 'accrued_interest': 0, 'accrued_wages': 150}}], ['control 5', {'period_end': 28, 'entries': [['E0', 29, 'regular', 'accrued_interest', 100], ['E1', 28, 'deferral', 'rent', -40], ['E2', 29, 'regular', 'rent', 100], ['E3', 29, 'accrual', 'cash', 250], ['E4', 25, 'accrual', 'accrued_interest', 250], ['E5', 25, 'regular', 'accrued_interest', -100], ['E6', 5, 'accrual', 'accrued_interest', 100]], 'as_of': 30}, {'reversals': [['R-E4', 29, -250], ['R-E6', 29, -100]], 'balances': {'accrued_interest': 0, 'rent': 60, 'cash': 250}}], ['control 6', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'accrued_interest', 100], ['E1', 28, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'rent', 100], ['E3', 29, 'deferral', 'accrued_interest', -40], ['E4', 28, 'deferral', 'cash', 100], ['E5', 28, 'accrual', 'accrued_wages', -40]], 'as_of': 27}, {'reversals': [['R-E1', 29, -100], ['R-E5', 29, 40]], 'balances': {}}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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):
    end = x['period_end']
    rev = []
    for eid, day, kind, acct, amt in x['entries']:
        if kind == 'accrual' and day <= end:
            rev.append(['R-' + eid, end + 1, kind, acct, -amt])
    bal = {}
    for eid, day, kind, acct, amt in x['entries'] + rev:
        if day < x['as_of'] + (1 if kind == 'regular' else 0):
            bal[acct] = bal.get(acct, 0) + amt
    return {'reversals': [[r[0], r[1], r[4]] for r in rev], 'balances': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', 250], ['E1', 27, 'regular', 'rent', 250], ['E2', 30, 'accrual', 'cash', -100], ['E3', 30, 'deferral', 'accrued_interest', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -250]], 'balances': {'rent': 250}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'accrued_wages', 250], ['E1', 32, 'regular', 'cash', 100], ['E2', 27, 'accrual', 'rent', 100], ['E3', 5, 'regular', 'accrued_wages', 100], ['E4', 31, 'regular', 'accrued_interest', -40], ['E5', 32, 'regular', 'cash', -40]], 'as_of': 30}, {'reversals': [['R-E2', 31, -100]], 'balances': {'rent': 100, 'accrued_wages': 100}}], ['control 2', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 700], ['E1', 5, 'deferral', 'accrued_interest', -100], ['E2', 5, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': -100, 'cash': -40}}], ['control 3', {'period_end': 30, 'entries': [['E0', 29, 'regular', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'accrued_interest', -100]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100], ['R-E2', 31, 100]], 'balances': {'rent': 700, 'accrued_interest': 0}}], ['control 4', {'period_end': 31, 'entries': [['E0', 5, 'deferral', 'accrued_interest', -40], ['E1', 28, 'deferral', 'accrued_wages', -100], ['E2', 33, 'deferral', 'cash', 100], ['E3', 5, 'accrual', 'accrued_interest', -40], ['E4', 5, 'accrual', 'accrued_interest', 250], ['E5', 31, 'accrual', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [['R-E3', 32, 40], ['R-E4', 32, -250], ['R-E5', 32, -100]], 'balances': {'accrued_interest': 170, 'accrued_wages': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', -40], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 30, 'accrual', 'accrued_wages', -100], ['E3', 30, 'deferral', 'cash', 100], ['E4', 30, 'accrual', 'cash', -100]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100], ['R-E2', 31, 100], ['R-E4', 31, 100]], 'balances': {'accrued_wages': -40, 'accrued_interest': 0, 'cash': 100}}], ['control 6', {'period_end': 30, 'entries': [['E0', 27, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'accrued_interest', 700], ['E2', 27, 'regular', 'accrued_interest', -100], ['E3', 30, 'deferral', 'cash', -40], ['E4', 30, 'deferral', 'rent', 100], ['E5', 30, 'accrual', 'accrued_wages', -40]], 'as_of': 29}, {'reversals': [['R-E0', 31, 40], ['R-E1', 31, -700], ['R-E5', 31, 40]], 'balances': {'rent': -40, 'accrued_interest': 600}}]], [['regression: as-of inclusivity', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_wages', 250], ['E1', 28, 'accrual', 'cash', 100], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 31, 'regular', 'cash', 100], ['E4', 5, 'accrual', 'cash', -40], ['E5', 31, 'accrual', 'accrued_interest', 250], ['E6', 33, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E2', 32, 40], ['R-E4', 32, 40], ['R-E5', 32, -250]], 'balances': {'accrued_wages': 250, 'cash': 100, 'accrued_interest': -100}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_wages', 100], ['E1', 29, 'regular', 'accrued_wages', 100], ['E2', 32, 'deferral', 'accrued_wages', 700], ['E3', 27, 'deferral', 'rent', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -40}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'accrued_interest', -40], ['E1', 30, 'accrual', 'accrued_interest', 250], ['E2', 29, 'regular', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 27, 'deferral', 'rent', 250], ['E5', 29, 'accrual', 'accrued_interest', -100], ['E6', 27, 'deferral', 'rent', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'accrued_interest': -40, 'rent': 950}}], ['control 3', {'period_end': 28, 'entries': [['E0', 25, 'regular', 'accrued_interest', 100], ['E1', 29, 'accrual', 'cash', 100], ['E2', 30, 'accrual', 'rent', 100], ['E3', 29, 'regular', 'cash', 700], ['E4', 25, 'accrual', 'rent', 700]], 'as_of': 28}, {'reversals': [['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'rent': 700}}], ['control 4', {'period_end': 28, 'entries': [['E0', 29, 'deferral', 'cash', -40], ['E1', 5, 'accrual', 'accrued_interest', -100], ['E2', 25, 'deferral', 'accrued_interest', 250], ['E3', 25, 'accrual', 'accrued_wages', 700], ['E4', 28, 'accrual', 'rent', -100]], 'as_of': 27}, {'reversals': [['R-E1', 29, 100], ['R-E3', 29, -700], ['R-E4', 29, 100]], 'balances': {'accrued_interest': 150, 'accrued_wages': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'rent', 100], ['E1', 29, 'deferral', 'accrued_interest', 700], ['E2', 25, 'regular', 'accrued_wages', -40], ['E3', 28, 'accrual', 'accrued_wages', -100], ['E4', 25, 'accrual', 'accrued_interest', 100], ['E5', 28, 'deferral', 'accrued_wages', 100], ['E6', 30, 'regular', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E3', 29, 100], ['R-E4', 29, -100]], 'balances': {'rent': 100, 'accrued_wages': -40, 'accrued_interest': 100}}], ['control 6', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'cash', 700], ['E1', 32, 'deferral', 'cash', -40], ['E2', 5, 'accrual', 'accrued_wages', -40]], 'as_of': 33}, {'reversals': [['R-E0', 32, -700], ['R-E2', 32, 40]], 'balances': {'cash': -40, 'accrued_wages': 0}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_interest', 250], ['E2', 28, 'accrual', 'rent', -40], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 5, 'accrual', 'accrued_wages', 700]], 'as_of': 27}, {'reversals': [['R-E2', 29, 40], ['R-E3', 29, -100], ['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'accrued_wages': 700}}], ['regression: as-of inclusivity, partial-repair probe', {'period_end': 30, 'entries': [['E0', 27, 'regular', 'cash', 250], ['E1', 29, 'regular', 'rent', 100], ['E2', 29, 'accrual', 'accrued_wages', 250], ['E3', 30, 'accrual', 'rent', 100], ['E4', 5, 'accrual', 'cash', 250], ['E5', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -250], ['R-E3', 31, -100], ['R-E4', 31, -250]], 'balances': {'cash': 500, 'rent': 100, 'accrued_wages': 150}}], ['control 1', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'rent', -40], ['E1', 30, 'accrual', 'accrued_wages', 250], ['E2', 30, 'deferral', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_interest', 100], ['E4', 32, 'regular', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 31, -250], ['R-E3', 31, -100]], 'balances': {'rent': -40, 'accrued_interest': 100}}], ['control 2', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}], ['control 3', {'period_end': 31, 'entries': [['E0', 28, 'accrual', 'accrued_interest', 100], ['E1', 31, 'deferral', 'cash', 250], ['E2', 30, 'regular', 'cash', -100]], 'as_of': 33}, {'reversals': [['R-E0', 32, -100]], 'balances': {'accrued_interest': 0, 'cash': 150}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'accrued_interest', -40], ['E1', 29, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'accrued_interest', -40], ['E3', 28, 'accrual', 'accrued_wages', -40], ['E4', 28, 'accrual', 'cash', 100], ['E5', 5, 'accrual', 'rent', 250]], 'as_of': 27}, {'reversals': [['R-E3', 29, 40], ['R-E4', 29, -100], ['R-E5', 29, -250]], 'balances': {'accrued_interest': -40, 'rent': 250}}], ['control 5', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'cash', -100], ['E1', 31, 'deferral', 'accrued_interest', 700], ['E2', 30, 'accrual', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, 100]], 'balances': {}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'cash', 250], ['E2', 28, 'regular', 'cash', 100]], 'as_of': 27}, {'reversals': [['R-E1', 29, -250]], 'balances': {'accrued_wages': 700}}], ['control 1', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'cash', -100], ['E2', 5, 'accrual', 'cash', 100], ['E3', 27, 'regular', 'accrued_interest', 700]], 'as_of': 30}, {'reversals': [['R-E0', 29, 40], ['R-E1', 29, 100], ['R-E2', 29, -100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_interest': 700}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 29, 'accrual', 'accrued_interest', 700], ['E2', 28, 'deferral', 'rent', 250], ['E3', 29, 'regular', 'accrued_interest', 250]], 'as_of': 30}, {'reversals': [['R-E0', 29, -100]], 'balances': {'cash': 0, 'accrued_interest': 950, 'rent': 250}}], ['control 3', {'period_end': 30, 'entries': [['E0', 30, 'regular', 'cash', -40], ['E1', 30, 'accrual', 'cash', 700], ['E2', 30, 'deferral', 'accrued_wages', 700]], 'as_of': 32}, {'reversals': [['R-E1', 31, -700]], 'balances': {'cash': -40, 'accrued_wages': 700}}], ['control 4', {'period_end': 28, 'entries': [['E0', 29, 'regular', 'cash', 100], ['E1', 25, 'accrual', 'cash', 250], ['E2', 27, 'deferral', 'rent', -100], ['E3', 28, 'regular', 'cash', 100], ['E4', 28, 'regular', 'rent', 250], ['E5', 28, 'regular', 'rent', -40], ['E6', 28, 'accrual', 'rent', 250]], 'as_of': 30}, {'reversals': [['R-E1', 29, -250], ['R-E6', 29, -250]], 'balances': {'cash': 200, 'rent': 110}}], ['control 5', {'period_end': 31, 'entries': [['E0', 28, 'regular', 'cash', 100], ['E1', 33, 'accrual', 'accrued_wages', 100], ['E2', 5, 'deferral', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 30, 'accrual', 'accrued_wages', 100]], 'as_of': 31}, {'reversals': [['R-E3', 32, -700], ['R-E4', 32, -100]], 'balances': {'cash': 1500, 'accrued_wages': 100}}], ['control 6', {'period_end': 30, 'entries': [['E0', 31, 'deferral', 'cash', 100], ['E1', 31, 'accrual', 'accrued_wages', 100], ['E2', 30, 'deferral', 'accrued_interest', -100], ['E3', 5, 'deferral', 'accrued_interest', 250]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 100, 'accrued_wages': 100, 'accrued_interest': 150}}]], [['regression: as-of inclusivity', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'cash', -40], ['E1', 27, 'accrual', 'accrued_interest', 100], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100]], 'balances': {'cash': -40, 'accrued_interest': 0}}], ['control 1', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', -100], ['E2', 29, 'deferral', 'cash', 100], ['E3', 28, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'cash', -40], ['E5', 30, 'regular', 'cash', 250]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700]], 'balances': {}}], ['control 2', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'deferral', 'cash', -100], ['E2', 32, 'regular', 'cash', 700], ['E3', 32, 'accrual', 'rent', 100], ['E4', 31, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 3', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'accrual', 'rent', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 30, 'deferral', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -100]], 'balances': {'cash': 100, 'rent': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 28, 'regular', 'cash', 100], ['E1', 30, 'accrual', 'accrued_interest', 100], ['E2', 28, 'deferral', 'accrued_wages', -100], ['E3', 31, 'accrual', 'cash', 250], ['E4', 30, 'deferral', 'accrued_wages', 250]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E3', 32, -250]], 'balances': {'cash': 100, 'accrued_interest': 0, 'accrued_wages': 150}}], ['control 5', {'period_end': 28, 'entries': [['E0', 29, 'regular', 'accrued_interest', 100], ['E1', 28, 'deferral', 'rent', -40], ['E2', 29, 'regular', 'rent', 100], ['E3', 29, 'accrual', 'cash', 250], ['E4', 25, 'accrual', 'accrued_interest', 250], ['E5', 25, 'regular', 'accrued_interest', -100], ['E6', 5, 'accrual', 'accrued_interest', 100]], 'as_of': 30}, {'reversals': [['R-E4', 29, -250], ['R-E6', 29, -100]], 'balances': {'accrued_interest': 0, 'rent': 60, 'cash': 250}}], ['control 6', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'accrued_interest', 100], ['E1', 28, 'accrual', 'accrued_interest', 100], ['E2', 29, 'accrual', 'rent', 100], ['E3', 29, 'deferral', 'accrued_interest', -40], ['E4', 28, 'deferral', 'cash', 100], ['E5', 28, 'accrual', 'accrued_wages', -40]], 'as_of': 27}, {'reversals': [['R-E1', 29, -100], ['R-E5', 29, 40]], 'balances': {}}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Balances as of a date omit entries dated that day.

x = {'period_end': day, 'as_of': day, 'entries': [[id, day, kind, account, signed amount]]}. Every entry of kind 'accrual' dated on or before period_end is reversed by a generated entry 'R-'+id dated period_end + 1 with the negated amount; regular and deferral entries and later accruals are not reversed. Balances include every original and generated row dated on or before as_of; an account with rows in range appears even if its balance is zero. Return {'reversals': [[id, day, amount]], 'balances': {account: amount}}.

split: open-access


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

N = 1
observations = []
def solve(x):
    end = x['period_end']
    rev = []
    for eid, day, kind, acct, amt in x['entries']:
        if kind == 'accrual' and day <= end:
            rev.append(['R-' + eid, end + 1, kind, acct, -amt])
    bal = {}
    for eid, day, kind, acct, amt in x['entries'] + rev:
        if day <= x['as_of']:
            bal[acct] = bal.get(acct, 0) + amt
    return {'reversals': [[r[0], r[1], r[4]] for r in rev], 'balances': {a: v for a, v in bal.items() if v}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: zero balance accounts', {'period_end': 31, 'entries': [['E0', 33, 'accrual', 'accrued_wages', -40], ['E1', 31, 'accrual', 'rent', 250], ['E2', 31, 'accrual', 'cash', -100], ['E3', 32, 'deferral', 'accrued_wages', 250]], 'as_of': 32}, {'reversals': [['R-E1', 32, -250], ['R-E2', 32, 100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_wages': 250}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'accrued_wages', 100], ['E1', 5, 'regular', 'accrued_interest', -100], ['E2', 28, 'accrual', 'accrued_wages', 700], ['E3', 32, 'accrual', 'cash', -100], ['E4', 28, 'deferral', 'accrued_interest', 100], ['E5', 31, 'accrual', 'cash', 100]], 'as_of': 32}, {'reversals': [['R-E0', 32, -100], ['R-E2', 32, -700], ['R-E5', 32, -100]], 'balances': {'accrued_wages': 0, 'accrued_interest': 0, 'cash': -100}}], ['control 1', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', 250], ['E1', 27, 'regular', 'rent', 250], ['E2', 30, 'accrual', 'cash', -100], ['E3', 30, 'deferral', 'accrued_interest', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -250]], 'balances': {'rent': 250}}], ['control 2', {'period_end': 31, 'entries': [['E0', 33, 'accrual', 'rent', 700], ['E1', 31, 'deferral', 'rent', -40], ['E2', 32, 'deferral', 'rent', 100]], 'as_of': 32}, {'reversals': [], 'balances': {'rent': 60}}], ['control 3', {'period_end': 30, 'entries': [['E0', 29, 'regular', 'cash', 700], ['E1', 32, 'accrual', 'cash', 700], ['E2', 5, 'accrual', 'cash', 100], ['E3', 30, 'deferral', 'rent', 700], ['E4', 30, 'accrual', 'rent', 100], ['E5', 5, 'regular', 'accrued_wages', 250]], 'as_of': 29}, {'reversals': [['R-E2', 31, -100], ['R-E4', 31, -100]], 'balances': {'cash': 800, 'accrued_wages': 250}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_interest', 100], ['E1', 5, 'accrual', 'cash', 250], ['E2', 33, 'regular', 'accrued_interest', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 31, 'regular', 'accrued_interest', 250], ['E5', 31, 'regular', 'accrued_wages', 100]], 'as_of': 31}, {'reversals': [['R-E1', 32, -250], ['R-E3', 32, 100]], 'balances': {'accrued_interest': 350, 'cash': 150, 'accrued_wages': 100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 30, 'regular', 'accrued_interest', 100], ['E1', 31, 'accrual', 'accrued_interest', 700], ['E2', 28, 'deferral', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [['R-E1', 32, -700]], 'balances': {'accrued_interest': 900}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'accrued_wages', 100], ['E2', 30, 'accrual', 'cash', -100], ['E3', 29, 'accrual', 'rent', -40], ['E4', 28, 'accrual', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100], ['R-E4', 29, -250]], 'balances': {'accrued_wages': 0, 'rent': -40, 'cash': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 30, 'entries': [['E0', 27, 'deferral', 'rent', 250], ['E1', 27, 'accrual', 'accrued_interest', 700], ['E2', 29, 'regular', 'accrued_wages', 100], ['E3', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E1', 31, -700]], 'balances': {'rent': 250, 'accrued_interest': 700, 'accrued_wages': 0}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_wages', 100], ['E1', 29, 'regular', 'accrued_wages', 100], ['E2', 32, 'deferral', 'accrued_wages', 700], ['E3', 27, 'deferral', 'rent', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -40}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'accrued_interest', -40], ['E1', 30, 'accrual', 'accrued_interest', 250], ['E2', 29, 'regular', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 27, 'deferral', 'rent', 250], ['E5', 29, 'accrual', 'accrued_interest', -100], ['E6', 27, 'deferral', 'rent', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'accrued_interest': -40, 'rent': 950}}], ['control 3', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_wages', 250], ['E1', 28, 'accrual', 'cash', 100], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 31, 'regular', 'cash', 100], ['E4', 5, 'accrual', 'cash', -40], ['E5', 31, 'accrual', 'accrued_interest', 250], ['E6', 33, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E2', 32, 40], ['R-E4', 32, 40], ['R-E5', 32, -250]], 'balances': {'accrued_wages': 250, 'cash': 100, 'accrued_interest': -100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'regular', 'accrued_interest', 100], ['E1', 29, 'accrual', 'cash', 100], ['E2', 30, 'accrual', 'rent', 100], ['E3', 29, 'regular', 'cash', 700], ['E4', 25, 'accrual', 'rent', 700]], 'as_of': 28}, {'reversals': [['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'rent': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'cash', -40], ['E1', 29, 'accrual', 'rent', -40], ['E2', 25, 'regular', 'rent', 250], ['E3', 29, 'accrual', 'accrued_wages', -100], ['E4', 29, 'accrual', 'rent', 250], ['E5', 28, 'regular', 'rent', -40], ['E6', 27, 'accrual', 'accrued_wages', -40]], 'as_of': 27}, {'reversals': [['R-E6', 29, 40]], 'balances': {'cash': -40, 'rent': 250, 'accrued_wages': -40}}]], [['regression: zero balance accounts', {'period_end': 31, 'entries': [['E0', 5, 'regular', 'rent', 250], ['E1', 32, 'regular', 'accrued_interest', -40], ['E2', 31, 'accrual', 'cash', -40], ['E3', 33, 'accrual', 'accrued_wages', 100]], 'as_of': 32}, {'reversals': [['R-E2', 32, 40]], 'balances': {'rent': 250, 'accrued_interest': -40, 'cash': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 31, 'entries': [['E0', 28, 'accrual', 'cash', -100], ['E1', 31, 'deferral', 'accrued_wages', -100], ['E2', 31, 'regular', 'accrued_interest', 700], ['E3', 31, 'deferral', 'rent', -40], ['E4', 32, 'accrual', 'accrued_wages', 100]], 'as_of': 33}, {'reversals': [['R-E0', 32, 100]], 'balances': {'cash': 0, 'accrued_wages': 0, 'accrued_interest': 700, 'rent': -40}}], ['control 1', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_interest', 250], ['E2', 28, 'accrual', 'rent', -40], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 5, 'accrual', 'accrued_wages', 700]], 'as_of': 27}, {'reversals': [['R-E2', 29, 40], ['R-E3', 29, -100], ['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'accrued_wages': 700}}], ['control 2', {'period_end': 30, 'entries': [['E0', 27, 'regular', 'cash', 250], ['E1', 29, 'regular', 'rent', 100], ['E2', 29, 'accrual', 'accrued_wages', 250], ['E3', 30, 'accrual', 'rent', 100], ['E4', 5, 'accrual', 'cash', 250], ['E5', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -250], ['R-E3', 31, -100], ['R-E4', 31, -250]], 'balances': {'cash': 500, 'rent': 100, 'accrued_wages': 150}}], ['control 3', {'period_end': 28, 'entries': [['E0', 28, 'deferral', 'rent', 100], ['E1', 28, 'deferral', 'cash', 250], ['E2', 28, 'regular', 'cash', 250], ['E3', 27, 'deferral', 'cash', 100], ['E4', 28, 'regular', 'rent', 100], ['E5', 28, 'regular', 'cash', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'rent': 200, 'cash': 1300}}], ['control 4', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'rent', -40], ['E1', 30, 'accrual', 'accrued_wages', 250], ['E2', 30, 'deferral', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_interest', 100], ['E4', 32, 'regular', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 31, -250], ['R-E3', 31, -100]], 'balances': {'rent': -40, 'accrued_interest': 100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'cash', -100], ['E2', 5, 'accrual', 'cash', 100], ['E3', 27, 'regular', 'accrued_interest', 700]], 'as_of': 30}, {'reversals': [['R-E0', 29, 40], ['R-E1', 29, 100], ['R-E2', 29, -100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_interest': 700}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'cash', -40], ['E1', 27, 'regular', 'rent', 100], ['E2', 29, 'deferral', 'accrued_wages', 100], ['E3', 5, 'regular', 'accrued_wages', 100], ['E4', 5, 'deferral', 'accrued_wages', -100], ['E5', 29, 'deferral', 'cash', -40], ['E6', 30, 'accrual', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, 40]], 'balances': {'cash': -40, 'rent': 100, 'accrued_wages': 0}}], ['control 1', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'cash', 250], ['E2', 28, 'regular', 'cash', 100]], 'as_of': 27}, {'reversals': [['R-E1', 29, -250]], 'balances': {'accrued_wages': 700}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 100], ['E1', 30, 'deferral', 'accrued_wages', -40], ['E2', 5, 'deferral', 'rent', 700], ['E3', 28, 'regular', 'accrued_wages', -100], ['E4', 28, 'regular', 'cash', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -100]], 'balances': {'accrued_wages': -100, 'rent': 700, 'cash': 100}}], ['control 3', {'period_end': 31, 'entries': [['E0', 31, 'regular', 'accrued_wages', 250], ['E1', 31, 'accrual', 'accrued_wages', 700], ['E2', 31, 'regular', 'rent', -40], ['E3', 31, 'accrual', 'rent', -100], ['E4', 28, 'accrual', 'accrued_wages', 100], ['E5', 31, 'accrual', 'accrued_interest', 700], ['E6', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 31}, {'reversals': [['R-E1', 32, -700], ['R-E3', 32, 100], ['R-E4', 32, -100], ['R-E5', 32, -700]], 'balances': {'accrued_wages': 1010, 'rent': -140, 'accrued_interest': 700}}], ['control 4', {'period_end': 30, 'entries': [['E0', 30, 'regular', 'cash', 250], ['E1', 32, 'accrual', 'rent', 700], ['E2', 29, 'deferral', 'cash', -100], ['E3', 30, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'rent', 700], ['E5', 30, 'regular', 'cash', -100]], 'as_of': 32}, {'reversals': [['R-E4', 31, -700]], 'balances': {'cash': 750, 'rent': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'rent', 100], ['E1', 28, 'regular', 'accrued_wages', 250], ['E2', 27, 'accrual', 'rent', 700], ['E3', 5, 'deferral', 'accrued_wages', 100], ['E4', 29, 'deferral', 'rent', -100], ['E5', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 28}, {'reversals': [['R-E2', 29, -700]], 'balances': {'rent': 800, 'accrued_wages': 350}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'cash', -40], ['E1', 27, 'accrual', 'accrued_interest', 100], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100]], 'balances': {'cash': -40, 'accrued_interest': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'cash', 100], ['E2', 31, 'accrual', 'rent', 100], ['E3', 5, 'deferral', 'accrued_interest', -100], ['E4', 32, 'regular', 'accrued_wages', 700]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100]], 'balances': {'accrued_interest': 0, 'cash': 0, 'rent': 100, 'accrued_wages': 700}}], ['control 1', {'period_end': 31, 'entries': [['E0', 32, 'deferral', 'cash', 250], ['E1', 28, 'regular', 'rent', 250], ['E2', 33, 'deferral', 'cash', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 250, 'rent': 250}}], ['control 2', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', -100], ['E2', 29, 'deferral', 'cash', 100], ['E3', 28, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'cash', -40], ['E5', 30, 'regular', 'cash', 250]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700]], 'balances': {}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'rent', 250], ['E1', 30, 'deferral', 'accrued_interest', -40], ['E2', 32, 'accrual', 'cash', 100], ['E3', 29, 'regular', 'cash', -40], ['E4', 27, 'accrual', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [['R-E4', 31, -100]], 'balances': {'accrued_interest': -40, 'cash': -40, 'accrued_wages': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'deferral', 'cash', -100], ['E2', 32, 'regular', 'cash', 700], ['E3', 32, 'accrual', 'rent', 100], ['E4', 31, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'accrual', 'rent', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 30, 'deferral', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -100]], 'balances': {'cash': 100, 'rent': 100}}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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):
    end = x['period_end']
    rev = []
    for eid, day, kind, acct, amt in x['entries']:
        if kind == 'accrual' and day <= end:
            rev.append(['R-' + eid, end + 1, kind, acct, -amt])
    bal = {}
    for eid, day, kind, acct, amt in x['entries'] + rev:
        if day <= x['as_of']:
            bal[acct] = bal.get(acct, 0) + amt
    return {'reversals': [[r[0], r[1], r[4]] for r in rev], 'balances': {a: v for a, v in bal.items() if v or a in {r[3] for r in rev}}}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: zero balance accounts', {'period_end': 31, 'entries': [['E0', 33, 'accrual', 'accrued_wages', -40], ['E1', 31, 'accrual', 'rent', 250], ['E2', 31, 'accrual', 'cash', -100], ['E3', 32, 'deferral', 'accrued_wages', 250]], 'as_of': 32}, {'reversals': [['R-E1', 32, -250], ['R-E2', 32, 100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_wages': 250}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'accrued_wages', 100], ['E1', 5, 'regular', 'accrued_interest', -100], ['E2', 28, 'accrual', 'accrued_wages', 700], ['E3', 32, 'accrual', 'cash', -100], ['E4', 28, 'deferral', 'accrued_interest', 100], ['E5', 31, 'accrual', 'cash', 100]], 'as_of': 32}, {'reversals': [['R-E0', 32, -100], ['R-E2', 32, -700], ['R-E5', 32, -100]], 'balances': {'accrued_wages': 0, 'accrued_interest': 0, 'cash': -100}}], ['control 1', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', 250], ['E1', 27, 'regular', 'rent', 250], ['E2', 30, 'accrual', 'cash', -100], ['E3', 30, 'deferral', 'accrued_interest', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -250]], 'balances': {'rent': 250}}], ['control 2', {'period_end': 31, 'entries': [['E0', 33, 'accrual', 'rent', 700], ['E1', 31, 'deferral', 'rent', -40], ['E2', 32, 'deferral', 'rent', 100]], 'as_of': 32}, {'reversals': [], 'balances': {'rent': 60}}], ['control 3', {'period_end': 30, 'entries': [['E0', 29, 'regular', 'cash', 700], ['E1', 32, 'accrual', 'cash', 700], ['E2', 5, 'accrual', 'cash', 100], ['E3', 30, 'deferral', 'rent', 700], ['E4', 30, 'accrual', 'rent', 100], ['E5', 5, 'regular', 'accrued_wages', 250]], 'as_of': 29}, {'reversals': [['R-E2', 31, -100], ['R-E4', 31, -100]], 'balances': {'cash': 800, 'accrued_wages': 250}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_interest', 100], ['E1', 5, 'accrual', 'cash', 250], ['E2', 33, 'regular', 'accrued_interest', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 31, 'regular', 'accrued_interest', 250], ['E5', 31, 'regular', 'accrued_wages', 100]], 'as_of': 31}, {'reversals': [['R-E1', 32, -250], ['R-E3', 32, 100]], 'balances': {'accrued_interest': 350, 'cash': 150, 'accrued_wages': 100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 30, 'regular', 'accrued_interest', 100], ['E1', 31, 'accrual', 'accrued_interest', 700], ['E2', 28, 'deferral', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [['R-E1', 32, -700]], 'balances': {'accrued_interest': 900}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'accrued_wages', 100], ['E2', 30, 'accrual', 'cash', -100], ['E3', 29, 'accrual', 'rent', -40], ['E4', 28, 'accrual', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100], ['R-E4', 29, -250]], 'balances': {'accrued_wages': 0, 'rent': -40, 'cash': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 30, 'entries': [['E0', 27, 'deferral', 'rent', 250], ['E1', 27, 'accrual', 'accrued_interest', 700], ['E2', 29, 'regular', 'accrued_wages', 100], ['E3', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E1', 31, -700]], 'balances': {'rent': 250, 'accrued_interest': 700, 'accrued_wages': 0}}], ['control 1', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_wages', 100], ['E1', 29, 'regular', 'accrued_wages', 100], ['E2', 32, 'deferral', 'accrued_wages', 700], ['E3', 27, 'deferral', 'rent', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -40}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'regular', 'accrued_interest', -40], ['E1', 30, 'accrual', 'accrued_interest', 250], ['E2', 29, 'regular', 'cash', 700], ['E3', 30, 'accrual', 'cash', 700], ['E4', 27, 'deferral', 'rent', 250], ['E5', 29, 'accrual', 'accrued_interest', -100], ['E6', 27, 'deferral', 'rent', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'accrued_interest': -40, 'rent': 950}}], ['control 3', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'accrued_wages', 250], ['E1', 28, 'accrual', 'cash', 100], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 31, 'regular', 'cash', 100], ['E4', 5, 'accrual', 'cash', -40], ['E5', 31, 'accrual', 'accrued_interest', 250], ['E6', 33, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E1', 32, -100], ['R-E2', 32, 40], ['R-E4', 32, 40], ['R-E5', 32, -250]], 'balances': {'accrued_wages': 250, 'cash': 100, 'accrued_interest': -100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'regular', 'accrued_interest', 100], ['E1', 29, 'accrual', 'cash', 100], ['E2', 30, 'accrual', 'rent', 100], ['E3', 29, 'regular', 'cash', 700], ['E4', 25, 'accrual', 'rent', 700]], 'as_of': 28}, {'reversals': [['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'rent': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'cash', -40], ['E1', 29, 'accrual', 'rent', -40], ['E2', 25, 'regular', 'rent', 250], ['E3', 29, 'accrual', 'accrued_wages', -100], ['E4', 29, 'accrual', 'rent', 250], ['E5', 28, 'regular', 'rent', -40], ['E6', 27, 'accrual', 'accrued_wages', -40]], 'as_of': 27}, {'reversals': [['R-E6', 29, 40]], 'balances': {'cash': -40, 'rent': 250, 'accrued_wages': -40}}]], [['regression: zero balance accounts', {'period_end': 31, 'entries': [['E0', 5, 'regular', 'rent', 250], ['E1', 32, 'regular', 'accrued_interest', -40], ['E2', 31, 'accrual', 'cash', -40], ['E3', 33, 'accrual', 'accrued_wages', 100]], 'as_of': 32}, {'reversals': [['R-E2', 32, 40]], 'balances': {'rent': 250, 'accrued_interest': -40, 'cash': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 31, 'entries': [['E0', 28, 'accrual', 'cash', -100], ['E1', 31, 'deferral', 'accrued_wages', -100], ['E2', 31, 'regular', 'accrued_interest', 700], ['E3', 31, 'deferral', 'rent', -40], ['E4', 32, 'accrual', 'accrued_wages', 100]], 'as_of': 33}, {'reversals': [['R-E0', 32, 100]], 'balances': {'cash': 0, 'accrued_wages': 0, 'accrued_interest': 700, 'rent': -40}}], ['control 1', {'period_end': 28, 'entries': [['E0', 27, 'regular', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_interest', 250], ['E2', 28, 'accrual', 'rent', -40], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 5, 'accrual', 'accrued_wages', 700]], 'as_of': 27}, {'reversals': [['R-E2', 29, 40], ['R-E3', 29, -100], ['R-E4', 29, -700]], 'balances': {'accrued_interest': 100, 'accrued_wages': 700}}], ['control 2', {'period_end': 30, 'entries': [['E0', 27, 'regular', 'cash', 250], ['E1', 29, 'regular', 'rent', 100], ['E2', 29, 'accrual', 'accrued_wages', 250], ['E3', 30, 'accrual', 'rent', 100], ['E4', 5, 'accrual', 'cash', 250], ['E5', 27, 'deferral', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -250], ['R-E3', 31, -100], ['R-E4', 31, -250]], 'balances': {'cash': 500, 'rent': 100, 'accrued_wages': 150}}], ['control 3', {'period_end': 28, 'entries': [['E0', 28, 'deferral', 'rent', 100], ['E1', 28, 'deferral', 'cash', 250], ['E2', 28, 'regular', 'cash', 250], ['E3', 27, 'deferral', 'cash', 100], ['E4', 28, 'regular', 'rent', 100], ['E5', 28, 'regular', 'cash', 700]], 'as_of': 28}, {'reversals': [], 'balances': {'rent': 200, 'cash': 1300}}], ['control 4', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'rent', -40], ['E1', 30, 'accrual', 'accrued_wages', 250], ['E2', 30, 'deferral', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_interest', 100], ['E4', 32, 'regular', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E1', 31, -250], ['R-E3', 31, -100]], 'balances': {'rent': -40, 'accrued_interest': 100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'rent', -40], ['E1', 27, 'accrual', 'cash', -100], ['E2', 5, 'accrual', 'cash', 100], ['E3', 27, 'regular', 'accrued_interest', 700]], 'as_of': 30}, {'reversals': [['R-E0', 29, 40], ['R-E1', 29, 100], ['R-E2', 29, -100]], 'balances': {'rent': 0, 'cash': 0, 'accrued_interest': 700}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'cash', -40], ['E1', 27, 'regular', 'rent', 100], ['E2', 29, 'deferral', 'accrued_wages', 100], ['E3', 5, 'regular', 'accrued_wages', 100], ['E4', 5, 'deferral', 'accrued_wages', -100], ['E5', 29, 'deferral', 'cash', -40], ['E6', 30, 'accrual', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, 40]], 'balances': {'cash': -40, 'rent': 100, 'accrued_wages': 0}}], ['control 1', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'cash', 250], ['E2', 28, 'regular', 'cash', 100]], 'as_of': 27}, {'reversals': [['R-E1', 29, -250]], 'balances': {'accrued_wages': 700}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 100], ['E1', 30, 'deferral', 'accrued_wages', -40], ['E2', 5, 'deferral', 'rent', 700], ['E3', 28, 'regular', 'accrued_wages', -100], ['E4', 28, 'regular', 'cash', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -100]], 'balances': {'accrued_wages': -100, 'rent': 700, 'cash': 100}}], ['control 3', {'period_end': 31, 'entries': [['E0', 31, 'regular', 'accrued_wages', 250], ['E1', 31, 'accrual', 'accrued_wages', 700], ['E2', 31, 'regular', 'rent', -40], ['E3', 31, 'accrual', 'rent', -100], ['E4', 28, 'accrual', 'accrued_wages', 100], ['E5', 31, 'accrual', 'accrued_interest', 700], ['E6', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 31}, {'reversals': [['R-E1', 32, -700], ['R-E3', 32, 100], ['R-E4', 32, -100], ['R-E5', 32, -700]], 'balances': {'accrued_wages': 1010, 'rent': -140, 'accrued_interest': 700}}], ['control 4', {'period_end': 30, 'entries': [['E0', 30, 'regular', 'cash', 250], ['E1', 32, 'accrual', 'rent', 700], ['E2', 29, 'deferral', 'cash', -100], ['E3', 30, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'rent', 700], ['E5', 30, 'regular', 'cash', -100]], 'as_of': 32}, {'reversals': [['R-E4', 31, -700]], 'balances': {'cash': 750, 'rent': 700}}], ['control 5', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'rent', 100], ['E1', 28, 'regular', 'accrued_wages', 250], ['E2', 27, 'accrual', 'rent', 700], ['E3', 5, 'deferral', 'accrued_wages', 100], ['E4', 29, 'deferral', 'rent', -100], ['E5', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 28}, {'reversals': [['R-E2', 29, -700]], 'balances': {'rent': 800, 'accrued_wages': 350}}]], [['regression: zero balance accounts', {'period_end': 28, 'entries': [['E0', 28, 'regular', 'cash', -40], ['E1', 27, 'accrual', 'accrued_interest', 100], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 29}, {'reversals': [['R-E1', 29, -100]], 'balances': {'cash': -40, 'accrued_interest': 0}}], ['regression: zero balance accounts, partial-repair probe', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'cash', 100], ['E2', 31, 'accrual', 'rent', 100], ['E3', 5, 'deferral', 'accrued_interest', -100], ['E4', 32, 'regular', 'accrued_wages', 700]], 'as_of': 32}, {'reversals': [['R-E1', 31, -100]], 'balances': {'accrued_interest': 0, 'cash': 0, 'rent': 100, 'accrued_wages': 700}}], ['control 1', {'period_end': 31, 'entries': [['E0', 32, 'deferral', 'cash', 250], ['E1', 28, 'regular', 'rent', 250], ['E2', 33, 'deferral', 'cash', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 250, 'rent': 250}}], ['control 2', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'accrued_interest', -100], ['E2', 29, 'deferral', 'cash', 100], ['E3', 28, 'regular', 'cash', 700], ['E4', 29, 'accrual', 'cash', -40], ['E5', 30, 'regular', 'cash', 250]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700]], 'balances': {}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'rent', 250], ['E1', 30, 'deferral', 'accrued_interest', -40], ['E2', 32, 'accrual', 'cash', 100], ['E3', 29, 'regular', 'cash', -40], ['E4', 27, 'accrual', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [['R-E4', 31, -100]], 'balances': {'accrued_interest': -40, 'cash': -40, 'accrued_wages': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'deferral', 'cash', -100], ['E2', 32, 'regular', 'cash', 700], ['E3', 32, 'accrual', 'rent', 100], ['E4', 31, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'cash', 100], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'accrual', 'rent', 700], ['E3', 30, 'accrual', 'cash', -100], ['E4', 30, 'deferral', 'rent', -40]], 'as_of': 28}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -100]], 'balances': {'cash': 100, 'rent': 100}}]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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 whose accrual was reversed vanish from the balance list.

x = {'period_end': day, 'as_of': day, 'entries': [[id, day, kind, account, signed amount]]}. Every entry of kind 'accrual' dated on or before period_end is reversed by a generated entry 'R-'+id dated period_end + 1 with the negated amount; regular and deferral entries and later accruals are not reversed. Balances include every original and generated row dated on or before as_of; an account with rows in range appears even if its balance is zero. Return {'reversals': [[id, day, amount]], 'balances': {account: amount}}.

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date < p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: period end inclusivity', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['regression: period end inclusivity, partial-repair probe', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 1', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 2', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 3', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]], ['control 4', {'periods': [[1, 28, 'open'], [34, 61, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, True], ['E2', 31, False], ['E3', 64, True], ['E4', 31, True], ['E5', 62, False]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'no_period'], ['E4', None, 'no_period'], ['E5', None, 'no_period']]], ['control 5', {'periods': [[1, 31, 'soft'], [32, 62, 'closed']], 'policy': 'reject', 'entries': [['E0', 1, False], ['E1', 34, True], ['E2', 35, True], ['E3', 32, True], ['E4', 32, False], ['E5', 4, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', 4, 'posted']]]], [['regression: period end inclusivity', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [60, 89, 'closed'], [29, 59, 'closed'], [95, 125, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 90, True], ['E2', 92, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 2', {'periods': [[37, 66, 'open'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 69, False], ['E1', 1, False], ['E2', 69, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 37, 'rolled'], ['E2', None, 'no_period'], ['E3', 37, 'rolled']]], ['control 3', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 4, True], ['E2', 57, False]]}, [['E0', None, 'closed'], ['E1', 4, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[36, 65, 'closed'], [66, 93, 'open'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 68, False], ['E1', 96, True], ['E2', 31, True], ['E3', 68, True]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted']]], ['control 5', {'periods': [[93, 123, 'open'], [124, 153, 'open'], [32, 62, 'closed'], [1, 31, 'open'], [63, 92, 'closed']], 'policy': 'reject', 'entries': [['E0', 4, True], ['E1', 65, False], ['E2', 35, False], ['E3', 95, False]]}, [['E0', 4, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 95, 'posted']]], ['control 6', {'periods': [[32, 59, 'closed'], [60, 87, 'closed'], [1, 31, 'open']], 'policy': 'roll', 'entries': [['E0', 60, False], ['E1', 32, True], ['E2', 35, False], ['E3', 60, False], ['E4', 35, True], ['E5', 62, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]]], [['regression: period end inclusivity', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 4', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]], ['control 5', {'periods': [[37, 66, 'open'], [67, 94, 'soft'], [1, 31, 'soft']], 'policy': 'reject', 'entries': [['E0', 40, False], ['E1', 70, False], ['E2', 69, True], ['E3', 32, True], ['E4', 4, True], ['E5', 1, True]]}, [['E0', 40, 'posted'], ['E1', None, 'closed'], ['E2', 69, 'posted'], ['E3', None, 'no_period'], ['E4', 4, 'posted'], ['E5', 1, 'posted']]], ['control 6', {'periods': [[1, 31, 'closed'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 34, True], ['E1', 32, True], ['E2', 32, False], ['E3', 34, False], ['E4', 34, True], ['E5', 1, True]]}, [['E0', 34, 'posted'], ['E1', 32, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 34, 'posted'], ['E5', None, 'closed']]]], [['regression: period end inclusivity', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 1', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 2', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 3', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 5', {'periods': [[1, 28, 'soft'], [34, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 64, False], ['E1', 31, False], ['E2', 31, True], ['E3', 4, False], ['E4', 29, True]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'no_period']]], ['control 6', {'periods': [[1, 31, 'open'], [32, 62, 'open'], [68, 97, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, True], ['E2', 68, False], ['E3', 68, True], ['E4', 4, True]]}, [['E0', 32, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'closed'], ['E3', 68, 'posted'], ['E4', 4, 'posted']]]], [['regression: period end inclusivity', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 2', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]], ['control 5', {'periods': [[98, 125, 'closed'], [63, 92, 'open'], [32, 62, 'closed'], [126, 155, 'open'], [1, 31, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 126, False], ['E2', 32, False]]}, [['E0', None, 'closed'], ['E1', 126, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[32, 62, 'closed'], [63, 92, 'soft'], [1, 31, 'closed'], [123, 152, 'open'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 65, True], ['E1', 126, False], ['E2', 66, False]]}, [['E0', 65, 'posted'], ['E1', 126, 'posted'], ['E2', 123, 'rolled']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] < date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: period end inclusivity', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['regression: period end inclusivity, partial-repair probe', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 1', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 2', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 3', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]], ['control 4', {'periods': [[1, 28, 'open'], [34, 61, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, True], ['E2', 31, False], ['E3', 64, True], ['E4', 31, True], ['E5', 62, False]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'no_period'], ['E4', None, 'no_period'], ['E5', None, 'no_period']]], ['control 5', {'periods': [[1, 31, 'soft'], [32, 62, 'closed']], 'policy': 'reject', 'entries': [['E0', 1, False], ['E1', 34, True], ['E2', 35, True], ['E3', 32, True], ['E4', 32, False], ['E5', 4, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', 4, 'posted']]]], [['regression: period end inclusivity', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [60, 89, 'closed'], [29, 59, 'closed'], [95, 125, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 90, True], ['E2', 92, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 2', {'periods': [[37, 66, 'open'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 69, False], ['E1', 1, False], ['E2', 69, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 37, 'rolled'], ['E2', None, 'no_period'], ['E3', 37, 'rolled']]], ['control 3', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 4, True], ['E2', 57, False]]}, [['E0', None, 'closed'], ['E1', 4, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[36, 65, 'closed'], [66, 93, 'open'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 68, False], ['E1', 96, True], ['E2', 31, True], ['E3', 68, True]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted']]], ['control 5', {'periods': [[93, 123, 'open'], [124, 153, 'open'], [32, 62, 'closed'], [1, 31, 'open'], [63, 92, 'closed']], 'policy': 'reject', 'entries': [['E0', 4, True], ['E1', 65, False], ['E2', 35, False], ['E3', 95, False]]}, [['E0', 4, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 95, 'posted']]], ['control 6', {'periods': [[32, 59, 'closed'], [60, 87, 'closed'], [1, 31, 'open']], 'policy': 'roll', 'entries': [['E0', 60, False], ['E1', 32, True], ['E2', 35, False], ['E3', 60, False], ['E4', 35, True], ['E5', 62, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]]], [['regression: period end inclusivity', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 4', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]], ['control 5', {'periods': [[37, 66, 'open'], [67, 94, 'soft'], [1, 31, 'soft']], 'policy': 'reject', 'entries': [['E0', 40, False], ['E1', 70, False], ['E2', 69, True], ['E3', 32, True], ['E4', 4, True], ['E5', 1, True]]}, [['E0', 40, 'posted'], ['E1', None, 'closed'], ['E2', 69, 'posted'], ['E3', None, 'no_period'], ['E4', 4, 'posted'], ['E5', 1, 'posted']]], ['control 6', {'periods': [[1, 31, 'closed'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 34, True], ['E1', 32, True], ['E2', 32, False], ['E3', 34, False], ['E4', 34, True], ['E5', 1, True]]}, [['E0', 34, 'posted'], ['E1', 32, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 34, 'posted'], ['E5', None, 'closed']]]], [['regression: period end inclusivity', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 1', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 2', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 3', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 5', {'periods': [[1, 28, 'soft'], [34, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 64, False], ['E1', 31, False], ['E2', 31, True], ['E3', 4, False], ['E4', 29, True]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'no_period']]], ['control 6', {'periods': [[1, 31, 'open'], [32, 62, 'open'], [68, 97, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, True], ['E2', 68, False], ['E3', 68, True], ['E4', 4, True]]}, [['E0', 32, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'closed'], ['E3', 68, 'posted'], ['E4', 4, 'posted']]]], [['regression: period end inclusivity', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 2', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]], ['control 5', {'periods': [[98, 125, 'closed'], [63, 92, 'open'], [32, 62, 'closed'], [126, 155, 'open'], [1, 31, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 126, False], ['E2', 32, False]]}, [['E0', None, 'closed'], ['E1', 126, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[32, 62, 'closed'], [63, 92, 'soft'], [1, 31, 'closed'], [123, 152, 'open'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 65, True], ['E1', 126, False], ['E2', 66, False]]}, [['E0', 65, 'posted'], ['E1', 126, 'posted'], ['E2', 123, 'rolled']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Entries dated on the last day of a period are reported as outside any period.

x = {'periods': [[start_day, end_day, 'open'|'soft'|'closed']] (non-overlapping, any order), 'policy': 'reject'|'roll', 'entries': [[id, day, adjusting]]}. The period containing the day (start and end inclusive) is found; none gives [id, None, 'no_period']. Soft periods accept adjusting entries only. Open acceptance gives [id, day, 'posted']. Otherwise under 'roll' the entry posts on the start day of the earliest later open period ([id, start, 'rolled']) and with none, or under 'reject', gives [id, None, 'closed'].

split: open-access