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: reversal sign', {'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}}], ['regression: reversal sign, partial-repair probe', {'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 1', {'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 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', 30, 'deferral', 'accrued_interest', 100], ['E1', 32, 'accrual', 'cash', -100], ['E2', 31, 'deferral', 'accrued_interest', 700], ['E3', 31, 'regular', 'rent', 250], ['E4', 30, 'deferral', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_interest': 100, 'accrued_wages': 100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'cash', 100], ['E1', 27, 'regular', 'cash', 250], ['E2', 30, 'regular', 'accrued_wages', 100], ['E3', 28, 'regular', 'cash', -100], ['E4', 30, 'regular', 'accrued_interest', 100], ['E5', 27, 'regular', 'accrued_interest', 100], ['E6', 5, 'deferral', 'rent', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'cash': 250, 'accrued_wages': 100, 'accrued_interest': 200, 'rent': 100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'regular', 'accrued_wages', -40], ['E2', 30, 'deferral', 'rent', 100], ['E3', 33, 'accrual', 'accrued_interest', -100], ['E4', 5, 'deferral', 'cash', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'rent': 100, 'cash': -40}}]], [['regression: reversal sign', {'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', 29, 'regular', 'accrued_interest', 100], ['E1', 28, 'regular', 'rent', 250], ['E2', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': 100, 'rent': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 32, 'regular', 'accrued_interest', -100], ['E1', 29, 'deferral', 'cash', -40], ['E2', 31, 'accrual', 'accrued_wages', -100]], 'as_of': 31}, {'reversals': [], 'balances': {'cash': -40, 'accrued_wages': -100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'regular', 'rent', 100], ['E1', 33, 'regular', 'rent', 250], ['E2', 33, 'deferral', 'rent', 100]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 6', {'period_end': 31, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 100], ['E1', 30, 'regular', 'cash', -100], ['E2', 33, 'regular', 'accrued_wages', -40], ['E3', 32, 'accrual', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [], 'balances': {'accrued_wages': 100, 'cash': -100}}]], [['regression: reversal sign', {'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 1', {'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 2', {'period_end': 28, 'entries': [['E0', 28, 'deferral', 'accrued_interest', 100], ['E1', 27, 'regular', 'rent', -100], ['E2', 27, 'regular', 'rent', -100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': 100, 'rent': -200}}], ['control 3', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'rent', -40], ['E1', 28, 'regular', 'accrued_interest', 100], ['E2', 5, 'regular', 'accrued_wages', -100], ['E3', 25, 'regular', 'accrued_interest', 250]], 'as_of': 27}, {'reversals': [], 'balances': {'accrued_wages': -100, 'accrued_interest': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'cash', 100], ['E1', 30, 'deferral', 'accrued_interest', -40], ['E2', 30, 'regular', 'rent', 250], ['E3', 29, 'deferral', 'accrued_wages', -100], ['E4', 30, 'deferral', 'cash', 700], ['E5', 30, 'regular', 'accrued_wages', -100], ['E6', 30, 'deferral', 'cash', 100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_wages': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'cash', -40], ['E1', 5, 'regular', 'accrued_wages', 100], ['E2', 5, 'deferral', 'rent', 100], ['E3', 30, 'regular', 'cash', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 660, 'accrued_wages': 100, 'rent': 100}}], ['control 6', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -40], ['E1', 33, 'deferral', 'cash', -100], ['E2', 31, 'deferral', 'accrued_interest', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': -40, 'accrued_interest': 700}}]], [['regression: reversal sign', {'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 1', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'cash', -100], ['E1', 32, 'accrual', 'cash', 250], ['E2', 32, 'accrual', 'rent', -100], ['E3', 31, 'accrual', 'cash', -100], ['E4', 31, 'regular', 'accrued_wages', 100], ['E5', 5, 'deferral', 'cash', 700], ['E6', 30, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {'cash': 600, 'accrued_wages': 700}}], ['control 2', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', -40], ['E1', 32, 'accrual', 'accrued_interest', -40], ['E2', 27, 'deferral', 'accrued_interest', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': -40, 'accrued_interest': 100}}], ['control 3', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', -100], ['E1', 28, 'deferral', 'accrued_wages', 100], ['E2', 29, 'regular', 'rent', -40], ['E3', 25, 'deferral', 'rent', -100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -140}}], ['control 4', {'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}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_wages', 250], ['E2', 30, 'regular', 'cash', 250], ['E3', 27, 'regular', 'accrued_interest', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': -40}}], ['control 6', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'rent', 100], ['E1', 27, 'deferral', 'accrued_wages', 700], ['E2', 5, 'regular', 'rent', 700], ['E3', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'rent': 800, 'accrued_wages': 660}}]], [['regression: reversal sign', {'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: reversal sign, partial-repair probe', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 100], ['E1', 32, 'deferral', 'rent', -40], ['E2', 29, 'accrual', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_wages', 250], ['E4', 30, 'accrual', 'accrued_wages', -100], ['E5', 30, 'accrual', 'accrued_interest', 100], ['E6', 31, 'accrual', 'cash', 250]], 'as_of': 31}, {'reversals': [['R-E2', 31, 40], ['R-E3', 31, -250], ['R-E4', 31, 100], ['R-E5', 31, -100]], 'balances': {'accrued_wages': 100, 'accrued_interest': 0, 'cash': 250}}], ['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': 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': 31, 'entries': [['E0', 32, 'accrual', 'accrued_wages', 100], ['E1', 33, 'deferral', 'cash', 100], ['E2', 30, 'regular', 'cash', 700], ['E3', 33, 'regular', 'rent', 700]], 'as_of': 33}, {'reversals': [], 'balances': {'accrued_wages': 100, 'cash': 800, 'rent': 700}}], ['control 4', {'period_end': 30, 'entries': [['E0', 29, 'deferral', 'accrued_wages', 100], ['E1', 5, 'deferral', 'accrued_interest', -100], ['E2', 30, 'regular', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 800, 'accrued_interest': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 31, 'regular', 'accrued_interest', -100], ['E1', 27, 'regular', 'rent', 250], ['E2', 31, 'deferral', 'accrued_wages', 250], ['E3', 31, 'regular', 'accrued_interest', 100], ['E4', 27, 'deferral', 'accrued_interest', 100], ['E5', 29, 'regular', 'accrued_interest', 100], ['E6', 32, 'accrual', 'cash', 250]], 'as_of': 32}, {'reversals': [], 'balances': {'accrued_interest': 200, 'rent': 250, 'accrued_wages': 250, 'cash': 250}}]]]
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, -abs(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: reversal sign', {'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}}], ['regression: reversal sign, partial-repair probe', {'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 1', {'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 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', 30, 'deferral', 'accrued_interest', 100], ['E1', 32, 'accrual', 'cash', -100], ['E2', 31, 'deferral', 'accrued_interest', 700], ['E3', 31, 'regular', 'rent', 250], ['E4', 30, 'deferral', 'accrued_wages', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_interest': 100, 'accrued_wages': 100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 25, 'deferral', 'cash', 100], ['E1', 27, 'regular', 'cash', 250], ['E2', 30, 'regular', 'accrued_wages', 100], ['E3', 28, 'regular', 'cash', -100], ['E4', 30, 'regular', 'accrued_interest', 100], ['E5', 27, 'regular', 'accrued_interest', 100], ['E6', 5, 'deferral', 'rent', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'cash': 250, 'accrued_wages': 100, 'accrued_interest': 200, 'rent': 100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -100], ['E1', 31, 'regular', 'accrued_wages', -40], ['E2', 30, 'deferral', 'rent', 100], ['E3', 33, 'accrual', 'accrued_interest', -100], ['E4', 5, 'deferral', 'cash', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'rent': 100, 'cash': -40}}]], [['regression: reversal sign', {'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', 29, 'regular', 'accrued_interest', 100], ['E1', 28, 'regular', 'rent', 250], ['E2', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': 100, 'rent': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 32, 'regular', 'accrued_interest', -100], ['E1', 29, 'deferral', 'cash', -40], ['E2', 31, 'accrual', 'accrued_wages', -100]], 'as_of': 31}, {'reversals': [], 'balances': {'cash': -40, 'accrued_wages': -100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'regular', 'rent', 100], ['E1', 33, 'regular', 'rent', 250], ['E2', 33, 'deferral', 'rent', 100]], 'as_of': 30}, {'reversals': [], 'balances': {}}], ['control 6', {'period_end': 31, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 100], ['E1', 30, 'regular', 'cash', -100], ['E2', 33, 'regular', 'accrued_wages', -40], ['E3', 32, 'accrual', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [], 'balances': {'accrued_wages': 100, 'cash': -100}}]], [['regression: reversal sign', {'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 1', {'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 2', {'period_end': 28, 'entries': [['E0', 28, 'deferral', 'accrued_interest', 100], ['E1', 27, 'regular', 'rent', -100], ['E2', 27, 'regular', 'rent', -100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': 100, 'rent': -200}}], ['control 3', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'rent', -40], ['E1', 28, 'regular', 'accrued_interest', 100], ['E2', 5, 'regular', 'accrued_wages', -100], ['E3', 25, 'regular', 'accrued_interest', 250]], 'as_of': 27}, {'reversals': [], 'balances': {'accrued_wages': -100, 'accrued_interest': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'cash', 100], ['E1', 30, 'deferral', 'accrued_interest', -40], ['E2', 30, 'regular', 'rent', 250], ['E3', 29, 'deferral', 'accrued_wages', -100], ['E4', 30, 'deferral', 'cash', 700], ['E5', 30, 'regular', 'accrued_wages', -100], ['E6', 30, 'deferral', 'cash', 100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_wages': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 32, 'accrual', 'cash', -40], ['E1', 5, 'regular', 'accrued_wages', 100], ['E2', 5, 'deferral', 'rent', 100], ['E3', 30, 'regular', 'cash', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': 660, 'accrued_wages': 100, 'rent': 100}}], ['control 6', {'period_end': 31, 'entries': [['E0', 31, 'deferral', 'cash', -40], ['E1', 33, 'deferral', 'cash', -100], ['E2', 31, 'deferral', 'accrued_interest', 700]], 'as_of': 32}, {'reversals': [], 'balances': {'cash': -40, 'accrued_interest': 700}}]], [['regression: reversal sign', {'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 1', {'period_end': 30, 'entries': [['E0', 5, 'deferral', 'cash', -100], ['E1', 32, 'accrual', 'cash', 250], ['E2', 32, 'accrual', 'rent', -100], ['E3', 31, 'accrual', 'cash', -100], ['E4', 31, 'regular', 'accrued_wages', 100], ['E5', 5, 'deferral', 'cash', 700], ['E6', 30, 'deferral', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {'cash': 600, 'accrued_wages': 700}}], ['control 2', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', -40], ['E1', 32, 'accrual', 'accrued_interest', -40], ['E2', 27, 'deferral', 'accrued_interest', 100]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': -40, 'accrued_interest': 100}}], ['control 3', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', -100], ['E1', 28, 'deferral', 'accrued_wages', 100], ['E2', 29, 'regular', 'rent', -40], ['E3', 25, 'deferral', 'rent', -100]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_wages': 100, 'rent': -140}}], ['control 4', {'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}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 100], ['E1', 30, 'deferral', 'accrued_wages', 250], ['E2', 30, 'regular', 'cash', 250], ['E3', 27, 'regular', 'accrued_interest', -40]], 'as_of': 29}, {'reversals': [], 'balances': {'accrued_interest': -40}}], ['control 6', {'period_end': 28, 'entries': [['E0', 27, 'deferral', 'rent', 100], ['E1', 27, 'deferral', 'accrued_wages', 700], ['E2', 5, 'regular', 'rent', 700], ['E3', 30, 'deferral', 'accrued_wages', -40]], 'as_of': 30}, {'reversals': [], 'balances': {'rent': 800, 'accrued_wages': 660}}]], [['regression: reversal sign', {'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: reversal sign, partial-repair probe', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 100], ['E1', 32, 'deferral', 'rent', -40], ['E2', 29, 'accrual', 'accrued_interest', -40], ['E3', 27, 'accrual', 'accrued_wages', 250], ['E4', 30, 'accrual', 'accrued_wages', -100], ['E5', 30, 'accrual', 'accrued_interest', 100], ['E6', 31, 'accrual', 'cash', 250]], 'as_of': 31}, {'reversals': [['R-E2', 31, 40], ['R-E3', 31, -250], ['R-E4', 31, 100], ['R-E5', 31, -100]], 'balances': {'accrued_wages': 100, 'accrued_interest': 0, 'cash': 250}}], ['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': 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': 31, 'entries': [['E0', 32, 'accrual', 'accrued_wages', 100], ['E1', 33, 'deferral', 'cash', 100], ['E2', 30, 'regular', 'cash', 700], ['E3', 33, 'regular', 'rent', 700]], 'as_of': 33}, {'reversals': [], 'balances': {'accrued_wages': 100, 'cash': 800, 'rent': 700}}], ['control 4', {'period_end': 30, 'entries': [['E0', 29, 'deferral', 'accrued_wages', 100], ['E1', 5, 'deferral', 'accrued_interest', -100], ['E2', 30, 'regular', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [], 'balances': {'accrued_wages': 800, 'accrued_interest': -100}}], ['control 5', {'period_end': 30, 'entries': [['E0', 31, 'regular', 'accrued_interest', -100], ['E1', 27, 'regular', 'rent', 250], ['E2', 31, 'deferral', 'accrued_wages', 250], ['E3', 31, 'regular', 'accrued_interest', 100], ['E4', 27, 'deferral', 'accrued_interest', 100], ['E5', 29, 'regular', 'accrued_interest', 100], ['E6', 32, 'accrual', 'cash', 250]], 'as_of': 32}, {'reversals': [], 'balances': {'accrued_interest': 200, 'rent': 250, 'accrued_wages': 250, 'cash': 250}}]]]
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:
Reversal entries double the accrual instead of cancelling it.

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 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: reversible kind filter', {'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}}], ['regression: reversible kind filter, partial-repair probe', {'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 1', {'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}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'accrued_interest', 100], ['E1', 29, 'deferral', 'rent', -40], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 30, 'deferral', 'accrued_wages', -40], ['E4', 28, 'accrual', 'accrued_wages', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -100], ['R-E2', 29, 40], ['R-E4', 29, -100]], 'balances': {'accrued_interest': 0, 'rent': -40, 'accrued_wages': 0}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_interest', 250], ['E1', 30, 'accrual', 'accrued_wages', 100], ['E2', 31, 'accrual', 'accrued_interest', 100], ['E3', 30, 'accrual', 'cash', 100]], 'as_of': 30}, {'reversals': [['R-E1', 31, -100], ['R-E3', 31, -100]], 'balances': {'accrued_wages': 100, 'cash': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'accrual', 'rent', 250], ['E1', 32, 'accrual', 'accrued_wages', -100], ['E2', 32, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E0', 32, -250]], 'balances': {'rent': 0, 'accrued_wages': -100, 'accrued_interest': -100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'accrual', 'cash', -40], ['E1', 5, 'accrual', 'accrued_wages', 100], ['E2', 33, 'accrual', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [['R-E0', 32, 40], ['R-E1', 32, -100]], 'balances': {'cash': -40, 'accrued_wages': 100}}]], [['regression: reversible kind filter', {'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 1', {'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}}], ['control 2', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'rent', -40], ['E1', 30, 'accrual', 'rent', -40], ['E2', 32, 'regular', 'rent', 250]], 'as_of': 30}, {'reversals': [['R-E0', 31, 40], ['R-E1', 31, 40]], 'balances': {'rent': -80}}], ['control 3', {'period_end': 31, 'entries': [['E0', 32, 'accrual', 'accrued_wages', -40], ['E1', 32, 'accrual', 'accrued_wages', 250], ['E2', 33, 'accrual', 'accrued_wages', 100], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 32, 'accrual', 'cash', 100]], 'as_of': 33}, {'reversals': [['R-E3', 32, -100]], 'balances': {'accrued_wages': 310, 'accrued_interest': 0, 'cash': 100}}], ['control 4', {'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}}], ['control 5', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'cash', 700], ['E1', 27, 'accrual', 'cash', 100], ['E2', 31, 'accrual', 'rent', -40], ['E3', 32, 'accrual', 'rent', 700]], 'as_of': 30}, {'reversals': [['R-E0', 31, -700], ['R-E1', 31, -100]], 'balances': {'cash': 800}}], ['control 6', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_interest', 700], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'regular', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700], ['R-E1', 29, -100]], 'balances': {'accrued_interest': 700, 'rent': 100}}]], [['regression: reversible kind filter', {'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: reversible kind filter, 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', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}], ['control 2', {'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': {}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'regular', 'rent', -40], ['E1', 32, 'regular', 'cash', 250], ['E2', 32, 'accrual', 'accrued_interest', 100], ['E3', 31, 'accrual', 'accrued_wages', 100], ['E4', 32, 'regular', 'cash', 250], ['E5', 29, 'accrual', 'cash', -40], ['E6', 27, 'accrual', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E5', 31, 40], ['R-E6', 31, 100]], 'balances': {'cash': -40, 'accrued_wages': -100}}], ['control 4', {'period_end': 30, 'entries': [['E0', 5, 'accrual', 'accrued_wages', -100], ['E1', 32, 'regular', 'accrued_interest', 100], ['E2', 31, 'deferral', 'rent', -100]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {'accrued_wages': -100}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'accrued_interest', -100], ['E2', 29, 'accrual', 'accrued_interest', 700], ['E3', 30, 'regular', 'accrued_interest', -100], ['E4', 29, 'regular', 'accrued_wages', 250], ['E5', 29, 'accrual', 'accrued_interest', 700]], 'as_of': 29}, {'reversals': [['R-E1', 29, 100]], 'balances': {'accrued_interest': 1400, 'accrued_wages': 250}}]], [['regression: reversible kind filter', {'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: reversible kind filter, partial-repair probe', {'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': 30, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 100], ['E1', 31, 'accrual', 'accrued_interest', 100], ['E2', 31, 'accrual', 'rent', 100], ['E3', 5, 'accrual', 'accrued_interest', -40], ['E4', 31, 'regular', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [['R-E0', 31, -100], ['R-E3', 31, 40]], 'balances': {'accrued_interest': 60}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 100], ['E1', 5, 'accrual', 'accrued_interest', 700], ['E2', 30, 'accrual', 'cash', -100], ['E3', 28, 'accrual', 'accrued_interest', -100], ['E4', 25, 'accrual', 'rent', 700], ['E5', 29, 'regular', 'cash', -100], ['E6', 30, 'accrual', 'accrued_wages', -100]], 'as_of': 27}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -700], ['R-E3', 29, 100], ['R-E4', 29, -700]], 'balances': {'accrued_wages': 100, 'accrued_interest': 700, 'rent': 700}}], ['control 3', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'rent', -100], ['E1', 31, 'deferral', 'cash', 700], ['E2', 5, 'accrual', 'accrued_wages', 100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -100]], 'balances': {'accrued_wages': 100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'accrued_wages', 700], ['E2', 5, 'accrual', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, -100], ['R-E2', 29, 40]], 'balances': {'rent': -40}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', 100], ['E1', 29, 'accrual', 'accrued_wages', 100], ['E2', 29, 'accrual', 'cash', 250], ['E3', 29, 'deferral', 'cash', 100]], 'as_of': 28}, {'reversals': [], 'balances': {}}]], [['regression: reversible kind filter', {'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: reversible kind filter, partial-repair probe', {'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 1', {'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 2', {'period_end': 30, 'entries': [['E0', 27, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'rent', 100], ['E2', 5, 'accrual', 'accrued_interest', 700]], 'as_of': 31}, {'reversals': [['R-E0', 31, -700], ['R-E1', 31, -100], ['R-E2', 31, -700]], 'balances': {'rent': 0, 'accrued_interest': 0}}], ['control 3', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'accrued_wages', 700], ['E1', 31, 'regular', 'accrued_interest', 700], ['E2', 30, 'accrual', 'rent', 100], ['E3', 31, 'accrual', 'accrued_interest', 700], ['E4', 5, 'accrual', 'accrued_interest', 700], ['E5', 32, 'regular', 'cash', -100], ['E6', 30, 'accrual', 'rent', 100]], 'as_of': 31}, {'reversals': [['R-E0', 31, -700], ['R-E2', 31, -100], ['R-E4', 31, -700], ['R-E6', 31, -100]], 'balances': {'accrued_wages': 0, 'accrued_interest': 1400, 'rent': 0}}], ['control 4', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', -100], ['E1', 30, 'accrual', 'rent', 250], ['E2', 28, 'accrual', 'rent', 250], ['E3', 29, 'regular', 'rent', 250]], 'as_of': 28}, {'reversals': [['R-E2', 29, -250]], 'balances': {'rent': 250}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'deferral', 'rent', -100], ['E1', 25, 'accrual', 'accrued_interest', 100], ['E2', 27, 'accrual', 'cash', -100], ['E3', 5, 'accrual', 'accrued_interest', -40]], 'as_of': 27}, {'reversals': [['R-E1', 29, -100], ['R-E2', 29, 100], ['R-E3', 29, 40]], 'balances': {'accrued_interest': 60, 'cash': -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 != 'regular' 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: reversible kind filter', {'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}}], ['regression: reversible kind filter, partial-repair probe', {'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 1', {'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}}], ['control 2', {'period_end': 28, 'entries': [['E0', 5, 'accrual', 'accrued_interest', 100], ['E1', 29, 'deferral', 'rent', -40], ['E2', 5, 'accrual', 'accrued_wages', -40], ['E3', 30, 'deferral', 'accrued_wages', -40], ['E4', 28, 'accrual', 'accrued_wages', 100]], 'as_of': 29}, {'reversals': [['R-E0', 29, -100], ['R-E2', 29, 40], ['R-E4', 29, -100]], 'balances': {'accrued_interest': 0, 'rent': -40, 'accrued_wages': 0}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'deferral', 'accrued_interest', 250], ['E1', 30, 'accrual', 'accrued_wages', 100], ['E2', 31, 'accrual', 'accrued_interest', 100], ['E3', 30, 'accrual', 'cash', 100]], 'as_of': 30}, {'reversals': [['R-E1', 31, -100], ['R-E3', 31, -100]], 'balances': {'accrued_wages': 100, 'cash': 100}}], ['control 4', {'period_end': 31, 'entries': [['E0', 31, 'accrual', 'rent', 250], ['E1', 32, 'accrual', 'accrued_wages', -100], ['E2', 32, 'accrual', 'accrued_interest', -100]], 'as_of': 33}, {'reversals': [['R-E0', 32, -250]], 'balances': {'rent': 0, 'accrued_wages': -100, 'accrued_interest': -100}}], ['control 5', {'period_end': 31, 'entries': [['E0', 31, 'accrual', 'cash', -40], ['E1', 5, 'accrual', 'accrued_wages', 100], ['E2', 33, 'accrual', 'accrued_interest', 100]], 'as_of': 31}, {'reversals': [['R-E0', 32, 40], ['R-E1', 32, -100]], 'balances': {'cash': -40, 'accrued_wages': 100}}]], [['regression: reversible kind filter', {'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 1', {'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}}], ['control 2', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'rent', -40], ['E1', 30, 'accrual', 'rent', -40], ['E2', 32, 'regular', 'rent', 250]], 'as_of': 30}, {'reversals': [['R-E0', 31, 40], ['R-E1', 31, 40]], 'balances': {'rent': -80}}], ['control 3', {'period_end': 31, 'entries': [['E0', 32, 'accrual', 'accrued_wages', -40], ['E1', 32, 'accrual', 'accrued_wages', 250], ['E2', 33, 'accrual', 'accrued_wages', 100], ['E3', 28, 'accrual', 'accrued_interest', 100], ['E4', 32, 'accrual', 'cash', 100]], 'as_of': 33}, {'reversals': [['R-E3', 32, -100]], 'balances': {'accrued_wages': 310, 'accrued_interest': 0, 'cash': 100}}], ['control 4', {'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}}], ['control 5', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'cash', 700], ['E1', 27, 'accrual', 'cash', 100], ['E2', 31, 'accrual', 'rent', -40], ['E3', 32, 'accrual', 'rent', 700]], 'as_of': 30}, {'reversals': [['R-E0', 31, -700], ['R-E1', 31, -100]], 'balances': {'cash': 800}}], ['control 6', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_interest', 700], ['E1', 5, 'accrual', 'rent', 100], ['E2', 30, 'regular', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, -700], ['R-E1', 29, -100]], 'balances': {'accrued_interest': 700, 'rent': 100}}]], [['regression: reversible kind filter', {'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: reversible kind filter, 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', 30, 'accrual', 'rent', -100], ['E1', 31, 'regular', 'rent', 700], ['E2', 32, 'deferral', 'cash', 250]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {}}], ['control 2', {'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': {}}], ['control 3', {'period_end': 30, 'entries': [['E0', 32, 'regular', 'rent', -40], ['E1', 32, 'regular', 'cash', 250], ['E2', 32, 'accrual', 'accrued_interest', 100], ['E3', 31, 'accrual', 'accrued_wages', 100], ['E4', 32, 'regular', 'cash', 250], ['E5', 29, 'accrual', 'cash', -40], ['E6', 27, 'accrual', 'accrued_wages', -100]], 'as_of': 29}, {'reversals': [['R-E5', 31, 40], ['R-E6', 31, 100]], 'balances': {'cash': -40, 'accrued_wages': -100}}], ['control 4', {'period_end': 30, 'entries': [['E0', 5, 'accrual', 'accrued_wages', -100], ['E1', 32, 'regular', 'accrued_interest', 100], ['E2', 31, 'deferral', 'rent', -100]], 'as_of': 29}, {'reversals': [['R-E0', 31, 100]], 'balances': {'accrued_wages': -100}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'deferral', 'accrued_wages', 700], ['E1', 28, 'accrual', 'accrued_interest', -100], ['E2', 29, 'accrual', 'accrued_interest', 700], ['E3', 30, 'regular', 'accrued_interest', -100], ['E4', 29, 'regular', 'accrued_wages', 250], ['E5', 29, 'accrual', 'accrued_interest', 700]], 'as_of': 29}, {'reversals': [['R-E1', 29, 100]], 'balances': {'accrued_interest': 1400, 'accrued_wages': 250}}]], [['regression: reversible kind filter', {'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: reversible kind filter, partial-repair probe', {'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': 30, 'entries': [['E0', 30, 'accrual', 'accrued_interest', 100], ['E1', 31, 'accrual', 'accrued_interest', 100], ['E2', 31, 'accrual', 'rent', 100], ['E3', 5, 'accrual', 'accrued_interest', -40], ['E4', 31, 'regular', 'accrued_wages', 700]], 'as_of': 30}, {'reversals': [['R-E0', 31, -100], ['R-E3', 31, 40]], 'balances': {'accrued_interest': 60}}], ['control 2', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 100], ['E1', 5, 'accrual', 'accrued_interest', 700], ['E2', 30, 'accrual', 'cash', -100], ['E3', 28, 'accrual', 'accrued_interest', -100], ['E4', 25, 'accrual', 'rent', 700], ['E5', 29, 'regular', 'cash', -100], ['E6', 30, 'accrual', 'accrued_wages', -100]], 'as_of': 27}, {'reversals': [['R-E0', 29, -100], ['R-E1', 29, -700], ['R-E3', 29, 100], ['R-E4', 29, -700]], 'balances': {'accrued_wages': 100, 'accrued_interest': 700, 'rent': 700}}], ['control 3', {'period_end': 30, 'entries': [['E0', 31, 'accrual', 'rent', -100], ['E1', 31, 'deferral', 'cash', 700], ['E2', 5, 'accrual', 'accrued_wages', 100]], 'as_of': 29}, {'reversals': [['R-E2', 31, -100]], 'balances': {'accrued_wages': 100}}], ['control 4', {'period_end': 28, 'entries': [['E0', 28, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'accrued_wages', 700], ['E2', 5, 'accrual', 'rent', -40]], 'as_of': 27}, {'reversals': [['R-E0', 29, -100], ['R-E2', 29, 40]], 'balances': {'rent': -40}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'cash', 100], ['E1', 29, 'accrual', 'accrued_wages', 100], ['E2', 29, 'accrual', 'cash', 250], ['E3', 29, 'deferral', 'cash', 100]], 'as_of': 28}, {'reversals': [], 'balances': {}}]], [['regression: reversible kind filter', {'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: reversible kind filter, partial-repair probe', {'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 1', {'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 2', {'period_end': 30, 'entries': [['E0', 27, 'accrual', 'rent', 700], ['E1', 30, 'accrual', 'rent', 100], ['E2', 5, 'accrual', 'accrued_interest', 700]], 'as_of': 31}, {'reversals': [['R-E0', 31, -700], ['R-E1', 31, -100], ['R-E2', 31, -700]], 'balances': {'rent': 0, 'accrued_interest': 0}}], ['control 3', {'period_end': 30, 'entries': [['E0', 30, 'accrual', 'accrued_wages', 700], ['E1', 31, 'regular', 'accrued_interest', 700], ['E2', 30, 'accrual', 'rent', 100], ['E3', 31, 'accrual', 'accrued_interest', 700], ['E4', 5, 'accrual', 'accrued_interest', 700], ['E5', 32, 'regular', 'cash', -100], ['E6', 30, 'accrual', 'rent', 100]], 'as_of': 31}, {'reversals': [['R-E0', 31, -700], ['R-E2', 31, -100], ['R-E4', 31, -700], ['R-E6', 31, -100]], 'balances': {'accrued_wages': 0, 'accrued_interest': 1400, 'rent': 0}}], ['control 4', {'period_end': 28, 'entries': [['E0', 30, 'accrual', 'accrued_interest', -100], ['E1', 30, 'accrual', 'rent', 250], ['E2', 28, 'accrual', 'rent', 250], ['E3', 29, 'regular', 'rent', 250]], 'as_of': 28}, {'reversals': [['R-E2', 29, -250]], 'balances': {'rent': 250}}], ['control 5', {'period_end': 28, 'entries': [['E0', 30, 'deferral', 'rent', -100], ['E1', 25, 'accrual', 'accrued_interest', 100], ['E2', 27, 'accrual', 'cash', -100], ['E3', 5, 'accrual', 'accrued_interest', -40]], 'as_of': 27}, {'reversals': [['R-E1', 29, -100], ['R-E2', 29, 100], ['R-E3', 29, 40]], 'balances': {'accrued_interest': 60, 'cash': -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:
Ordinary cash postings are reversed at period start.

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': bal}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: accrual period cutoff', {'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 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': 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 4', {'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 5', {'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 6', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'cash', -100], ['E1', 31, 'regular', 'rent', -40], ['E2', 30, 'accrual', 'accrued_wages', 100], ['E3', 28, 'accrual', 'accrued_interest', -40], ['E4', 30, 'deferral', 'rent', 100]], 'as_of': 32}, {'reversals': [['R-E0', 32, 100], ['R-E2', 32, -100], ['R-E3', 32, 40]], 'balances': {'cash': 0, 'rent': 60, 'accrued_wages': 0, 'accrued_interest': 0}}]], [['regression: accrual period cutoff', {'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', 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}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 700], ['E1', 5, 'regular', 'accrued_wages', -40], ['E2', 29, 'accrual', 'rent', -40], ['E3', 28, 'regular', 'accrued_interest', -40]], 'as_of': 29}, {'reversals': [['R-E0', 29, -700]], 'balances': {'accrued_wages': -40, 'rent': -40, 'accrued_interest': -40}}], ['control 6', {'period_end': 31, 'entries': [['E0', 32, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'rent', 700], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 30}, {'reversals': [['R-E1', 32, -700]], 'balances': {'rent': 700, 'cash': -40}}]], [['regression: accrual period cutoff', {'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: accrual period cutoff, partial-repair probe', {'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}}], ['control 1', {'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 2', {'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 3', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'rent', -40], ['E1', 29, 'accrual', 'accrued_interest', 250], ['E2', 32, 'accrual', 'rent', -40]], 'as_of': 30}, {'reversals': [['R-E1', 31, -250]], 'balances': {'rent': -40, 'accrued_interest': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'cash', 100], ['E1', 5, 'regular', 'rent', 250], ['E2', 5, 'deferral', 'rent', 700], ['E3', 27, 'accrual', 'accrued_wages', -40], ['E4', 32, 'regular', 'accrued_wages', 250]], 'as_of': 30}, {'reversals': [['R-E0', 31, -100], ['R-E3', 31, 40]], 'balances': {'cash': 100, 'rent': 950, 'accrued_wages': -40}}], ['control 5', {'period_end': 31, 'entries': [['E0', 33, 'deferral', 'accrued_interest', 700], ['E1', 30, 'accrual', 'accrued_wages', -40], ['E2', 33, 'accrual', 'cash', 100], ['E3', 5, 'accrual', 'rent', 700], ['E4', 31, 'deferral', 'accrued_wages', -100]], 'as_of': 30}, {'reversals': [['R-E1', 32, 40], ['R-E3', 32, -700]], 'balances': {'accrued_wages': -40, 'rent': 700}}]], [['regression: accrual period cutoff', {'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}}], ['regression: accrual period cutoff, partial-repair probe', {'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 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', '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': 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 4', {'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}}], ['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}}]], [['regression: accrual period cutoff', {'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 1', {'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 2', {'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 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}}], ['control 6', {'period_end': 30, 'entries': [['E0', 31, 'regular', 'accrued_wages', 100], ['E1', 31, 'accrual', 'accrued_interest', -40], ['E2', 29, 'deferral', 'accrued_interest', 100], ['E3', 5, 'deferral', 'cash', 100], ['E4', 5, 'regular', 'cash', -40], ['E5', 5, 'accrual', 'accrued_interest', 250]], 'as_of': 29}, {'reversals': [['R-E5', 31, -250]], 'balances': {'accrued_interest': 350, 'cash': 60}}]]]
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':
            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: accrual period cutoff', {'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 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': 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 4', {'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 5', {'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 6', {'period_end': 31, 'entries': [['E0', 5, 'accrual', 'cash', -100], ['E1', 31, 'regular', 'rent', -40], ['E2', 30, 'accrual', 'accrued_wages', 100], ['E3', 28, 'accrual', 'accrued_interest', -40], ['E4', 30, 'deferral', 'rent', 100]], 'as_of': 32}, {'reversals': [['R-E0', 32, 100], ['R-E2', 32, -100], ['R-E3', 32, 40]], 'balances': {'cash': 0, 'rent': 60, 'accrued_wages': 0, 'accrued_interest': 0}}]], [['regression: accrual period cutoff', {'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', 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}}], ['control 5', {'period_end': 28, 'entries': [['E0', 27, 'accrual', 'accrued_wages', 700], ['E1', 5, 'regular', 'accrued_wages', -40], ['E2', 29, 'accrual', 'rent', -40], ['E3', 28, 'regular', 'accrued_interest', -40]], 'as_of': 29}, {'reversals': [['R-E0', 29, -700]], 'balances': {'accrued_wages': -40, 'rent': -40, 'accrued_interest': -40}}], ['control 6', {'period_end': 31, 'entries': [['E0', 32, 'accrual', 'accrued_interest', 100], ['E1', 30, 'accrual', 'rent', 700], ['E2', 30, 'regular', 'cash', -40]], 'as_of': 30}, {'reversals': [['R-E1', 32, -700]], 'balances': {'rent': 700, 'cash': -40}}]], [['regression: accrual period cutoff', {'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: accrual period cutoff, partial-repair probe', {'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}}], ['control 1', {'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 2', {'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 3', {'period_end': 30, 'entries': [['E0', 30, 'deferral', 'rent', -40], ['E1', 29, 'accrual', 'accrued_interest', 250], ['E2', 32, 'accrual', 'rent', -40]], 'as_of': 30}, {'reversals': [['R-E1', 31, -250]], 'balances': {'rent': -40, 'accrued_interest': 250}}], ['control 4', {'period_end': 30, 'entries': [['E0', 29, 'accrual', 'cash', 100], ['E1', 5, 'regular', 'rent', 250], ['E2', 5, 'deferral', 'rent', 700], ['E3', 27, 'accrual', 'accrued_wages', -40], ['E4', 32, 'regular', 'accrued_wages', 250]], 'as_of': 30}, {'reversals': [['R-E0', 31, -100], ['R-E3', 31, 40]], 'balances': {'cash': 100, 'rent': 950, 'accrued_wages': -40}}], ['control 5', {'period_end': 31, 'entries': [['E0', 33, 'deferral', 'accrued_interest', 700], ['E1', 30, 'accrual', 'accrued_wages', -40], ['E2', 33, 'accrual', 'cash', 100], ['E3', 5, 'accrual', 'rent', 700], ['E4', 31, 'deferral', 'accrued_wages', -100]], 'as_of': 30}, {'reversals': [['R-E1', 32, 40], ['R-E3', 32, -700]], 'balances': {'accrued_wages': -40, 'rent': 700}}]], [['regression: accrual period cutoff', {'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}}], ['regression: accrual period cutoff, partial-repair probe', {'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 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', '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': 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 4', {'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}}], ['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}}]], [['regression: accrual period cutoff', {'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 1', {'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 2', {'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 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}}], ['control 6', {'period_end': 30, 'entries': [['E0', 31, 'regular', 'accrued_wages', 100], ['E1', 31, 'accrual', 'accrued_interest', -40], ['E2', 29, 'deferral', 'accrued_interest', 100], ['E3', 5, 'deferral', 'cash', 100], ['E4', 5, 'regular', 'cash', -40], ['E5', 5, 'accrual', 'accrued_interest', 250]], 'as_of': 29}, {'reversals': [['R-E5', 31, -250]], 'balances': {'accrued_interest': 350, 'cash': 60}}]]]
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:
Accruals booked on the last day of the period are never reversed.

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