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

N = 1
observations = []
def solve(x):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: nonzero closing filter', {'accounts': {'reve_0': ['revenue', 1200], 'cont_1': ['contra_revenue', 3000], 'loss_2': ['loss', 3000], 'liab_3': ['liability', 400], 'loss_4': ['loss', -200], 'expe_5': ['expense', 0], 'divi_6': ['dividend', 3000], 'reve_7': ['revenue', 400], 'loss_8': ['loss', -200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4000, 'retained': -6000, 'aoci': 0, 'closed': ['cont_1', 'divi_6', 'loss_2', 'loss_4', 'loss_8', 'reve_0', 'reve_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 3', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 150], 'divi_1': ['dividend', 150], 'divi_2': ['dividend', -200], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -150, 'retained': 900, 'aoci': -100, 'closed': ['cont_0', 'divi_1', 'divi_2']}], ['control 5', {'accounts': {'divi_0': ['dividend', 7500], 'expe_1': ['expense', 150], 'divi_2': ['dividend', 7500], 'asse_3': ['asset', -200], 'loss_4': ['loss', 400], 'gain_5': ['gain', 3000]}, 'retained': -500, 'aoci': 0}, {'net_income': 2450, 'retained': -13050, 'aoci': 0, 'closed': ['divi_0', 'divi_2', 'expe_1', 'gain_5', 'loss_4']}], ['control 6', {'accounts': {'cont_0': ['contra_revenue', 400], 'liab_1': ['liability', 3000], 'loss_2': ['loss', 400], 'cont_3': ['contra_revenue', 150], 'gain_4': ['gain', -200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1150, 'retained': -150, 'aoci': 0, 'closed': ['cont_0', 'cont_3', 'gain_4', 'loss_2']}]], [['regression: nonzero closing filter', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 1', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 150], 'gain_1': ['gain', 7500], 'loss_2': ['loss', 400], 'divi_3': ['dividend', 7500], 'cont_4': ['contra_revenue', 150], 'liab_5': ['liability', 7500], 'asse_6': ['asset', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 6950, 'retained': 450, 'aoci': 150, 'closed': ['cont_4', 'divi_3', 'gain_1', 'loss_2', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', -200], 'reve_1': ['revenue', 1200], 'loss_2': ['loss', 7500], 'asse_3': ['asset', 0], 'divi_4': ['dividend', 150], 'liab_5': ['liability', 0], 'liab_6': ['liability', 3000], 'reve_7': ['revenue', 150]}, 'retained': 0, 'aoci': 0}, {'net_income': -6350, 'retained': -6500, 'aoci': 0, 'closed': ['divi_4', 'gain_0', 'loss_2', 'reve_1', 'reve_7']}], ['control 4', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}], ['control 5', {'accounts': {'reve_0': ['revenue', 1200], 'liab_1': ['liability', 150], 'gain_2': ['gain', 3000], 'expe_3': ['expense', 400], 'cont_4': ['contra_revenue', 1200], 'asse_5': ['asset', 3000]}, 'retained': 1000, 'aoci': 0}, {'net_income': 2600, 'retained': 3600, 'aoci': 0, 'closed': ['cont_4', 'expe_3', 'gain_2', 'reve_0']}], ['control 6', {'accounts': {'oci_0': ['oci', 7500], 'loss_1': ['loss', -200], 'asse_2': ['asset', 0], 'loss_3': ['loss', 150], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 400], 'reve_6': ['revenue', 400], 'gain_7': ['gain', 150], 'cont_8': ['contra_revenue', 7500]}, 'retained': 25000, 'aoci': -100}, {'net_income': -14800, 'retained': 10200, 'aoci': 7400, 'closed': ['cont_5', 'cont_8', 'gain_7', 'loss_1', 'loss_3', 'loss_4', 'oci_0', 'reve_6']}]], [['regression: nonzero closing filter', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 3', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 4', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 5', {'accounts': {'oci_0': ['oci', 7500], 'liab_1': ['liability', 7500], 'liab_2': ['liability', 0], 'asse_3': ['asset', 7500], 'liab_4': ['liability', 7500], 'gain_5': ['gain', 1200], 'divi_6': ['dividend', 7500], 'reve_7': ['revenue', 150], 'oci_8': ['oci', 7500]}, 'retained': 0, 'aoci': 0}, {'net_income': 1350, 'retained': -6150, 'aoci': 15000, 'closed': ['divi_6', 'gain_5', 'oci_0', 'oci_8', 'reve_7']}], ['control 6', {'accounts': {'cont_0': ['contra_revenue', 7500], 'reve_1': ['revenue', 1200], 'divi_2': ['dividend', 150], 'expe_3': ['expense', 150], 'oci_4': ['oci', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': -6450, 'retained': 18400, 'aoci': 1200, 'closed': ['cont_0', 'divi_2', 'expe_3', 'oci_4', 'reve_1']}]], [['regression: nonzero closing filter', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'divi_0': ['dividend', 150], 'divi_1': ['dividend', -200], 'asse_2': ['asset', 150], 'cont_3': ['contra_revenue', 400], 'gain_4': ['gain', 150]}, 'retained': 0, 'aoci': 300}, {'net_income': -250, 'retained': -200, 'aoci': 300, 'closed': ['cont_3', 'divi_0', 'divi_1', 'gain_4']}], ['control 4', {'accounts': {'reve_0': ['revenue', 150], 'asse_1': ['asset', 7500], 'oci_2': ['oci', 1200], 'reve_3': ['revenue', 400], 'divi_4': ['dividend', 150], 'gain_5': ['gain', 1200], 'liab_6': ['liability', -200], 'asse_7': ['asset', 150], 'divi_8': ['dividend', 7500]}, 'retained': 1000, 'aoci': 300}, {'net_income': 1750, 'retained': -4900, 'aoci': 1500, 'closed': ['divi_4', 'divi_8', 'gain_5', 'oci_2', 'reve_0', 'reve_3']}], ['control 5', {'accounts': {'divi_0': ['dividend', -200], 'loss_1': ['loss', 1200], 'loss_2': ['loss', -200], 'cont_3': ['contra_revenue', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 3000], 'divi_6': ['dividend', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -14500, 'retained': -15500, 'aoci': 0, 'closed': ['cont_3', 'cont_4', 'divi_0', 'divi_6', 'expe_5', 'loss_1', 'loss_2']}], ['control 6', {'accounts': {'asse_0': ['asset', 7500], 'divi_1': ['dividend', 400], 'liab_2': ['liability', 400], 'reve_3': ['revenue', 3000], 'gain_4': ['gain', 400], 'expe_5': ['expense', 3000], 'loss_6': ['loss', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -2600, 'retained': -2000, 'aoci': 300, 'closed': ['divi_1', 'expe_5', 'gain_4', 'loss_6', 'reve_3']}]], [['regression: nonzero closing filter', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['regression: nonzero closing filter, partial-repair probe', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 1', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 2', {'accounts': {'cont_0': ['contra_revenue', 3000], 'reve_1': ['revenue', 7500], 'asse_2': ['asset', 0], 'oci_3': ['oci', 150], 'liab_4': ['liability', 0], 'reve_5': ['revenue', 400], 'divi_6': ['dividend', 1200], 'reve_7': ['revenue', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': 6100, 'retained': 29900, 'aoci': 150, 'closed': ['cont_0', 'divi_6', 'oci_3', 'reve_1', 'reve_5', 'reve_7']}], ['control 3', {'accounts': {'asse_0': ['asset', 0], 'expe_1': ['expense', 1200], 'loss_2': ['loss', -200], 'divi_3': ['dividend', 1200], 'liab_4': ['liability', 0], 'asse_5': ['asset', 150], 'expe_6': ['expense', 400], 'asse_7': ['asset', 150]}, 'retained': 1000, 'aoci': -100}, {'net_income': -1400, 'retained': -1600, 'aoci': -100, 'closed': ['divi_3', 'expe_1', 'expe_6', 'loss_2']}], ['control 4', {'accounts': {'gain_0': ['gain', 3000], 'expe_1': ['expense', -200], 'asse_2': ['asset', 0], 'expe_3': ['expense', 150], 'asse_4': ['asset', 7500], 'gain_5': ['gain', 400], 'divi_6': ['dividend', 150], 'expe_7': ['expense', 3000], 'reve_8': ['revenue', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 600, 'retained': -50, 'aoci': 0, 'closed': ['divi_6', 'expe_1', 'expe_3', 'expe_7', 'gain_0', 'gain_5', 'reve_8']}], ['control 5', {'accounts': {'asse_0': ['asset', -200], 'expe_1': ['expense', 1200], 'liab_2': ['liability', 150], 'divi_3': ['dividend', 7500], 'asse_4': ['asset', -200], 'reve_5': ['revenue', 3000], 'divi_6': ['dividend', 400], 'reve_7': ['revenue', 1200]}, 'retained': -500, 'aoci': 0}, {'net_income': 3000, 'retained': -5400, 'aoci': 0, 'closed': ['divi_3', 'divi_6', 'expe_1', 'reve_5', 'reve_7']}]]]
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):
    acc = x['accounts']
    def total(kind):
        return sum(b for k, b in acc.values() if k == kind)
    rev = total('revenue')
    contra = total('contra_revenue')
    exp = total('expense')
    gain = total('gain')
    loss = total('loss')
    div = total('dividend')
    oci = total('oci')
    income_summary = rev - contra + gain - exp - loss
    retained = x['retained'] + income_summary - div
    aoci = x['aoci'] + oci
    temporary = ('revenue', 'contra_revenue', 'expense', 'gain', 'loss', 'dividend', 'oci')
    closed = sorted(n for n, (k, b) in acc.items() if k in temporary and b > 0)
    return {'net_income': income_summary, 'retained': retained, 'aoci': aoci, 'closed': closed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: nonzero closing filter', {'accounts': {'reve_0': ['revenue', 1200], 'cont_1': ['contra_revenue', 3000], 'loss_2': ['loss', 3000], 'liab_3': ['liability', 400], 'loss_4': ['loss', -200], 'expe_5': ['expense', 0], 'divi_6': ['dividend', 3000], 'reve_7': ['revenue', 400], 'loss_8': ['loss', -200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4000, 'retained': -6000, 'aoci': 0, 'closed': ['cont_1', 'divi_6', 'loss_2', 'loss_4', 'loss_8', 'reve_0', 'reve_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 150], 'oci_1': ['oci', 400], 'expe_2': ['expense', 7500], 'loss_3': ['loss', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -10500, 'retained': -9500, 'aoci': 450, 'closed': ['expe_2', 'loss_3', 'oci_0', 'oci_1']}], ['control 2', {'accounts': {'reve_0': ['revenue', 3000], 'oci_1': ['oci', 1200], 'divi_2': ['dividend', 400], 'expe_3': ['expense', 150]}, 'retained': 0, 'aoci': -100}, {'net_income': 2850, 'retained': 2450, 'aoci': 1100, 'closed': ['divi_2', 'expe_3', 'oci_1', 'reve_0']}], ['control 3', {'accounts': {'asse_0': ['asset', 400], 'gain_1': ['gain', 150], 'reve_2': ['revenue', 7500], 'gain_3': ['gain', 7500], 'asse_4': ['asset', 3000], 'reve_5': ['revenue', 3000], 'expe_6': ['expense', 400], 'reve_7': ['revenue', 400], 'reve_8': ['revenue', 3000]}, 'retained': 25000, 'aoci': 300}, {'net_income': 21150, 'retained': 46150, 'aoci': 300, 'closed': ['expe_6', 'gain_1', 'gain_3', 'reve_2', 'reve_5', 'reve_7', 'reve_8']}], ['control 4', {'accounts': {'cont_0': ['contra_revenue', 150], 'divi_1': ['dividend', 150], 'divi_2': ['dividend', -200], 'asse_3': ['asset', 3000]}, 'retained': 1000, 'aoci': -100}, {'net_income': -150, 'retained': 900, 'aoci': -100, 'closed': ['cont_0', 'divi_1', 'divi_2']}], ['control 5', {'accounts': {'divi_0': ['dividend', 7500], 'expe_1': ['expense', 150], 'divi_2': ['dividend', 7500], 'asse_3': ['asset', -200], 'loss_4': ['loss', 400], 'gain_5': ['gain', 3000]}, 'retained': -500, 'aoci': 0}, {'net_income': 2450, 'retained': -13050, 'aoci': 0, 'closed': ['divi_0', 'divi_2', 'expe_1', 'gain_5', 'loss_4']}], ['control 6', {'accounts': {'cont_0': ['contra_revenue', 400], 'liab_1': ['liability', 3000], 'loss_2': ['loss', 400], 'cont_3': ['contra_revenue', 150], 'gain_4': ['gain', -200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -1150, 'retained': -150, 'aoci': 0, 'closed': ['cont_0', 'cont_3', 'gain_4', 'loss_2']}]], [['regression: nonzero closing filter', {'accounts': {'asse_0': ['asset', 7500], 'expe_1': ['expense', 7500], 'gain_2': ['gain', 400], 'loss_3': ['loss', 0], 'liab_4': ['liability', 400], 'oci_5': ['oci', -200], 'cont_6': ['contra_revenue', 150], 'oci_7': ['oci', -200]}, 'retained': 25000, 'aoci': 300}, {'net_income': -7250, 'retained': 17750, 'aoci': -100, 'closed': ['cont_6', 'expe_1', 'gain_2', 'oci_5', 'oci_7']}], ['control 1', {'accounts': {'reve_0': ['revenue', 1200], 'expe_1': ['expense', 7500], 'asse_2': ['asset', -200], 'cont_3': ['contra_revenue', 7500], 'cont_4': ['contra_revenue', 7500], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 3000], 'cont_7': ['contra_revenue', 7500]}, 'retained': 0, 'aoci': -100}, {'net_income': -28800, 'retained': -39300, 'aoci': -100, 'closed': ['cont_3', 'cont_4', 'cont_7', 'divi_5', 'divi_6', 'expe_1', 'reve_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 150], 'gain_1': ['gain', 7500], 'loss_2': ['loss', 400], 'divi_3': ['dividend', 7500], 'cont_4': ['contra_revenue', 150], 'liab_5': ['liability', 7500], 'asse_6': ['asset', 150]}, 'retained': 1000, 'aoci': 0}, {'net_income': 6950, 'retained': 450, 'aoci': 150, 'closed': ['cont_4', 'divi_3', 'gain_1', 'loss_2', 'oci_0']}], ['control 3', {'accounts': {'gain_0': ['gain', -200], 'reve_1': ['revenue', 1200], 'loss_2': ['loss', 7500], 'asse_3': ['asset', 0], 'divi_4': ['dividend', 150], 'liab_5': ['liability', 0], 'liab_6': ['liability', 3000], 'reve_7': ['revenue', 150]}, 'retained': 0, 'aoci': 0}, {'net_income': -6350, 'retained': -6500, 'aoci': 0, 'closed': ['divi_4', 'gain_0', 'loss_2', 'reve_1', 'reve_7']}], ['control 4', {'accounts': {'loss_0': ['loss', 1200], 'cont_1': ['contra_revenue', 3000], 'reve_2': ['revenue', 1200], 'expe_3': ['expense', 7500], 'reve_4': ['revenue', 400], 'liab_5': ['liability', 400]}, 'retained': -500, 'aoci': 300}, {'net_income': -10100, 'retained': -10600, 'aoci': 300, 'closed': ['cont_1', 'expe_3', 'loss_0', 'reve_2', 'reve_4']}], ['control 5', {'accounts': {'reve_0': ['revenue', 1200], 'liab_1': ['liability', 150], 'gain_2': ['gain', 3000], 'expe_3': ['expense', 400], 'cont_4': ['contra_revenue', 1200], 'asse_5': ['asset', 3000]}, 'retained': 1000, 'aoci': 0}, {'net_income': 2600, 'retained': 3600, 'aoci': 0, 'closed': ['cont_4', 'expe_3', 'gain_2', 'reve_0']}], ['control 6', {'accounts': {'oci_0': ['oci', 7500], 'loss_1': ['loss', -200], 'asse_2': ['asset', 0], 'loss_3': ['loss', 150], 'loss_4': ['loss', 7500], 'cont_5': ['contra_revenue', 400], 'reve_6': ['revenue', 400], 'gain_7': ['gain', 150], 'cont_8': ['contra_revenue', 7500]}, 'retained': 25000, 'aoci': -100}, {'net_income': -14800, 'retained': 10200, 'aoci': 7400, 'closed': ['cont_5', 'cont_8', 'gain_7', 'loss_1', 'loss_3', 'loss_4', 'oci_0', 'reve_6']}]], [['regression: nonzero closing filter', {'accounts': {'reve_0': ['revenue', 400], 'gain_1': ['gain', 0], 'liab_2': ['liability', 400], 'gain_3': ['gain', -200], 'asse_4': ['asset', 0], 'divi_5': ['dividend', 400]}, 'retained': 0, 'aoci': 300}, {'net_income': 200, 'retained': -200, 'aoci': 300, 'closed': ['divi_5', 'gain_3', 'reve_0']}], ['control 1', {'accounts': {'cont_0': ['contra_revenue', -200], 'expe_1': ['expense', -200], 'liab_2': ['liability', 0], 'asse_3': ['asset', 3000], 'gain_4': ['gain', 1200], 'gain_5': ['gain', 150], 'liab_6': ['liability', 1200], 'gain_7': ['gain', 400], 'liab_8': ['liability', 0]}, 'retained': 25000, 'aoci': -100}, {'net_income': 2150, 'retained': 27150, 'aoci': -100, 'closed': ['cont_0', 'expe_1', 'gain_4', 'gain_5', 'gain_7']}], ['control 2', {'accounts': {'liab_0': ['liability', 1200], 'cont_1': ['contra_revenue', 400], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 400], 'liab_4': ['liability', 1200], 'expe_5': ['expense', 400], 'asse_6': ['asset', 3000], 'oci_7': ['oci', 3000]}, 'retained': 0, 'aoci': 0}, {'net_income': -2400, 'retained': -2400, 'aoci': 3000, 'closed': ['cont_1', 'expe_2', 'expe_5', 'loss_3', 'oci_7']}], ['control 3', {'accounts': {'reve_0': ['revenue', 3000], 'liab_1': ['liability', -200], 'asse_2': ['asset', 7500], 'asse_3': ['asset', 0]}, 'retained': -500, 'aoci': -100}, {'net_income': 3000, 'retained': 2500, 'aoci': -100, 'closed': ['reve_0']}], ['control 4', {'accounts': {'expe_0': ['expense', -200], 'cont_1': ['contra_revenue', 1200], 'cont_2': ['contra_revenue', 1200], 'liab_3': ['liability', -200], 'cont_4': ['contra_revenue', 1200], 'oci_5': ['oci', 400], 'reve_6': ['revenue', -200], 'liab_7': ['liability', -200], 'loss_8': ['loss', 1200]}, 'retained': 1000, 'aoci': 0}, {'net_income': -4800, 'retained': -3800, 'aoci': 400, 'closed': ['cont_1', 'cont_2', 'cont_4', 'expe_0', 'loss_8', 'oci_5', 'reve_6']}], ['control 5', {'accounts': {'oci_0': ['oci', 7500], 'liab_1': ['liability', 7500], 'liab_2': ['liability', 0], 'asse_3': ['asset', 7500], 'liab_4': ['liability', 7500], 'gain_5': ['gain', 1200], 'divi_6': ['dividend', 7500], 'reve_7': ['revenue', 150], 'oci_8': ['oci', 7500]}, 'retained': 0, 'aoci': 0}, {'net_income': 1350, 'retained': -6150, 'aoci': 15000, 'closed': ['divi_6', 'gain_5', 'oci_0', 'oci_8', 'reve_7']}], ['control 6', {'accounts': {'cont_0': ['contra_revenue', 7500], 'reve_1': ['revenue', 1200], 'divi_2': ['dividend', 150], 'expe_3': ['expense', 150], 'oci_4': ['oci', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': -6450, 'retained': 18400, 'aoci': 1200, 'closed': ['cont_0', 'divi_2', 'expe_3', 'oci_4', 'reve_1']}]], [['regression: nonzero closing filter', {'accounts': {'liab_0': ['liability', 0], 'expe_1': ['expense', 150], 'gain_2': ['gain', 0], 'liab_3': ['liability', 1200], 'gain_4': ['gain', -200], 'divi_5': ['dividend', 7500], 'divi_6': ['dividend', 1200], 'oci_7': ['oci', -200], 'asse_8': ['asset', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': -350, 'retained': -9050, 'aoci': 100, 'closed': ['divi_5', 'divi_6', 'expe_1', 'gain_4', 'oci_7']}], ['control 1', {'accounts': {'oci_0': ['oci', 1200], 'liab_1': ['liability', 3000], 'expe_2': ['expense', 1200], 'loss_3': ['loss', 3000], 'liab_4': ['liability', 1200], 'loss_5': ['loss', 150], 'asse_6': ['asset', -200]}, 'retained': -500, 'aoci': 300}, {'net_income': -4350, 'retained': -4850, 'aoci': 1500, 'closed': ['expe_2', 'loss_3', 'loss_5', 'oci_0']}], ['control 2', {'accounts': {'oci_0': ['oci', 400], 'liab_1': ['liability', 1200], 'asse_2': ['asset', 7500], 'expe_3': ['expense', 3000], 'asse_4': ['asset', 400], 'liab_5': ['liability', 3000], 'liab_6': ['liability', 7500]}, 'retained': -500, 'aoci': -100}, {'net_income': -3000, 'retained': -3500, 'aoci': 300, 'closed': ['expe_3', 'oci_0']}], ['control 3', {'accounts': {'divi_0': ['dividend', 150], 'divi_1': ['dividend', -200], 'asse_2': ['asset', 150], 'cont_3': ['contra_revenue', 400], 'gain_4': ['gain', 150]}, 'retained': 0, 'aoci': 300}, {'net_income': -250, 'retained': -200, 'aoci': 300, 'closed': ['cont_3', 'divi_0', 'divi_1', 'gain_4']}], ['control 4', {'accounts': {'reve_0': ['revenue', 150], 'asse_1': ['asset', 7500], 'oci_2': ['oci', 1200], 'reve_3': ['revenue', 400], 'divi_4': ['dividend', 150], 'gain_5': ['gain', 1200], 'liab_6': ['liability', -200], 'asse_7': ['asset', 150], 'divi_8': ['dividend', 7500]}, 'retained': 1000, 'aoci': 300}, {'net_income': 1750, 'retained': -4900, 'aoci': 1500, 'closed': ['divi_4', 'divi_8', 'gain_5', 'oci_2', 'reve_0', 'reve_3']}], ['control 5', {'accounts': {'divi_0': ['dividend', -200], 'loss_1': ['loss', 1200], 'loss_2': ['loss', -200], 'cont_3': ['contra_revenue', 3000], 'cont_4': ['contra_revenue', 7500], 'expe_5': ['expense', 3000], 'divi_6': ['dividend', 1200]}, 'retained': 0, 'aoci': 0}, {'net_income': -14500, 'retained': -15500, 'aoci': 0, 'closed': ['cont_3', 'cont_4', 'divi_0', 'divi_6', 'expe_5', 'loss_1', 'loss_2']}], ['control 6', {'accounts': {'asse_0': ['asset', 7500], 'divi_1': ['dividend', 400], 'liab_2': ['liability', 400], 'reve_3': ['revenue', 3000], 'gain_4': ['gain', 400], 'expe_5': ['expense', 3000], 'loss_6': ['loss', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -2600, 'retained': -2000, 'aoci': 300, 'closed': ['divi_1', 'expe_5', 'gain_4', 'loss_6', 'reve_3']}]], [['regression: nonzero closing filter', {'accounts': {'oci_0': ['oci', 0], 'gain_1': ['gain', 0], 'oci_2': ['oci', 3000], 'expe_3': ['expense', 150], 'loss_4': ['loss', 150], 'divi_5': ['dividend', 150], 'cont_6': ['contra_revenue', 1200], 'expe_7': ['expense', 7500]}, 'retained': -500, 'aoci': 300}, {'net_income': -9000, 'retained': -9650, 'aoci': 3300, 'closed': ['cont_6', 'divi_5', 'expe_3', 'expe_7', 'loss_4', 'oci_2']}], ['regression: nonzero closing filter, partial-repair probe', {'accounts': {'gain_0': ['gain', 400], 'reve_1': ['revenue', 1200], 'reve_2': ['revenue', 400], 'expe_3': ['expense', 3000], 'oci_4': ['oci', -200], 'reve_5': ['revenue', -200], 'gain_6': ['gain', 3000], 'reve_7': ['revenue', -200]}, 'retained': 0, 'aoci': 300}, {'net_income': 1600, 'retained': 1600, 'aoci': 100, 'closed': ['expe_3', 'gain_0', 'gain_6', 'oci_4', 'reve_1', 'reve_2', 'reve_5', 'reve_7']}], ['control 1', {'accounts': {'liab_0': ['liability', 3000], 'gain_1': ['gain', -200], 'reve_2': ['revenue', -200], 'oci_3': ['oci', 150], 'oci_4': ['oci', 3000], 'oci_5': ['oci', 3000], 'cont_6': ['contra_revenue', 3000]}, 'retained': 1000, 'aoci': 300}, {'net_income': -3400, 'retained': -2400, 'aoci': 6450, 'closed': ['cont_6', 'gain_1', 'oci_3', 'oci_4', 'oci_5', 'reve_2']}], ['control 2', {'accounts': {'cont_0': ['contra_revenue', 3000], 'reve_1': ['revenue', 7500], 'asse_2': ['asset', 0], 'oci_3': ['oci', 150], 'liab_4': ['liability', 0], 'reve_5': ['revenue', 400], 'divi_6': ['dividend', 1200], 'reve_7': ['revenue', 1200]}, 'retained': 25000, 'aoci': 0}, {'net_income': 6100, 'retained': 29900, 'aoci': 150, 'closed': ['cont_0', 'divi_6', 'oci_3', 'reve_1', 'reve_5', 'reve_7']}], ['control 3', {'accounts': {'asse_0': ['asset', 0], 'expe_1': ['expense', 1200], 'loss_2': ['loss', -200], 'divi_3': ['dividend', 1200], 'liab_4': ['liability', 0], 'asse_5': ['asset', 150], 'expe_6': ['expense', 400], 'asse_7': ['asset', 150]}, 'retained': 1000, 'aoci': -100}, {'net_income': -1400, 'retained': -1600, 'aoci': -100, 'closed': ['divi_3', 'expe_1', 'expe_6', 'loss_2']}], ['control 4', {'accounts': {'gain_0': ['gain', 3000], 'expe_1': ['expense', -200], 'asse_2': ['asset', 0], 'expe_3': ['expense', 150], 'asse_4': ['asset', 7500], 'gain_5': ['gain', 400], 'divi_6': ['dividend', 150], 'expe_7': ['expense', 3000], 'reve_8': ['revenue', 150]}, 'retained': -500, 'aoci': 0}, {'net_income': 600, 'retained': -50, 'aoci': 0, 'closed': ['divi_6', 'expe_1', 'expe_3', 'expe_7', 'gain_0', 'gain_5', 'reve_8']}], ['control 5', {'accounts': {'asse_0': ['asset', -200], 'expe_1': ['expense', 1200], 'liab_2': ['liability', 150], 'divi_3': ['dividend', 7500], 'asse_4': ['asset', -200], 'reve_5': ['revenue', 3000], 'divi_6': ['dividend', 400], 'reve_7': ['revenue', 1200]}, 'retained': -500, 'aoci': 0}, {'net_income': 3000, 'retained': -5400, 'aoci': 0, 'closed': ['divi_3', 'divi_6', 'expe_1', 'reve_5', 'reve_7']}]]]
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:
Zero-balance temporary accounts receive pointless closing entries.

x = {'accounts': {name: [type, normal-signed balance]}, 'retained': opening retained earnings, 'aoci': opening accumulated OCI}. Temporary types are revenue, contra_revenue, expense, gain, loss, dividend and oci. Income summary = revenue - contra_revenue + gain - expense - loss and is net income. Retained earnings close = opening + net income - dividends. OCI closes to AOCI, never to income or retained earnings. 'closed' lists temporary accounts with a nonzero balance (including abnormal negative ones), sorted. Return {'net_income', 'retained', 'aoci', 'closed'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bank = x['bank']
    book = x['book']
    entries = []
    for item in x['items']:
        kind = item[0]
        if kind == 'deposit_in_transit':
            bank += item[1]
        elif kind == 'outstanding_check':
            bank += item[1]
        elif kind == 'bank_error':
            bank += item[1]
        else:
            if kind == 'bank_fee' or kind == 'nsf':
                adj = -item[1]
            elif kind == 'interest':
                adj = item[1]
            elif kind == 'collection':
                adj = item[1] - item[2]
            elif kind == 'check_error':
                adj = item[1] - item[2]
            else:
                continue
            book += adj
            entries.append([kind, adj])
    return {'adjusted_bank': bank, 'adjusted_book': book, 'reconciled': bank == book, 'entries': entries}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: outstanding check side', {'bank': 8000, 'book': 10000, 'items': [['nsf', 400], ['memo', 90], ['bank_fee', 15], ['bank_fee', 1200], ['check_error', 1200, 1020], ['outstanding_check', 250]]}, {'adjusted_bank': 7750, 'adjusted_book': 8565, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 180]]}], ['control 1', {'bank': 10000, 'book': 10000, 'items': [['bank_fee', 90], ['interest', 15], ['bank_error', 1200], ['nsf', 1200], ['memo', 250], ['memo', 1200]]}, {'adjusted_bank': 11200, 'adjusted_book': 8725, 'reconciled': False, 'entries': [['bank_fee', -90], ['interest', 15], ['nsf', -1200]]}], ['control 2', {'bank': 8000, 'book': 9000, 'items': [['interest', 15], ['bank_fee', 400], ['check_error', 2100, 450]]}, {'adjusted_bank': 8000, 'adjusted_book': 10265, 'reconciled': False, 'entries': [['interest', 15], ['bank_fee', -400], ['check_error', 1650]]}], ['control 3', {'bank': 8000, 'book': 9000, 'items': [['memo', 15], ['check_error', 540, 450], ['bank_error', 400], ['interest', 15], ['bank_fee', 90]]}, {'adjusted_bank': 8400, 'adjusted_book': 9015, 'reconciled': False, 'entries': [['check_error', 90], ['interest', 15], ['bank_fee', -90]]}], ['control 4', {'bank': 10000, 'book': 10000, 'items': [['deposit_in_transit', 1200], ['deposit_in_transit', 400], ['bank_fee', 90], ['bank_fee', 1200], ['deposit_in_transit', 400]]}, {'adjusted_bank': 12000, 'adjusted_book': 8710, 'reconciled': False, 'entries': [['bank_fee', -90], ['bank_fee', -1200]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['interest', 1200], ['bank_error', 400], ['interest', 400], ['bank_error', 250], ['interest', 400]]}, {'adjusted_bank': 8650, 'adjusted_book': 11000, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 400], ['interest', 400]]}], ['control 6', {'bank': 8000, 'book': 10000, 'items': [['bank_fee', 250], ['deposit_in_transit', 250], ['check_error', 2100, 450], ['deposit_in_transit', 90], ['check_error', 540, 2010], ['deposit_in_transit', 90], ['collection', 2500, 15]]}, {'adjusted_bank': 8430, 'adjusted_book': 12415, 'reconciled': False, 'entries': [['bank_fee', -250], ['check_error', 1650], ['check_error', -1470], ['collection', 2485]]}]], [['regression: outstanding check side', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 400], ['outstanding_check', 400], ['memo', 15], ['outstanding_check', 250], ['memo', 1200], ['deposit_in_transit', 250]]}, {'adjusted_bank': 8000, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 9000, 'items': [['nsf', 400], ['bank_error', -90], ['bank_fee', 90]]}, {'adjusted_bank': 12410, 'adjusted_book': 8510, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -90]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['memo', 400], ['bank_fee', 1200], ['interest', 90], ['memo', 400], ['interest', 15], ['bank_error', -400], ['memo', 250]]}, {'adjusted_bank': 7600, 'adjusted_book': 10705, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 90], ['interest', 15]]}], ['control 3', {'bank': 8000, 'book': 11800, 'items': [['bank_fee', 1200], ['interest', 250], ['bank_error', -1200]]}, {'adjusted_bank': 6800, 'adjusted_book': 10850, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 250]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -250], ['interest', 250], ['check_error', 1200, 1209], ['bank_fee', 90], ['bank_error', -400]]}, {'adjusted_bank': 11850, 'adjusted_book': 9151, 'reconciled': False, 'entries': [['interest', 250], ['check_error', -9], ['bank_fee', -90]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['collection', 4000, 25], ['nsf', 400], ['bank_fee', 15], ['deposit_in_transit', 400]]}, {'adjusted_bank': 8400, 'adjusted_book': 12560, 'reconciled': False, 'entries': [['collection', 3975], ['nsf', -400], ['bank_fee', -15]]}], ['control 6', {'bank': 8000, 'book': 11800, 'items': [['check_error', 1200, 1209], ['nsf', 1200], ['check_error', 450, 2010], ['bank_error', 250], ['nsf', 1200], ['bank_error', 15], ['bank_error', 90]]}, {'adjusted_bank': 8355, 'adjusted_book': 7831, 'reconciled': False, 'entries': [['check_error', -9], ['nsf', -1200], ['check_error', -1560], ['nsf', -1200]]}]], [['regression: outstanding check side', {'bank': 10000, 'book': 11800, 'items': [['collection', 4000, 15], ['outstanding_check', 1200], ['bank_error', 400], ['bank_fee', 1200], ['bank_error', 400]]}, {'adjusted_bank': 9600, 'adjusted_book': 14585, 'reconciled': False, 'entries': [['collection', 3985], ['bank_fee', -1200]]}], ['control 1', {'bank': 10000, 'book': 11800, 'items': [['deposit_in_transit', 1200], ['check_error', 450, 459], ['check_error', 540, 450], ['bank_error', 15]]}, {'adjusted_bank': 11215, 'adjusted_book': 11881, 'reconciled': False, 'entries': [['check_error', -9], ['check_error', 90]]}], ['control 2', {'bank': 10000, 'book': 9000, 'items': [['collection', 150, 15], ['nsf', 15], ['deposit_in_transit', 90], ['memo', 1200], ['collection', 900, 25], ['interest', 90], ['deposit_in_transit', 400]]}, {'adjusted_bank': 10490, 'adjusted_book': 10085, 'reconciled': False, 'entries': [['collection', 135], ['nsf', -15], ['collection', 875], ['interest', 90]]}], ['control 3', {'bank': 10000, 'book': 10000, 'items': [['interest', 90], ['memo', 250], ['memo', 15], ['check_error', 540, 540], ['bank_fee', 400]]}, {'adjusted_bank': 10000, 'adjusted_book': 9690, 'reconciled': False, 'entries': [['interest', 90], ['check_error', 0], ['bank_fee', -400]]}], ['control 4', {'bank': 12500, 'book': 11800, 'items': [['bank_error', -90], ['deposit_in_transit', 400], ['collection', 12000, 15], ['deposit_in_transit', 90], ['bank_error', 250], ['check_error', 540, 540]]}, {'adjusted_bank': 13150, 'adjusted_book': 23785, 'reconciled': False, 'entries': [['collection', 11985], ['check_error', 0]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['memo', 90], ['interest', 250], ['memo', 250]]}, {'adjusted_bank': 12500, 'adjusted_book': 10250, 'reconciled': False, 'entries': [['interest', 250]]}], ['control 6', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -1200], ['memo', 15], ['check_error', 540, 1020]]}, {'adjusted_bank': 11300, 'adjusted_book': 8520, 'reconciled': False, 'entries': [['check_error', -480]]}]], [['regression: outstanding check side', {'bank': 12500, 'book': 10000, 'items': [['deposit_in_transit', 15], ['bank_error', -15], ['nsf', 90], ['collection', 2500, 25], ['outstanding_check', 90], ['collection', 900, 0]]}, {'adjusted_bank': 12410, 'adjusted_book': 13285, 'reconciled': False, 'entries': [['nsf', -90], ['collection', 2475], ['collection', 900]]}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['collection', 4000, 0], ['bank_error', 400], ['check_error', 450, 459]]}, {'adjusted_bank': 12900, 'adjusted_book': 15791, 'reconciled': False, 'entries': [['collection', 4000], ['check_error', -9]]}], ['control 2', {'bank': 12500, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['bank_error', 90]]}, {'adjusted_bank': 12750, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 3', {'bank': 8000, 'book': 10000, 'items': [['deposit_in_transit', 400], ['deposit_in_transit', 1200], ['memo', 90], ['interest', 250], ['check_error', 540, 540], ['check_error', 2100, 2109], ['interest', 250]]}, {'adjusted_bank': 9600, 'adjusted_book': 10491, 'reconciled': False, 'entries': [['interest', 250], ['check_error', 0], ['check_error', -9], ['interest', 250]]}], ['control 4', {'bank': 8000, 'book': 10000, 'items': [['deposit_in_transit', 90], ['bank_error', 15], ['collection', 4000, 0], ['interest', 250]]}, {'adjusted_bank': 8105, 'adjusted_book': 14250, 'reconciled': False, 'entries': [['collection', 4000], ['interest', 250]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['deposit_in_transit', 400], ['collection', 12000, 0]]}, {'adjusted_bank': 8560, 'adjusted_book': 21000, 'reconciled': False, 'entries': [['collection', 12000]]}], ['control 6', {'bank': 12500, 'book': 11800, 'items': [['interest', 1200], ['check_error', 450, 1020], ['bank_fee', 15], ['nsf', 250], ['collection', 150, 0]]}, {'adjusted_bank': 12500, 'adjusted_book': 12315, 'reconciled': False, 'entries': [['interest', 1200], ['check_error', -570], ['bank_fee', -15], ['nsf', -250], ['collection', 150]]}]], [['regression: outstanding check side', {'bank': 12500, 'book': 10000, 'items': [['outstanding_check', 250], ['collection', 4000, 25], ['check_error', 2100, 450], ['outstanding_check', 250], ['bank_fee', 90], ['interest', 1200], ['outstanding_check', 15]]}, {'adjusted_bank': 11985, 'adjusted_book': 16735, 'reconciled': False, 'entries': [['collection', 3975], ['check_error', 1650], ['bank_fee', -90], ['interest', 1200]]}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['nsf', 400], ['bank_fee', 250], ['bank_error', 250]]}, {'adjusted_bank': 12750, 'adjusted_book': 11150, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -250]]}], ['control 2', {'bank': 8000, 'book': 10000, 'items': [['nsf', 1200], ['collection', 4000, 15], ['interest', 400]]}, {'adjusted_bank': 8000, 'adjusted_book': 13185, 'reconciled': False, 'entries': [['nsf', -1200], ['collection', 3985], ['interest', 400]]}], ['control 3', {'bank': 10000, 'book': 11800, 'items': [['bank_error', -250], ['deposit_in_transit', 250], ['bank_fee', 250]]}, {'adjusted_bank': 10000, 'adjusted_book': 11550, 'reconciled': False, 'entries': [['bank_fee', -250]]}], ['control 4', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['collection', 150, 25], ['nsf', 400], ['nsf', 15], ['collection', 2500, 0], ['interest', 1200]]}, {'adjusted_bank': 12485, 'adjusted_book': 13410, 'reconciled': False, 'entries': [['collection', 125], ['nsf', -400], ['nsf', -15], ['collection', 2500], ['interest', 1200]]}], ['control 5', {'bank': 12500, 'book': 11800, 'items': [['check_error', 1200, 540], ['bank_error', -250], ['check_error', 2100, 450], ['bank_error', -15]]}, {'adjusted_bank': 12235, 'adjusted_book': 14110, 'reconciled': False, 'entries': [['check_error', 660], ['check_error', 1650]]}], ['control 6', {'bank': 10000, 'book': 9000, 'items': [['collection', 2500, 0], ['nsf', 400], ['memo', 400], ['collection', 2500, 0], ['collection', 900, 0], ['deposit_in_transit', 90], ['interest', 250]]}, {'adjusted_bank': 10090, 'adjusted_book': 14750, 'reconciled': False, 'entries': [['collection', 2500], ['nsf', -400], ['collection', 2500], ['collection', 900], ['interest', 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)

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):
    bank = x['bank']
    book = x['book']
    entries = []
    for item in x['items']:
        kind = item[0]
        if kind == 'deposit_in_transit':
            bank += item[1]
        elif kind == 'outstanding_check':
            book -= item[1]
        elif kind == 'bank_error':
            bank += item[1]
        else:
            if kind == 'bank_fee' or kind == 'nsf':
                adj = -item[1]
            elif kind == 'interest':
                adj = item[1]
            elif kind == 'collection':
                adj = item[1] - item[2]
            elif kind == 'check_error':
                adj = item[1] - item[2]
            else:
                continue
            book += adj
            entries.append([kind, adj])
    return {'adjusted_bank': bank, 'adjusted_book': book, 'reconciled': bank == book, 'entries': entries}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: outstanding check side', {'bank': 8000, 'book': 10000, 'items': [['nsf', 400], ['memo', 90], ['bank_fee', 15], ['bank_fee', 1200], ['check_error', 1200, 1020], ['outstanding_check', 250]]}, {'adjusted_bank': 7750, 'adjusted_book': 8565, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 180]]}], ['control 1', {'bank': 10000, 'book': 10000, 'items': [['bank_fee', 90], ['interest', 15], ['bank_error', 1200], ['nsf', 1200], ['memo', 250], ['memo', 1200]]}, {'adjusted_bank': 11200, 'adjusted_book': 8725, 'reconciled': False, 'entries': [['bank_fee', -90], ['interest', 15], ['nsf', -1200]]}], ['control 2', {'bank': 8000, 'book': 9000, 'items': [['interest', 15], ['bank_fee', 400], ['check_error', 2100, 450]]}, {'adjusted_bank': 8000, 'adjusted_book': 10265, 'reconciled': False, 'entries': [['interest', 15], ['bank_fee', -400], ['check_error', 1650]]}], ['control 3', {'bank': 8000, 'book': 9000, 'items': [['memo', 15], ['check_error', 540, 450], ['bank_error', 400], ['interest', 15], ['bank_fee', 90]]}, {'adjusted_bank': 8400, 'adjusted_book': 9015, 'reconciled': False, 'entries': [['check_error', 90], ['interest', 15], ['bank_fee', -90]]}], ['control 4', {'bank': 10000, 'book': 10000, 'items': [['deposit_in_transit', 1200], ['deposit_in_transit', 400], ['bank_fee', 90], ['bank_fee', 1200], ['deposit_in_transit', 400]]}, {'adjusted_bank': 12000, 'adjusted_book': 8710, 'reconciled': False, 'entries': [['bank_fee', -90], ['bank_fee', -1200]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['interest', 1200], ['bank_error', 400], ['interest', 400], ['bank_error', 250], ['interest', 400]]}, {'adjusted_bank': 8650, 'adjusted_book': 11000, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 400], ['interest', 400]]}], ['control 6', {'bank': 8000, 'book': 10000, 'items': [['bank_fee', 250], ['deposit_in_transit', 250], ['check_error', 2100, 450], ['deposit_in_transit', 90], ['check_error', 540, 2010], ['deposit_in_transit', 90], ['collection', 2500, 15]]}, {'adjusted_bank': 8430, 'adjusted_book': 12415, 'reconciled': False, 'entries': [['bank_fee', -250], ['check_error', 1650], ['check_error', -1470], ['collection', 2485]]}]], [['regression: outstanding check side', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 400], ['outstanding_check', 400], ['memo', 15], ['outstanding_check', 250], ['memo', 1200], ['deposit_in_transit', 250]]}, {'adjusted_bank': 8000, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 9000, 'items': [['nsf', 400], ['bank_error', -90], ['bank_fee', 90]]}, {'adjusted_bank': 12410, 'adjusted_book': 8510, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -90]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['memo', 400], ['bank_fee', 1200], ['interest', 90], ['memo', 400], ['interest', 15], ['bank_error', -400], ['memo', 250]]}, {'adjusted_bank': 7600, 'adjusted_book': 10705, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 90], ['interest', 15]]}], ['control 3', {'bank': 8000, 'book': 11800, 'items': [['bank_fee', 1200], ['interest', 250], ['bank_error', -1200]]}, {'adjusted_bank': 6800, 'adjusted_book': 10850, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 250]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -250], ['interest', 250], ['check_error', 1200, 1209], ['bank_fee', 90], ['bank_error', -400]]}, {'adjusted_bank': 11850, 'adjusted_book': 9151, 'reconciled': False, 'entries': [['interest', 250], ['check_error', -9], ['bank_fee', -90]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['collection', 4000, 25], ['nsf', 400], ['bank_fee', 15], ['deposit_in_transit', 400]]}, {'adjusted_bank': 8400, 'adjusted_book': 12560, 'reconciled': False, 'entries': [['collection', 3975], ['nsf', -400], ['bank_fee', -15]]}], ['control 6', {'bank': 8000, 'book': 11800, 'items': [['check_error', 1200, 1209], ['nsf', 1200], ['check_error', 450, 2010], ['bank_error', 250], ['nsf', 1200], ['bank_error', 15], ['bank_error', 90]]}, {'adjusted_bank': 8355, 'adjusted_book': 7831, 'reconciled': False, 'entries': [['check_error', -9], ['nsf', -1200], ['check_error', -1560], ['nsf', -1200]]}]], [['regression: outstanding check side', {'bank': 10000, 'book': 11800, 'items': [['collection', 4000, 15], ['outstanding_check', 1200], ['bank_error', 400], ['bank_fee', 1200], ['bank_error', 400]]}, {'adjusted_bank': 9600, 'adjusted_book': 14585, 'reconciled': False, 'entries': [['collection', 3985], ['bank_fee', -1200]]}], ['control 1', {'bank': 10000, 'book': 11800, 'items': [['deposit_in_transit', 1200], ['check_error', 450, 459], ['check_error', 540, 450], ['bank_error', 15]]}, {'adjusted_bank': 11215, 'adjusted_book': 11881, 'reconciled': False, 'entries': [['check_error', -9], ['check_error', 90]]}], ['control 2', {'bank': 10000, 'book': 9000, 'items': [['collection', 150, 15], ['nsf', 15], ['deposit_in_transit', 90], ['memo', 1200], ['collection', 900, 25], ['interest', 90], ['deposit_in_transit', 400]]}, {'adjusted_bank': 10490, 'adjusted_book': 10085, 'reconciled': False, 'entries': [['collection', 135], ['nsf', -15], ['collection', 875], ['interest', 90]]}], ['control 3', {'bank': 10000, 'book': 10000, 'items': [['interest', 90], ['memo', 250], ['memo', 15], ['check_error', 540, 540], ['bank_fee', 400]]}, {'adjusted_bank': 10000, 'adjusted_book': 9690, 'reconciled': False, 'entries': [['interest', 90], ['check_error', 0], ['bank_fee', -400]]}], ['control 4', {'bank': 12500, 'book': 11800, 'items': [['bank_error', -90], ['deposit_in_transit', 400], ['collection', 12000, 15], ['deposit_in_transit', 90], ['bank_error', 250], ['check_error', 540, 540]]}, {'adjusted_bank': 13150, 'adjusted_book': 23785, 'reconciled': False, 'entries': [['collection', 11985], ['check_error', 0]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['memo', 90], ['interest', 250], ['memo', 250]]}, {'adjusted_bank': 12500, 'adjusted_book': 10250, 'reconciled': False, 'entries': [['interest', 250]]}], ['control 6', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -1200], ['memo', 15], ['check_error', 540, 1020]]}, {'adjusted_bank': 11300, 'adjusted_book': 8520, 'reconciled': False, 'entries': [['check_error', -480]]}]], [['regression: outstanding check side', {'bank': 12500, 'book': 10000, 'items': [['deposit_in_transit', 15], ['bank_error', -15], ['nsf', 90], ['collection', 2500, 25], ['outstanding_check', 90], ['collection', 900, 0]]}, {'adjusted_bank': 12410, 'adjusted_book': 13285, 'reconciled': False, 'entries': [['nsf', -90], ['collection', 2475], ['collection', 900]]}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['collection', 4000, 0], ['bank_error', 400], ['check_error', 450, 459]]}, {'adjusted_bank': 12900, 'adjusted_book': 15791, 'reconciled': False, 'entries': [['collection', 4000], ['check_error', -9]]}], ['control 2', {'bank': 12500, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['bank_error', 90]]}, {'adjusted_bank': 12750, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 3', {'bank': 8000, 'book': 10000, 'items': [['deposit_in_transit', 400], ['deposit_in_transit', 1200], ['memo', 90], ['interest', 250], ['check_error', 540, 540], ['check_error', 2100, 2109], ['interest', 250]]}, {'adjusted_bank': 9600, 'adjusted_book': 10491, 'reconciled': False, 'entries': [['interest', 250], ['check_error', 0], ['check_error', -9], ['interest', 250]]}], ['control 4', {'bank': 8000, 'book': 10000, 'items': [['deposit_in_transit', 90], ['bank_error', 15], ['collection', 4000, 0], ['interest', 250]]}, {'adjusted_bank': 8105, 'adjusted_book': 14250, 'reconciled': False, 'entries': [['collection', 4000], ['interest', 250]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['deposit_in_transit', 400], ['collection', 12000, 0]]}, {'adjusted_bank': 8560, 'adjusted_book': 21000, 'reconciled': False, 'entries': [['collection', 12000]]}], ['control 6', {'bank': 12500, 'book': 11800, 'items': [['interest', 1200], ['check_error', 450, 1020], ['bank_fee', 15], ['nsf', 250], ['collection', 150, 0]]}, {'adjusted_bank': 12500, 'adjusted_book': 12315, 'reconciled': False, 'entries': [['interest', 1200], ['check_error', -570], ['bank_fee', -15], ['nsf', -250], ['collection', 150]]}]], [['regression: outstanding check side', {'bank': 12500, 'book': 10000, 'items': [['outstanding_check', 250], ['collection', 4000, 25], ['check_error', 2100, 450], ['outstanding_check', 250], ['bank_fee', 90], ['interest', 1200], ['outstanding_check', 15]]}, {'adjusted_bank': 11985, 'adjusted_book': 16735, 'reconciled': False, 'entries': [['collection', 3975], ['check_error', 1650], ['bank_fee', -90], ['interest', 1200]]}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['nsf', 400], ['bank_fee', 250], ['bank_error', 250]]}, {'adjusted_bank': 12750, 'adjusted_book': 11150, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -250]]}], ['control 2', {'bank': 8000, 'book': 10000, 'items': [['nsf', 1200], ['collection', 4000, 15], ['interest', 400]]}, {'adjusted_bank': 8000, 'adjusted_book': 13185, 'reconciled': False, 'entries': [['nsf', -1200], ['collection', 3985], ['interest', 400]]}], ['control 3', {'bank': 10000, 'book': 11800, 'items': [['bank_error', -250], ['deposit_in_transit', 250], ['bank_fee', 250]]}, {'adjusted_bank': 10000, 'adjusted_book': 11550, 'reconciled': False, 'entries': [['bank_fee', -250]]}], ['control 4', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['collection', 150, 25], ['nsf', 400], ['nsf', 15], ['collection', 2500, 0], ['interest', 1200]]}, {'adjusted_bank': 12485, 'adjusted_book': 13410, 'reconciled': False, 'entries': [['collection', 125], ['nsf', -400], ['nsf', -15], ['collection', 2500], ['interest', 1200]]}], ['control 5', {'bank': 12500, 'book': 11800, 'items': [['check_error', 1200, 540], ['bank_error', -250], ['check_error', 2100, 450], ['bank_error', -15]]}, {'adjusted_bank': 12235, 'adjusted_book': 14110, 'reconciled': False, 'entries': [['check_error', 660], ['check_error', 1650]]}], ['control 6', {'bank': 10000, 'book': 9000, 'items': [['collection', 2500, 0], ['nsf', 400], ['memo', 400], ['collection', 2500, 0], ['collection', 900, 0], ['deposit_in_transit', 90], ['interest', 250]]}, {'adjusted_bank': 10090, 'adjusted_book': 14750, 'reconciled': False, 'entries': [['collection', 2500], ['nsf', -400], ['collection', 2500], ['collection', 900], ['interest', 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:
Outstanding checks widen the gap between bank and book instead of closing it.

x = {'bank': statement balance, 'book': ledger cash balance, 'items': [[kind, ...]]}. Bank side: deposit_in_transit adds, outstanding_check subtracts, bank_error adds its signed correction. Book side (each produces an adjusting entry [kind, signed amount] in input order): bank_fee and nsf subtract, interest adds, collection [kind, face, fee] adds face - fee, check_error [kind, recorded, actual] adds recorded - actual. Other kinds are ignored. Return {'adjusted_bank', 'adjusted_book', 'reconciled', 'entries'}.

split: open-access


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

N = 1
observations = []
def solve(x):
    bank = x['bank']
    book = x['book']
    entries = []
    for item in x['items']:
        kind = item[0]
        if kind == 'deposit_in_transit':
            book += item[1]
        elif kind == 'outstanding_check':
            bank -= item[1]
        elif kind == 'bank_error':
            bank += item[1]
        else:
            if kind == 'bank_fee' or kind == 'nsf':
                adj = -item[1]
            elif kind == 'interest':
                adj = item[1]
            elif kind == 'collection':
                adj = item[1] - item[2]
            elif kind == 'check_error':
                adj = item[1] - item[2]
            else:
                continue
            book += adj
            entries.append([kind, adj])
    return {'adjusted_bank': bank, 'adjusted_book': book, 'reconciled': bank == book, 'entries': entries}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: deposit in transit side', {'bank': 10000, 'book': 10000, 'items': [['deposit_in_transit', 1200], ['deposit_in_transit', 400], ['bank_fee', 90], ['bank_fee', 1200], ['deposit_in_transit', 400]]}, {'adjusted_bank': 12000, 'adjusted_book': 8710, 'reconciled': False, 'entries': [['bank_fee', -90], ['bank_fee', -1200]]}], ['control 1', {'bank': 10000, 'book': 10000, 'items': [['bank_fee', 90], ['interest', 15], ['bank_error', 1200], ['nsf', 1200], ['memo', 250], ['memo', 1200]]}, {'adjusted_bank': 11200, 'adjusted_book': 8725, 'reconciled': False, 'entries': [['bank_fee', -90], ['interest', 15], ['nsf', -1200]]}], ['control 2', {'bank': 8000, 'book': 9000, 'items': [['interest', 15], ['bank_fee', 400], ['check_error', 2100, 450]]}, {'adjusted_bank': 8000, 'adjusted_book': 10265, 'reconciled': False, 'entries': [['interest', 15], ['bank_fee', -400], ['check_error', 1650]]}], ['control 3', {'bank': 8000, 'book': 9000, 'items': [['memo', 15], ['check_error', 540, 450], ['bank_error', 400], ['interest', 15], ['bank_fee', 90]]}, {'adjusted_bank': 8400, 'adjusted_book': 9015, 'reconciled': False, 'entries': [['check_error', 90], ['interest', 15], ['bank_fee', -90]]}], ['control 4', {'bank': 8000, 'book': 10000, 'items': [['nsf', 400], ['memo', 90], ['bank_fee', 15], ['bank_fee', 1200], ['check_error', 1200, 1020], ['outstanding_check', 250]]}, {'adjusted_bank': 7750, 'adjusted_book': 8565, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 180]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['interest', 1200], ['bank_error', 400], ['interest', 400], ['bank_error', 250], ['interest', 400]]}, {'adjusted_bank': 8650, 'adjusted_book': 11000, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 400], ['interest', 400]]}], ['control 6', {'bank': 10000, 'book': 9000, 'items': [['outstanding_check', 15], ['interest', 1200], ['interest', 1200], ['collection', 12000, 0], ['collection', 4000, 15], ['outstanding_check', 90]]}, {'adjusted_bank': 9895, 'adjusted_book': 27385, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 1200], ['collection', 12000], ['collection', 3985]]}]], [['regression: deposit in transit side', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 400], ['outstanding_check', 400], ['memo', 15], ['outstanding_check', 250], ['memo', 1200], ['deposit_in_transit', 250]]}, {'adjusted_bank': 8000, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 9000, 'items': [['nsf', 400], ['bank_error', -90], ['bank_fee', 90]]}, {'adjusted_bank': 12410, 'adjusted_book': 8510, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -90]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['memo', 400], ['bank_fee', 1200], ['interest', 90], ['memo', 400], ['interest', 15], ['bank_error', -400], ['memo', 250]]}, {'adjusted_bank': 7600, 'adjusted_book': 10705, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 90], ['interest', 15]]}], ['control 3', {'bank': 8000, 'book': 11800, 'items': [['bank_fee', 1200], ['interest', 250], ['bank_error', -1200]]}, {'adjusted_bank': 6800, 'adjusted_book': 10850, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 250]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -250], ['interest', 250], ['check_error', 1200, 1209], ['bank_fee', 90], ['bank_error', -400]]}, {'adjusted_bank': 11850, 'adjusted_book': 9151, 'reconciled': False, 'entries': [['interest', 250], ['check_error', -9], ['bank_fee', -90]]}], ['control 5', {'bank': 8000, 'book': 11800, 'items': [['check_error', 1200, 1209], ['nsf', 1200], ['check_error', 450, 2010], ['bank_error', 250], ['nsf', 1200], ['bank_error', 15], ['bank_error', 90]]}, {'adjusted_bank': 8355, 'adjusted_book': 7831, 'reconciled': False, 'entries': [['check_error', -9], ['nsf', -1200], ['check_error', -1560], ['nsf', -1200]]}], ['control 6', {'bank': 12500, 'book': 9000, 'items': [['bank_error', 90], ['check_error', 2100, 2010], ['bank_fee', 1200], ['bank_error', 90], ['bank_fee', 250], ['memo', 250]]}, {'adjusted_bank': 12680, 'adjusted_book': 7640, 'reconciled': False, 'entries': [['check_error', 90], ['bank_fee', -1200], ['bank_fee', -250]]}]], [['regression: deposit in transit side', {'bank': 10000, 'book': 11800, 'items': [['deposit_in_transit', 1200], ['check_error', 450, 459], ['check_error', 540, 450], ['bank_error', 15]]}, {'adjusted_bank': 11215, 'adjusted_book': 11881, 'reconciled': False, 'entries': [['check_error', -9], ['check_error', 90]]}], ['control 1', {'bank': 10000, 'book': 11800, 'items': [['collection', 4000, 15], ['outstanding_check', 1200], ['bank_error', 400], ['bank_fee', 1200], ['bank_error', 400]]}, {'adjusted_bank': 9600, 'adjusted_book': 14585, 'reconciled': False, 'entries': [['collection', 3985], ['bank_fee', -1200]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['check_error', 450, 450], ['outstanding_check', 1200], ['bank_error', -400], ['check_error', 2100, 2010]]}, {'adjusted_bank': 6400, 'adjusted_book': 11890, 'reconciled': False, 'entries': [['check_error', 0], ['check_error', 90]]}], ['control 3', {'bank': 10000, 'book': 10000, 'items': [['interest', 90], ['memo', 250], ['memo', 15], ['check_error', 540, 540], ['bank_fee', 400]]}, {'adjusted_bank': 10000, 'adjusted_book': 9690, 'reconciled': False, 'entries': [['interest', 90], ['check_error', 0], ['bank_fee', -400]]}], ['control 4', {'bank': 8000, 'book': 9000, 'items': [['memo', 250], ['check_error', 450, 450], ['nsf', 15], ['outstanding_check', 1200], ['memo', 400], ['bank_fee', 90]]}, {'adjusted_bank': 6800, 'adjusted_book': 8895, 'reconciled': False, 'entries': [['check_error', 0], ['nsf', -15], ['bank_fee', -90]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['memo', 250], ['collection', 12000, 25], ['bank_error', 15], ['outstanding_check', 1200]]}, {'adjusted_bank': 11300, 'adjusted_book': 21975, 'reconciled': False, 'entries': [['collection', 11975]]}], ['control 6', {'bank': 12500, 'book': 10000, 'items': [['memo', 90], ['interest', 250], ['memo', 250]]}, {'adjusted_bank': 12500, 'adjusted_book': 10250, 'reconciled': False, 'entries': [['interest', 250]]}]], [['regression: deposit in transit side', {'bank': 12500, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['bank_error', 90]]}, {'adjusted_bank': 12750, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['collection', 4000, 0], ['bank_error', 400], ['check_error', 450, 459]]}, {'adjusted_bank': 12900, 'adjusted_book': 15791, 'reconciled': False, 'entries': [['collection', 4000], ['check_error', -9]]}], ['control 2', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -1200], ['memo', 15], ['bank_fee', 15], ['outstanding_check', 400], ['outstanding_check', 400]]}, {'adjusted_bank': 10500, 'adjusted_book': 8985, 'reconciled': False, 'entries': [['bank_fee', -15]]}], ['control 3', {'bank': 12500, 'book': 11800, 'items': [['interest', 1200], ['check_error', 450, 1020], ['bank_fee', 15], ['nsf', 250], ['collection', 150, 0]]}, {'adjusted_bank': 12500, 'adjusted_book': 12315, 'reconciled': False, 'entries': [['interest', 1200], ['check_error', -570], ['bank_fee', -15], ['nsf', -250], ['collection', 150]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['collection', 2500, 15], ['check_error', 2100, 2109], ['bank_fee', 15], ['bank_error', -15], ['bank_fee', 1200], ['check_error', 2100, 540]]}, {'adjusted_bank': 12485, 'adjusted_book': 11821, 'reconciled': False, 'entries': [['collection', 2485], ['check_error', -9], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 1560]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_fee', 400], ['bank_error', -15], ['memo', 400], ['outstanding_check', 400]]}, {'adjusted_bank': 12085, 'adjusted_book': 9600, 'reconciled': False, 'entries': [['bank_fee', -400]]}], ['control 6', {'bank': 10000, 'book': 10000, 'items': [['memo', 15], ['bank_fee', 90], ['bank_error', 400], ['collection', 4000, 15], ['nsf', 1200]]}, {'adjusted_bank': 10400, 'adjusted_book': 12695, 'reconciled': False, 'entries': [['bank_fee', -90], ['collection', 3985], ['nsf', -1200]]}]], [['regression: deposit in transit side', {'bank': 10000, 'book': 10000, 'items': [['outstanding_check', 90], ['memo', 250], ['bank_fee', 15], ['interest', 1200], ['memo', 250], ['deposit_in_transit', 15]]}, {'adjusted_bank': 9925, 'adjusted_book': 11185, 'reconciled': False, 'entries': [['bank_fee', -15], ['interest', 1200]]}], ['control 1', {'bank': 12500, 'book': 10000, 'items': [['outstanding_check', 250], ['collection', 4000, 25], ['check_error', 2100, 450], ['outstanding_check', 250], ['bank_fee', 90], ['interest', 1200], ['outstanding_check', 15]]}, {'adjusted_bank': 11985, 'adjusted_book': 16735, 'reconciled': False, 'entries': [['collection', 3975], ['check_error', 1650], ['bank_fee', -90], ['interest', 1200]]}], ['control 2', {'bank': 12500, 'book': 11800, 'items': [['nsf', 400], ['bank_fee', 250], ['bank_error', 250]]}, {'adjusted_bank': 12750, 'adjusted_book': 11150, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -250]]}], ['control 3', {'bank': 8000, 'book': 10000, 'items': [['nsf', 1200], ['collection', 4000, 15], ['interest', 400]]}, {'adjusted_bank': 8000, 'adjusted_book': 13185, 'reconciled': False, 'entries': [['nsf', -1200], ['collection', 3985], ['interest', 400]]}], ['control 4', {'bank': 8000, 'book': 9000, 'items': [['check_error', 450, 459], ['outstanding_check', 400], ['interest', 1200]]}, {'adjusted_bank': 7600, 'adjusted_book': 10191, 'reconciled': False, 'entries': [['check_error', -9], ['interest', 1200]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['collection', 150, 25], ['nsf', 400], ['nsf', 15], ['collection', 2500, 0], ['interest', 1200]]}, {'adjusted_bank': 12485, 'adjusted_book': 13410, 'reconciled': False, 'entries': [['collection', 125], ['nsf', -400], ['nsf', -15], ['collection', 2500], ['interest', 1200]]}], ['control 6', {'bank': 8000, 'book': 10000, 'items': [['collection', 12000, 0], ['interest', 400], ['outstanding_check', 90], ['nsf', 90], ['bank_error', -1200], ['nsf', 400]]}, {'adjusted_bank': 6710, 'adjusted_book': 21910, 'reconciled': False, 'entries': [['collection', 12000], ['interest', 400], ['nsf', -90], ['nsf', -400]]}]]]
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):
    bank = x['bank']
    book = x['book']
    entries = []
    for item in x['items']:
        kind = item[0]
        if kind == 'deposit_in_transit':
            bank += item[1]
            book += item[1]
        elif kind == 'outstanding_check':
            bank -= item[1]
        elif kind == 'bank_error':
            bank += item[1]
        else:
            if kind == 'bank_fee' or kind == 'nsf':
                adj = -item[1]
            elif kind == 'interest':
                adj = item[1]
            elif kind == 'collection':
                adj = item[1] - item[2]
            elif kind == 'check_error':
                adj = item[1] - item[2]
            else:
                continue
            book += adj
            entries.append([kind, adj])
    return {'adjusted_bank': bank, 'adjusted_book': book, 'reconciled': bank == book, 'entries': entries}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: deposit in transit side', {'bank': 10000, 'book': 10000, 'items': [['deposit_in_transit', 1200], ['deposit_in_transit', 400], ['bank_fee', 90], ['bank_fee', 1200], ['deposit_in_transit', 400]]}, {'adjusted_bank': 12000, 'adjusted_book': 8710, 'reconciled': False, 'entries': [['bank_fee', -90], ['bank_fee', -1200]]}], ['control 1', {'bank': 10000, 'book': 10000, 'items': [['bank_fee', 90], ['interest', 15], ['bank_error', 1200], ['nsf', 1200], ['memo', 250], ['memo', 1200]]}, {'adjusted_bank': 11200, 'adjusted_book': 8725, 'reconciled': False, 'entries': [['bank_fee', -90], ['interest', 15], ['nsf', -1200]]}], ['control 2', {'bank': 8000, 'book': 9000, 'items': [['interest', 15], ['bank_fee', 400], ['check_error', 2100, 450]]}, {'adjusted_bank': 8000, 'adjusted_book': 10265, 'reconciled': False, 'entries': [['interest', 15], ['bank_fee', -400], ['check_error', 1650]]}], ['control 3', {'bank': 8000, 'book': 9000, 'items': [['memo', 15], ['check_error', 540, 450], ['bank_error', 400], ['interest', 15], ['bank_fee', 90]]}, {'adjusted_bank': 8400, 'adjusted_book': 9015, 'reconciled': False, 'entries': [['check_error', 90], ['interest', 15], ['bank_fee', -90]]}], ['control 4', {'bank': 8000, 'book': 10000, 'items': [['nsf', 400], ['memo', 90], ['bank_fee', 15], ['bank_fee', 1200], ['check_error', 1200, 1020], ['outstanding_check', 250]]}, {'adjusted_bank': 7750, 'adjusted_book': 8565, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 180]]}], ['control 5', {'bank': 8000, 'book': 9000, 'items': [['interest', 1200], ['bank_error', 400], ['interest', 400], ['bank_error', 250], ['interest', 400]]}, {'adjusted_bank': 8650, 'adjusted_book': 11000, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 400], ['interest', 400]]}], ['control 6', {'bank': 10000, 'book': 9000, 'items': [['outstanding_check', 15], ['interest', 1200], ['interest', 1200], ['collection', 12000, 0], ['collection', 4000, 15], ['outstanding_check', 90]]}, {'adjusted_bank': 9895, 'adjusted_book': 27385, 'reconciled': False, 'entries': [['interest', 1200], ['interest', 1200], ['collection', 12000], ['collection', 3985]]}]], [['regression: deposit in transit side', {'bank': 8000, 'book': 9000, 'items': [['deposit_in_transit', 400], ['outstanding_check', 400], ['memo', 15], ['outstanding_check', 250], ['memo', 1200], ['deposit_in_transit', 250]]}, {'adjusted_bank': 8000, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 9000, 'items': [['nsf', 400], ['bank_error', -90], ['bank_fee', 90]]}, {'adjusted_bank': 12410, 'adjusted_book': 8510, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -90]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['memo', 400], ['bank_fee', 1200], ['interest', 90], ['memo', 400], ['interest', 15], ['bank_error', -400], ['memo', 250]]}, {'adjusted_bank': 7600, 'adjusted_book': 10705, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 90], ['interest', 15]]}], ['control 3', {'bank': 8000, 'book': 11800, 'items': [['bank_fee', 1200], ['interest', 250], ['bank_error', -1200]]}, {'adjusted_bank': 6800, 'adjusted_book': 10850, 'reconciled': False, 'entries': [['bank_fee', -1200], ['interest', 250]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -250], ['interest', 250], ['check_error', 1200, 1209], ['bank_fee', 90], ['bank_error', -400]]}, {'adjusted_bank': 11850, 'adjusted_book': 9151, 'reconciled': False, 'entries': [['interest', 250], ['check_error', -9], ['bank_fee', -90]]}], ['control 5', {'bank': 8000, 'book': 11800, 'items': [['check_error', 1200, 1209], ['nsf', 1200], ['check_error', 450, 2010], ['bank_error', 250], ['nsf', 1200], ['bank_error', 15], ['bank_error', 90]]}, {'adjusted_bank': 8355, 'adjusted_book': 7831, 'reconciled': False, 'entries': [['check_error', -9], ['nsf', -1200], ['check_error', -1560], ['nsf', -1200]]}], ['control 6', {'bank': 12500, 'book': 9000, 'items': [['bank_error', 90], ['check_error', 2100, 2010], ['bank_fee', 1200], ['bank_error', 90], ['bank_fee', 250], ['memo', 250]]}, {'adjusted_bank': 12680, 'adjusted_book': 7640, 'reconciled': False, 'entries': [['check_error', 90], ['bank_fee', -1200], ['bank_fee', -250]]}]], [['regression: deposit in transit side', {'bank': 10000, 'book': 11800, 'items': [['deposit_in_transit', 1200], ['check_error', 450, 459], ['check_error', 540, 450], ['bank_error', 15]]}, {'adjusted_bank': 11215, 'adjusted_book': 11881, 'reconciled': False, 'entries': [['check_error', -9], ['check_error', 90]]}], ['control 1', {'bank': 10000, 'book': 11800, 'items': [['collection', 4000, 15], ['outstanding_check', 1200], ['bank_error', 400], ['bank_fee', 1200], ['bank_error', 400]]}, {'adjusted_bank': 9600, 'adjusted_book': 14585, 'reconciled': False, 'entries': [['collection', 3985], ['bank_fee', -1200]]}], ['control 2', {'bank': 8000, 'book': 11800, 'items': [['check_error', 450, 450], ['outstanding_check', 1200], ['bank_error', -400], ['check_error', 2100, 2010]]}, {'adjusted_bank': 6400, 'adjusted_book': 11890, 'reconciled': False, 'entries': [['check_error', 0], ['check_error', 90]]}], ['control 3', {'bank': 10000, 'book': 10000, 'items': [['interest', 90], ['memo', 250], ['memo', 15], ['check_error', 540, 540], ['bank_fee', 400]]}, {'adjusted_bank': 10000, 'adjusted_book': 9690, 'reconciled': False, 'entries': [['interest', 90], ['check_error', 0], ['bank_fee', -400]]}], ['control 4', {'bank': 8000, 'book': 9000, 'items': [['memo', 250], ['check_error', 450, 450], ['nsf', 15], ['outstanding_check', 1200], ['memo', 400], ['bank_fee', 90]]}, {'adjusted_bank': 6800, 'adjusted_book': 8895, 'reconciled': False, 'entries': [['check_error', 0], ['nsf', -15], ['bank_fee', -90]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['memo', 250], ['collection', 12000, 25], ['bank_error', 15], ['outstanding_check', 1200]]}, {'adjusted_bank': 11300, 'adjusted_book': 21975, 'reconciled': False, 'entries': [['collection', 11975]]}], ['control 6', {'bank': 12500, 'book': 10000, 'items': [['memo', 90], ['interest', 250], ['memo', 250]]}, {'adjusted_bank': 12500, 'adjusted_book': 10250, 'reconciled': False, 'entries': [['interest', 250]]}]], [['regression: deposit in transit side', {'bank': 12500, 'book': 9000, 'items': [['deposit_in_transit', 250], ['bank_error', -90], ['bank_error', 90]]}, {'adjusted_bank': 12750, 'adjusted_book': 9000, 'reconciled': False, 'entries': []}], ['control 1', {'bank': 12500, 'book': 11800, 'items': [['collection', 4000, 0], ['bank_error', 400], ['check_error', 450, 459]]}, {'adjusted_bank': 12900, 'adjusted_book': 15791, 'reconciled': False, 'entries': [['collection', 4000], ['check_error', -9]]}], ['control 2', {'bank': 12500, 'book': 9000, 'items': [['bank_error', -1200], ['memo', 15], ['bank_fee', 15], ['outstanding_check', 400], ['outstanding_check', 400]]}, {'adjusted_bank': 10500, 'adjusted_book': 8985, 'reconciled': False, 'entries': [['bank_fee', -15]]}], ['control 3', {'bank': 12500, 'book': 11800, 'items': [['interest', 1200], ['check_error', 450, 1020], ['bank_fee', 15], ['nsf', 250], ['collection', 150, 0]]}, {'adjusted_bank': 12500, 'adjusted_book': 12315, 'reconciled': False, 'entries': [['interest', 1200], ['check_error', -570], ['bank_fee', -15], ['nsf', -250], ['collection', 150]]}], ['control 4', {'bank': 12500, 'book': 9000, 'items': [['collection', 2500, 15], ['check_error', 2100, 2109], ['bank_fee', 15], ['bank_error', -15], ['bank_fee', 1200], ['check_error', 2100, 540]]}, {'adjusted_bank': 12485, 'adjusted_book': 11821, 'reconciled': False, 'entries': [['collection', 2485], ['check_error', -9], ['bank_fee', -15], ['bank_fee', -1200], ['check_error', 1560]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_fee', 400], ['bank_error', -15], ['memo', 400], ['outstanding_check', 400]]}, {'adjusted_bank': 12085, 'adjusted_book': 9600, 'reconciled': False, 'entries': [['bank_fee', -400]]}], ['control 6', {'bank': 10000, 'book': 10000, 'items': [['memo', 15], ['bank_fee', 90], ['bank_error', 400], ['collection', 4000, 15], ['nsf', 1200]]}, {'adjusted_bank': 10400, 'adjusted_book': 12695, 'reconciled': False, 'entries': [['bank_fee', -90], ['collection', 3985], ['nsf', -1200]]}]], [['regression: deposit in transit side', {'bank': 10000, 'book': 10000, 'items': [['outstanding_check', 90], ['memo', 250], ['bank_fee', 15], ['interest', 1200], ['memo', 250], ['deposit_in_transit', 15]]}, {'adjusted_bank': 9925, 'adjusted_book': 11185, 'reconciled': False, 'entries': [['bank_fee', -15], ['interest', 1200]]}], ['control 1', {'bank': 12500, 'book': 10000, 'items': [['outstanding_check', 250], ['collection', 4000, 25], ['check_error', 2100, 450], ['outstanding_check', 250], ['bank_fee', 90], ['interest', 1200], ['outstanding_check', 15]]}, {'adjusted_bank': 11985, 'adjusted_book': 16735, 'reconciled': False, 'entries': [['collection', 3975], ['check_error', 1650], ['bank_fee', -90], ['interest', 1200]]}], ['control 2', {'bank': 12500, 'book': 11800, 'items': [['nsf', 400], ['bank_fee', 250], ['bank_error', 250]]}, {'adjusted_bank': 12750, 'adjusted_book': 11150, 'reconciled': False, 'entries': [['nsf', -400], ['bank_fee', -250]]}], ['control 3', {'bank': 8000, 'book': 10000, 'items': [['nsf', 1200], ['collection', 4000, 15], ['interest', 400]]}, {'adjusted_bank': 8000, 'adjusted_book': 13185, 'reconciled': False, 'entries': [['nsf', -1200], ['collection', 3985], ['interest', 400]]}], ['control 4', {'bank': 8000, 'book': 9000, 'items': [['check_error', 450, 459], ['outstanding_check', 400], ['interest', 1200]]}, {'adjusted_bank': 7600, 'adjusted_book': 10191, 'reconciled': False, 'entries': [['check_error', -9], ['interest', 1200]]}], ['control 5', {'bank': 12500, 'book': 10000, 'items': [['bank_error', -15], ['collection', 150, 25], ['nsf', 400], ['nsf', 15], ['collection', 2500, 0], ['interest', 1200]]}, {'adjusted_bank': 12485, 'adjusted_book': 13410, 'reconciled': False, 'entries': [['collection', 125], ['nsf', -400], ['nsf', -15], ['collection', 2500], ['interest', 1200]]}], ['control 6', {'bank': 8000, 'book': 10000, 'items': [['collection', 12000, 0], ['interest', 400], ['outstanding_check', 90], ['nsf', 90], ['bank_error', -1200], ['nsf', 400]]}, {'adjusted_bank': 6710, 'adjusted_book': 21910, 'reconciled': False, 'entries': [['collection', 12000], ['interest', 400], ['nsf', -90], ['nsf', -400]]}]]]
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:
Deposits made after the statement cutoff inflate the adjusted book balance.

x = {'bank': statement balance, 'book': ledger cash balance, 'items': [[kind, ...]]}. Bank side: deposit_in_transit adds, outstanding_check subtracts, bank_error adds its signed correction. Book side (each produces an adjusting entry [kind, signed amount] in input order): bank_fee and nsf subtract, interest adds, collection [kind, face, fee] adds face - fee, check_error [kind, recorded, actual] adds recorded - actual. Other kinds are ignored. Return {'adjusted_bank', 'adjusted_book', 'reconciled', 'entries'}.

split: open-access