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

N = 1
observations = []
def solve(x):
    chart = x['chart']
    debit_normal = {'asset', 'expense', 'dividend'}
    bal = {a: 0 for a in chart}
    rejected = []
    posted = set()
    for eid, lines in x['entries']:
        ok = eid not in posted and len(lines) >= 2
        dr = cr = 0
        for acct, side, amt in lines:
            if acct not in chart or side not in ('D', 'C') or amt <= 0:
                ok = False
            elif side == 'D':
                dr += amt
            else:
                cr += amt
        if not ok or dr != cr:
            rejected.append(eid)
            continue
        posted.add(eid)
        for acct, side, amt in lines:
            sign = 1 if side == 'D' else -1
            bal[acct] += sign * amt
    return {'balances': bal, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: posting sign by side and normal balance', {'chart': {'acc_depr': 'contra_asset', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'capital': 'equity'}, 'entries': [['J1', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['equipment', 'C', 5000], ['payable', 'D', 5000]]], ['J1', [['acc_depr', 'C', 1200], ['payable', 'D', 1170], ['payable', 'D', 30]]], ['J4', [['equipment', 'C', 5000], ['acc_depr', 'D', 4970], ['acc_depr', 'D', 30]]], ['J3', [['acc_depr', 'D', -40], ['equipment', 'C', -40]]]]}, {'balances': {'acc_depr': -5000, 'drawings': 0, 'payable': -5040, 'equipment': -10040, 'capital': 0}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 999], ['sales', 'D', 999]]], ['J5', [['wages', 'C', 250], ['equipment', 'D', 250]]], ['J3', [['wages', 'C', 40], ['rent', 'D', 40]]], ['J5', [['drawings', 'C', 100], ['wages', 'C', 0], ['sales', 'D', 100], ['wages', 'D', 0]]], ['J4', [['equipment', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['rent', 'D', 100], ['equipment', 'C', 100]]]]}, {'balances': {'capital': 0, 'rent': 140, 'cash': 0, 'receivable': 0, 'drawings': 0, 'equipment': 1350, 'wages': -1490, 'sales': 0}, 'rejected': ['J2', 'J5']}], ['control 2', {'chart': {'drawings': 'dividend', 'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J4', [['receivable', 'C', 5000], ['cash', 'D', 4970], ['cash', 'D', 30]]], ['J1', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J3', []]]}, {'balances': {'drawings': 40, 'wages': 0, 'receivable': -5040, 'rent': 0, 'cash': 5000}, 'rejected': ['J3']}], ['control 3', {'chart': {'receivable': 'asset', 'equipment': 'asset', 'drawings': 'dividend', 'payable': 'liability', 'wages': 'expense', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J3', [['receivable', 'D', 999], ['equipment', 'C', 999]]], ['J1', [['receivable', 'D', 100], ['payable', 'C', 100]]], ['J4', [['payable', 'D', 100], ['rent', 'C', 100]]], ['J1', [['rent', 'D', 999], ['wages', 'C', 999]]], ['J2', [['drawings', 'C', 250], ['wages', 'D', 250]]], ['J3', [['rent', 'C', 40], ['payable', 'D', 40]]], ['J2', [['equipment', 'C', 250], ['cash', 'D', 250]]]]}, {'balances': {'receivable': 1099, 'equipment': -999, 'drawings': -250, 'payable': 0, 'wages': 250, 'cash': 0, 'rent': -100}, 'rejected': ['J1', 'J3', 'J2']}], ['control 4', {'chart': {'cash': 'asset', 'equipment': 'asset', 'receivable': 'asset', 'wages': 'expense', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J2', [['receivable', 'C', 5000], ['wages', 'D', 5000]]], ['J3', [['rent', 'D', 1200], ['cash', 'C', 1200]]], ['J4', [['equipment', 'D', 250], ['receivable', 'C', 250]]]]}, {'balances': {'cash': -1200, 'equipment': 250, 'receivable': -5250, 'wages': 5000, 'acc_depr': 0, 'rent': 1200}, 'rejected': []}], ['control 5', {'chart': {'cash': 'asset', 'equipment': 'asset', 'payable': 'liability', 'drawings': 'dividend', 'loan': 'liability', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J4', [['cash', 'D', -999], ['rent', 'C', -999]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J4', [['rent', 'C', 40], ['payable', 'D', 40]]], ['J3', [['rent', 'D', -999], ['cash', 'C', -999]]], ['J1', [['payable', 'C', 0], ['rent', 'C', 5000], ['cash', 'D', 5000], ['payable', 'D', 0]]]]}, {'balances': {'cash': 0, 'equipment': -5000, 'payable': 0, 'drawings': 0, 'loan': 0, 'acc_depr': 0, 'rent': 5000}, 'rejected': ['J4', 'J4', 'J3', 'J1']}], ['control 6', {'chart': {'rent': 'expense', 'sales': 'revenue', 'capital': 'equity', 'payable': 'liability', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'receivable': 'asset'}, 'entries': [['J3', [['capital', 'D', -40], ['equipment', 'C', -40]]], ['J5', [['receivable', 'D', 999], ['drawings', 'C', 0], ['drawings', 'D', 0], ['rent', 'C', 999]]], ['J2', [['sales', 'C', 40], ['receivable', 'D', 40], ['rent', 'D', 0], ['rent', 'C', 0]]], ['J5', [['equipment', 'D', 1200], ['drawings', 'C', 1200]]], ['J2', [['wages', 'C', 40], ['receivable', 'D', 40]]], ['J5', [['sales', 'D', 250], ['drawings', 'C', 250]]], ['J4', [['equipment', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'rent': 0, 'sales': 0, 'capital': 0, 'payable': 0, 'drawings': -1200, 'equipment': 1200, 'wages': -40, 'receivable': 40}, 'rejected': ['J3', 'J5', 'J2', 'J5', 'J4']}]], [['regression: posting sign by side and normal balance', {'chart': {'acc_depr': 'contra_asset', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense'}, 'entries': [['J3', [['acc_depr', 'D', 30], ['acc_depr', 'D', 4970], ['loan', 'C', 5000]]], ['J2', [['loan', 'D', 4970], ['loan', 'D', 30], ['acc_depr', 'C', 5000]]], ['J3', [['loan', 'D', 5000], ['wages', 'C', 4999]]], ['J4', [['sales', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['loan', 'C', 40], ['sales', 'D', 40]]]]}, {'balances': {'acc_depr': 999, 'loan': 0, 'equipment': 0, 'sales': -999, 'wages': 0}, 'rejected': ['J3', 'J3']}], ['control 1', {'chart': {'drawings': 'dividend', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['drawings', 'C', 1200], ['equipment', 'D', 1200]]], ['J3', [['receivable', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['drawings', 'C', 999]]]]}, {'balances': {'drawings': -1949, 'sales': 0, 'equipment': 1200, 'cash': 0, 'receivable': 749}, 'rejected': []}], ['control 2', {'chart': {'equipment': 'asset', 'wages': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J3', [['wages', 'D', 250], ['rent', 'C', 250]]], ['J2', [['receivable', 'D', 250], ['suspense', 'C', 250]]], ['J1', [['loan', 'C', 1199], ['wages', 'D', 1200]]], ['J3', [['sales', 'C', 100], ['receivable', 'D', 100]]]]}, {'balances': {'equipment': 0, 'wages': 250, 'capital': 0, 'receivable': 0, 'sales': 0, 'rent': -250, 'loan': 0}, 'rejected': ['J2', 'J1', 'J3']}], ['control 3', {'chart': {'wages': 'expense', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'receivable': 'asset', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J4', [['cash', 'D', 250], ['sales', 'C', 249]]], ['J2', [['sales', 'C', 1200], ['drawings', 'D', 1200], ['equipment', 'C', 0], ['equipment', 'D', 0]]], ['J3', [['wages', 'C', -100], ['payable', 'D', -100]]]]}, {'balances': {'wages': 0, 'drawings': 0, 'payable': 0, 'equipment': 0, 'sales': 0, 'receivable': 0, 'cash': 0, 'capital': 0}, 'rejected': ['J4', 'J2', 'J3']}], ['control 4', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'loan': 'liability', 'capital': 'equity', 'equipment': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['equipment', 'C', 40], ['drawings', 'D', 40]]], ['J1', [['wages', 'D', 30], ['acc_depr', 'C', 1200], ['wages', 'D', 1170]]], ['J3', [['capital', 'C', 0], ['drawings', 'D', 1200], ['acc_depr', 'C', 1200], ['capital', 'D', 0]]], ['J1', [['drawings', 'C', 100], ['acc_depr', 'D', 100]]]]}, {'balances': {'drawings': 40, 'acc_depr': 0, 'loan': 0, 'capital': 0, 'equipment': -40, 'wages': 0}, 'rejected': ['J1', 'J3', 'J1']}], ['control 5', {'chart': {'equipment': 'asset', 'payable': 'liability', 'rent': 'expense', 'drawings': 'dividend', 'cash': 'asset', 'wages': 'expense', 'capital': 'equity'}, 'entries': [['J5', [['equipment', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J5', [['cash', 'D', 999], ['drawings', 'C', 1000]]], ['J4', [['capital', 'C', 100], ['cash', 'D', 100]]], ['J1', [['payable', 'D', 250], ['cash', 'C', 250], ['wages', 'C', 0], ['wages', 'D', 0]]], ['J4', [['capital', 'D', 999], ['wages', 'C', 999]]], ['J4', [['wages', 'C', 260], ['drawings', 'D', 250]]]]}, {'balances': {'equipment': -100, 'payable': 0, 'rent': 0, 'drawings': 0, 'cash': 100, 'wages': 0, 'capital': 0}, 'rejected': ['J5', 'J1', 'J4', 'J4']}], ['control 6', {'chart': {'rent': 'expense', 'capital': 'equity', 'cash': 'asset', 'drawings': 'dividend', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['rent', 'D', 5000], ['drawings', 'C', 5000]]], ['J4', [['rent', 'C', 100], ['cash', 'D', 100]]], ['J5', []]]}, {'balances': {'rent': 4900, 'capital': 0, 'cash': 100, 'drawings': -5000, 'acc_depr': 0}, 'rejected': ['J5']}]], [['regression: posting sign by side and normal balance', {'chart': {'equipment': 'asset', 'capital': 'equity', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J5', [['sales', 'D', 1200], ['loan', 'C', 1200]]], ['J3', [['capital', 'D', 999], ['sales', 'C', 999]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]], ['J1', [['capital', 'D', 100], ['sales', 'C', 100]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['capital', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'equipment': -5000, 'capital': -1998, 'sales': -201, 'rent': 4101, 'loan': 1300}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'capital': 'equity', 'equipment': 'asset', 'cash': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['acc_depr', 'C', 0], ['acc_depr', 'D', 0], ['drawings', 'C', 999], ['capital', 'D', 999]]], ['J4', [['equipment', 'D', -250], ['drawings', 'C', -250]]], ['J2', [['receivable', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'capital': 0, 'equipment': 0, 'cash': 0, 'drawings': -100, 'rent': 0, 'receivable': 100, 'acc_depr': 0}, 'rejected': ['J4', 'J4']}], ['control 2', {'chart': {'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'rent': 'expense', 'capital': 'equity', 'cash': 'asset'}, 'entries': [['J3', [['cash', 'D', -999], ['rent', 'C', -999]]], ['J3', [['receivable', 'C', 1200], ['drawings', 'D', 1200]]], ['J3', [['drawings', 'C', 0], ['drawings', 'D', 0], ['rent', 'D', 100], ['receivable', 'C', 100]]], ['J2', [['drawings', 'C', 41], ['rent', 'D', 40]]], ['J1', [['drawings', 'D', -5000], ['cash', 'C', -5000]]]]}, {'balances': {'sales': 0, 'drawings': 1200, 'receivable': -1200, 'rent': 0, 'capital': 0, 'cash': 0}, 'rejected': ['J3', 'J3', 'J2', 'J1']}], ['control 3', {'chart': {'rent': 'expense', 'receivable': 'asset', 'drawings': 'dividend', 'loan': 'liability', 'wages': 'expense'}, 'entries': [['J5', [['wages', 'C', 251], ['loan', 'D', 250]]], ['J4', [['wages', 'C', 260], ['rent', 'D', 250]]], ['J4', [['wages', 'D', 999], ['receivable', 'C', 999]]], ['J1', [['drawings', 'D', 969], ['drawings', 'D', 30], ['receivable', 'C', 999]]]]}, {'balances': {'rent': 0, 'receivable': -1998, 'drawings': 999, 'loan': 0, 'wages': 999}, 'rejected': ['J5', 'J4']}], ['control 4', {'chart': {'rent': 'expense', 'cash': 'asset', 'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend'}, 'entries': [['J1', [['equipment', 'D', 5000], ['cash', 'C', 5000]]], ['J5', [['suspense', 'C', 1200], ['sales', 'D', 1200]]], ['J3', [['rent', 'D', 1200], ['drawings', 'C', 0], ['drawings', 'D', 0], ['cash', 'C', 1200]]], ['J4', []], ['J3', []]]}, {'balances': {'rent': 0, 'cash': -5000, 'equipment': 5000, 'sales': 0, 'drawings': 0}, 'rejected': ['J5', 'J3', 'J4', 'J3']}], ['control 5', {'chart': {'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'sales': 'revenue', 'loan': 'liability', 'drawings': 'dividend'}, 'entries': [['J5', [['wages', 'C', 260], ['equipment', 'D', 250]]], ['J3', [['loan', 'C', -250], ['payable', 'D', -250]]], ['J4', [['wages', 'D', 4970], ['wages', 'D', 30], ['equipment', 'C', 5000]]], ['J4', [['drawings', 'C', 40], ['wages', 'D', 30], ['wages', 'D', 10]]], ['J2', [['wages', 'D', 250], ['receivable', 'C', 250]]], ['J5', [['equipment', 'C', 999], ['drawings', 'D', 999]]], ['J2', [['drawings', 'C', 1200], ['receivable', 'D', 1200]]]]}, {'balances': {'payable': 0, 'wages': 5250, 'equipment': -5999, 'receivable': -250, 'sales': 0, 'loan': 0, 'drawings': 999}, 'rejected': ['J5', 'J3', 'J4', 'J2']}], ['control 6', {'chart': {'rent': 'expense', 'cash': 'asset', 'acc_depr': 'contra_asset', 'receivable': 'asset', 'equipment': 'asset'}, 'entries': [['J1', [['cash', 'D', 999], ['equipment', 'C', 999]]], ['J2', [['acc_depr', 'C', 998], ['rent', 'D', 999]]], ['J5', [['equipment', 'D', 1200], ['acc_depr', 'C', 1200]]], ['J5', [['cash', 'C', 100], ['rent', 'D', 70], ['rent', 'D', 30]]], ['J1', [['cash', 'D', 30], ['equipment', 'C', 1200], ['cash', 'D', 1170]]], ['J2', [['acc_depr', 'D', 1200], ['rent', 'C', 1200]]]]}, {'balances': {'rent': -1200, 'cash': 999, 'acc_depr': 0, 'receivable': 0, 'equipment': 201}, 'rejected': ['J2', 'J5', 'J1']}]], [['regression: posting sign by side and normal balance', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'loan': 'liability'}, 'entries': [['J3', [['loan', 'D', 999], ['receivable', 'C', 999]]], ['J5', [['loan', 'C', 5000], ['sales', 'D', 0], ['drawings', 'D', 5000], ['sales', 'C', 0]]], ['J2', [['drawings', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 30], ['equipment', 'C', 100], ['sales', 'D', 70]]]]}, {'balances': {'equipment': -100, 'sales': -100, 'drawings': 0, 'receivable': -999, 'loan': -999}, 'rejected': ['J5', 'J2']}], ['control 1', {'chart': {'rent': 'expense', 'drawings': 'dividend', 'cash': 'asset', 'payable': 'liability', 'wages': 'expense'}, 'entries': [['J2', [['cash', 'D', 5000], ['rent', 'C', 5000]]], ['J4', [['rent', 'C', 250], ['cash', 'D', 250]]], ['J4', [['payable', 'D', 30], ['payable', 'D', 10], ['drawings', 'C', 40]]], ['J4', [['payable', 'D', 30], ['rent', 'C', 999], ['payable', 'D', 969]]], ['J2', [['drawings', 'D', 5000], ['suspense', 'C', 5000]]]]}, {'balances': {'rent': -5250, 'drawings': 0, 'cash': 5250, 'payable': 0, 'wages': 0}, 'rejected': ['J4', 'J4', 'J2']}], ['control 2', {'chart': {'drawings': 'dividend', 'cash': 'asset', 'receivable': 'asset', 'loan': 'liability', 'acc_depr': 'contra_asset', 'equipment': 'asset'}, 'entries': [['J1', [['receivable', 'D', 40], ['acc_depr', 'C', 0], ['drawings', 'C', 40], ['acc_depr', 'D', 0]]], ['J5', [['receivable', 'D', 70], ['receivable', 'D', 30], ['equipment', 'C', 100]]], ['J3', [['cash', 'D', 4970], ['receivable', 'C', 5000], ['cash', 'D', 30]]], ['J3', [['receivable', 'C', 40], ['cash', 'D', 40]]], ['J3', [['receivable', 'D', 220], ['acc_depr', 'C', 250], ['receivable', 'D', 30]]], ['J5', [['drawings', 'D', 999], ['acc_depr', 'C', 999]]]]}, {'balances': {'drawings': 0, 'cash': 5000, 'receivable': -4900, 'loan': 0, 'acc_depr': 0, 'equipment': -100}, 'rejected': ['J1', 'J3', 'J3', 'J5']}], ['control 3', {'chart': {'equipment': 'asset', 'receivable': 'asset', 'loan': 'liability', 'wages': 'expense', 'drawings': 'dividend', 'cash': 'asset'}, 'entries': [['J3', [['cash', 'C', 100], ['equipment', 'D', 100]]], ['J2', [['receivable', 'D', -100], ['cash', 'C', -100]]], ['J1', [['suspense', 'C', 1200], ['cash', 'D', 1200]]], ['J2', [['receivable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['cash', 'D', 40], ['equipment', 'C', 40]]], ['J4', []], ['J2', [['receivable', 'D', 40], ['cash', 'C', 39]]]]}, {'balances': {'equipment': 60, 'receivable': 40, 'loan': 0, 'wages': 0, 'drawings': 0, 'cash': -100}, 'rejected': ['J2', 'J1', 'J3', 'J4', 'J2']}], ['control 4', {'chart': {'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'sales': 'revenue'}, 'entries': [['J4', [['capital', 'D', -999], ['equipment', 'C', -999]]], ['J4', [['suspense', 'C', 5000], ['capital', 'D', 5000]]], ['J5', [['receivable', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'wages': 0, 'equipment': 0, 'receivable': 0, 'drawings': 0, 'capital': 0, 'sales': 0}, 'rejected': ['J4', 'J4', 'J5']}], ['control 5', {'chart': {'receivable': 'asset', 'capital': 'equity', 'sales': 'revenue', 'cash': 'asset', 'wages': 'expense', 'drawings': 'dividend', 'loan': 'liability'}, 'entries': [['J1', [['capital', 'D', -40], ['wages', 'C', -40]]], ['J4', [['cash', 'C', 250], ['receivable', 'D', 250]]], ['J1', [['cash', 'D', 999], ['wages', 'C', 999]]]]}, {'balances': {'receivable': 250, 'capital': 0, 'sales': 0, 'cash': 749, 'wages': -999, 'drawings': 0, 'loan': 0}, 'rejected': ['J1']}], ['control 6', {'chart': {'payable': 'liability', 'receivable': 'asset', 'wages': 'expense', 'drawings': 'dividend', 'loan': 'liability', 'equipment': 'asset', 'capital': 'equity', 'rent': 'expense'}, 'entries': [['J1', [['receivable', 'C', 100], ['equipment', 'D', 100]]], ['J1', [['equipment', 'C', 5000], ['payable', 'D', 4970], ['payable', 'D', 30]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]]]}, {'balances': {'payable': 0, 'receivable': -100, 'wages': 0, 'drawings': 0, 'loan': 0, 'equipment': 100, 'capital': 0, 'rent': 0}, 'rejected': ['J1', 'J1']}]], [['regression: posting sign by side and normal balance', {'chart': {'cash': 'asset', 'acc_depr': 'contra_asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J1', [['loan', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['loan', 'C', 1200]]], ['J2', [['cash', 'C', -250], ['receivable', 'D', -250]]], ['J4', [['capital', 'D', 4970], ['capital', 'D', 30], ['receivable', 'C', 5000]]], ['J3', [['loan', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['cash', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'cash': 999, 'acc_depr': -1200, 'capital': -100, 'rent': -999, 'loan': 2299, 'receivable': 999}, 'rejected': ['J2', 'J4']}], ['control 1', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'payable': 'liability', 'loan': 'liability'}, 'entries': [['J1', [['receivable', 'C', 999], ['equipment', 'D', 999]]], ['J5', []], ['J3', [['sales', 'D', 5000], ['payable', 'C', 5010]]], ['J1', [['loan', 'D', 40], ['receivable', 'C', 40]]]]}, {'balances': {'equipment': 999, 'drawings': 0, 'rent': 0, 'capital': 0, 'receivable': -999, 'sales': 0, 'payable': 0, 'loan': 0}, 'rejected': ['J5', 'J3', 'J1']}], ['control 2', {'chart': {'payable': 'liability', 'acc_depr': 'contra_asset', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset'}, 'entries': [['J5', [['cash', 'D', 1200], ['equipment', 'C', 1200]]], ['J5', [['payable', 'D', 5000], ['sales', 'D', 0], ['equipment', 'C', 5000], ['sales', 'C', 0]]], ['J5', [['sales', 'C', 999], ['cash', 'D', 999]]], ['J2', [['sales', 'C', -5000], ['acc_depr', 'D', -5000]]], ['J3', [['cash', 'D', 1200], ['equipment', 'C', 1200]]], ['J4', [['cash', 'C', 5001], ['payable', 'D', 5000]]], ['J2', [['cash', 'D', 250], ['equipment', 'C', 260]]]]}, {'balances': {'payable': 0, 'acc_depr': 0, 'sales': 0, 'equipment': -2400, 'cash': 2400}, 'rejected': ['J5', 'J5', 'J2', 'J4', 'J2']}], ['control 3', {'chart': {'receivable': 'asset', 'acc_depr': 'contra_asset', 'equipment': 'asset', 'wages': 'expense', 'cash': 'asset', 'loan': 'liability', 'drawings': 'dividend'}, 'entries': [['J4', [['wages', 'C', 5000], ['equipment', 'D', 5000]]], ['J3', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J5', [['receivable', 'D', -5000], ['cash', 'C', -5000]]], ['J5', [['wages', 'C', -40], ['acc_depr', 'D', -40]]]]}, {'balances': {'receivable': -40, 'acc_depr': 0, 'equipment': 5000, 'wages': -5000, 'cash': 0, 'loan': 0, 'drawings': 40}, 'rejected': ['J5', 'J5']}], ['control 4', {'chart': {'cash': 'asset', 'wages': 'expense', 'loan': 'liability', 'sales': 'revenue', 'receivable': 'asset'}, 'entries': [['J3', [['receivable', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['sales', 'C', -250], ['cash', 'D', -250]]], ['J5', [['loan', 'D', 5000], ['sales', 'C', 5001]]], ['J2', [['receivable', 'D', 1170], ['receivable', 'D', 30], ['wages', 'C', 1200]]], ['J2', []], ['J5', [['sales', 'D', 0], ['sales', 'C', 0], ['wages', 'C', 999], ['receivable', 'D', 999]]]]}, {'balances': {'cash': 0, 'wages': -2400, 'loan': 0, 'sales': 0, 'receivable': 2400}, 'rejected': ['J2', 'J5', 'J2', 'J5']}], ['control 5', {'chart': {'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'capital': 'equity', 'payable': 'liability', 'drawings': 'dividend', 'acc_depr': 'contra_asset'}, 'entries': [['J5', [['wages', 'D', 100], ['rent', 'C', 100]]], ['J5', [['receivable', 'D', -1200], ['drawings', 'C', -1200]]], ['J3', [['acc_depr', 'D', 0], ['drawings', 'C', 100], ['receivable', 'D', 100], ['acc_depr', 'C', 0]]], ['J5', [['payable', 'D', 999], ['receivable', 'C', 999]]], ['J1', [['rent', 'D', 999], ['drawings', 'C', 999]]], ['J2', [['drawings', 'D', 40], ['rent', 'C', 40]]]]}, {'balances': {'wages': 100, 'receivable': 0, 'rent': 859, 'capital': 0, 'payable': 0, 'drawings': -959, 'acc_depr': 0}, 'rejected': ['J5', 'J3', 'J5']}], ['control 6', {'chart': {'loan': 'liability', 'receivable': 'asset', 'payable': 'liability', 'drawings': 'dividend', 'wages': 'expense'}, 'entries': [['J5', [['wages', 'D', 5000], ['receivable', 'C', 5000]]], ['J2', [['payable', 'D', 250], ['loan', 'D', 0], ['loan', 'C', 0], ['receivable', 'C', 250]]], ['J1', [['payable', 'C', 39], ['wages', 'D', 40]]]]}, {'balances': {'loan': 0, 'receivable': -5000, 'payable': 0, 'drawings': 0, 'wages': 5000}, 'rejected': ['J2', 'J1']}]]]
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):
    chart = x['chart']
    debit_normal = {'asset', 'expense', 'dividend'}
    bal = {a: 0 for a in chart}
    rejected = []
    posted = set()
    for eid, lines in x['entries']:
        ok = eid not in posted and len(lines) >= 2
        dr = cr = 0
        for acct, side, amt in lines:
            if acct not in chart or side not in ('D', 'C') or amt <= 0:
                ok = False
            elif side == 'D':
                dr += amt
            else:
                cr += amt
        if not ok or dr != cr:
            rejected.append(eid)
            continue
        posted.add(eid)
        for acct, side, amt in lines:
            sign = 1 if side == 'D' or chart[acct] not in debit_normal else -1
            bal[acct] += sign * amt
    return {'balances': bal, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: posting sign by side and normal balance', {'chart': {'acc_depr': 'contra_asset', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'capital': 'equity'}, 'entries': [['J1', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['equipment', 'C', 5000], ['payable', 'D', 5000]]], ['J1', [['acc_depr', 'C', 1200], ['payable', 'D', 1170], ['payable', 'D', 30]]], ['J4', [['equipment', 'C', 5000], ['acc_depr', 'D', 4970], ['acc_depr', 'D', 30]]], ['J3', [['acc_depr', 'D', -40], ['equipment', 'C', -40]]]]}, {'balances': {'acc_depr': -5000, 'drawings': 0, 'payable': -5040, 'equipment': -10040, 'capital': 0}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 999], ['sales', 'D', 999]]], ['J5', [['wages', 'C', 250], ['equipment', 'D', 250]]], ['J3', [['wages', 'C', 40], ['rent', 'D', 40]]], ['J5', [['drawings', 'C', 100], ['wages', 'C', 0], ['sales', 'D', 100], ['wages', 'D', 0]]], ['J4', [['equipment', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['rent', 'D', 100], ['equipment', 'C', 100]]]]}, {'balances': {'capital': 0, 'rent': 140, 'cash': 0, 'receivable': 0, 'drawings': 0, 'equipment': 1350, 'wages': -1490, 'sales': 0}, 'rejected': ['J2', 'J5']}], ['control 2', {'chart': {'drawings': 'dividend', 'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J4', [['receivable', 'C', 5000], ['cash', 'D', 4970], ['cash', 'D', 30]]], ['J1', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J3', []]]}, {'balances': {'drawings': 40, 'wages': 0, 'receivable': -5040, 'rent': 0, 'cash': 5000}, 'rejected': ['J3']}], ['control 3', {'chart': {'receivable': 'asset', 'equipment': 'asset', 'drawings': 'dividend', 'payable': 'liability', 'wages': 'expense', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J3', [['receivable', 'D', 999], ['equipment', 'C', 999]]], ['J1', [['receivable', 'D', 100], ['payable', 'C', 100]]], ['J4', [['payable', 'D', 100], ['rent', 'C', 100]]], ['J1', [['rent', 'D', 999], ['wages', 'C', 999]]], ['J2', [['drawings', 'C', 250], ['wages', 'D', 250]]], ['J3', [['rent', 'C', 40], ['payable', 'D', 40]]], ['J2', [['equipment', 'C', 250], ['cash', 'D', 250]]]]}, {'balances': {'receivable': 1099, 'equipment': -999, 'drawings': -250, 'payable': 0, 'wages': 250, 'cash': 0, 'rent': -100}, 'rejected': ['J1', 'J3', 'J2']}], ['control 4', {'chart': {'cash': 'asset', 'equipment': 'asset', 'receivable': 'asset', 'wages': 'expense', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J2', [['receivable', 'C', 5000], ['wages', 'D', 5000]]], ['J3', [['rent', 'D', 1200], ['cash', 'C', 1200]]], ['J4', [['equipment', 'D', 250], ['receivable', 'C', 250]]]]}, {'balances': {'cash': -1200, 'equipment': 250, 'receivable': -5250, 'wages': 5000, 'acc_depr': 0, 'rent': 1200}, 'rejected': []}], ['control 5', {'chart': {'cash': 'asset', 'equipment': 'asset', 'payable': 'liability', 'drawings': 'dividend', 'loan': 'liability', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J4', [['cash', 'D', -999], ['rent', 'C', -999]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J4', [['rent', 'C', 40], ['payable', 'D', 40]]], ['J3', [['rent', 'D', -999], ['cash', 'C', -999]]], ['J1', [['payable', 'C', 0], ['rent', 'C', 5000], ['cash', 'D', 5000], ['payable', 'D', 0]]]]}, {'balances': {'cash': 0, 'equipment': -5000, 'payable': 0, 'drawings': 0, 'loan': 0, 'acc_depr': 0, 'rent': 5000}, 'rejected': ['J4', 'J4', 'J3', 'J1']}], ['control 6', {'chart': {'rent': 'expense', 'sales': 'revenue', 'capital': 'equity', 'payable': 'liability', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'receivable': 'asset'}, 'entries': [['J3', [['capital', 'D', -40], ['equipment', 'C', -40]]], ['J5', [['receivable', 'D', 999], ['drawings', 'C', 0], ['drawings', 'D', 0], ['rent', 'C', 999]]], ['J2', [['sales', 'C', 40], ['receivable', 'D', 40], ['rent', 'D', 0], ['rent', 'C', 0]]], ['J5', [['equipment', 'D', 1200], ['drawings', 'C', 1200]]], ['J2', [['wages', 'C', 40], ['receivable', 'D', 40]]], ['J5', [['sales', 'D', 250], ['drawings', 'C', 250]]], ['J4', [['equipment', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'rent': 0, 'sales': 0, 'capital': 0, 'payable': 0, 'drawings': -1200, 'equipment': 1200, 'wages': -40, 'receivable': 40}, 'rejected': ['J3', 'J5', 'J2', 'J5', 'J4']}]], [['regression: posting sign by side and normal balance', {'chart': {'acc_depr': 'contra_asset', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense'}, 'entries': [['J3', [['acc_depr', 'D', 30], ['acc_depr', 'D', 4970], ['loan', 'C', 5000]]], ['J2', [['loan', 'D', 4970], ['loan', 'D', 30], ['acc_depr', 'C', 5000]]], ['J3', [['loan', 'D', 5000], ['wages', 'C', 4999]]], ['J4', [['sales', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['loan', 'C', 40], ['sales', 'D', 40]]]]}, {'balances': {'acc_depr': 999, 'loan': 0, 'equipment': 0, 'sales': -999, 'wages': 0}, 'rejected': ['J3', 'J3']}], ['control 1', {'chart': {'drawings': 'dividend', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['drawings', 'C', 1200], ['equipment', 'D', 1200]]], ['J3', [['receivable', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['drawings', 'C', 999]]]]}, {'balances': {'drawings': -1949, 'sales': 0, 'equipment': 1200, 'cash': 0, 'receivable': 749}, 'rejected': []}], ['control 2', {'chart': {'equipment': 'asset', 'wages': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J3', [['wages', 'D', 250], ['rent', 'C', 250]]], ['J2', [['receivable', 'D', 250], ['suspense', 'C', 250]]], ['J1', [['loan', 'C', 1199], ['wages', 'D', 1200]]], ['J3', [['sales', 'C', 100], ['receivable', 'D', 100]]]]}, {'balances': {'equipment': 0, 'wages': 250, 'capital': 0, 'receivable': 0, 'sales': 0, 'rent': -250, 'loan': 0}, 'rejected': ['J2', 'J1', 'J3']}], ['control 3', {'chart': {'wages': 'expense', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'receivable': 'asset', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J4', [['cash', 'D', 250], ['sales', 'C', 249]]], ['J2', [['sales', 'C', 1200], ['drawings', 'D', 1200], ['equipment', 'C', 0], ['equipment', 'D', 0]]], ['J3', [['wages', 'C', -100], ['payable', 'D', -100]]]]}, {'balances': {'wages': 0, 'drawings': 0, 'payable': 0, 'equipment': 0, 'sales': 0, 'receivable': 0, 'cash': 0, 'capital': 0}, 'rejected': ['J4', 'J2', 'J3']}], ['control 4', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'loan': 'liability', 'capital': 'equity', 'equipment': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['equipment', 'C', 40], ['drawings', 'D', 40]]], ['J1', [['wages', 'D', 30], ['acc_depr', 'C', 1200], ['wages', 'D', 1170]]], ['J3', [['capital', 'C', 0], ['drawings', 'D', 1200], ['acc_depr', 'C', 1200], ['capital', 'D', 0]]], ['J1', [['drawings', 'C', 100], ['acc_depr', 'D', 100]]]]}, {'balances': {'drawings': 40, 'acc_depr': 0, 'loan': 0, 'capital': 0, 'equipment': -40, 'wages': 0}, 'rejected': ['J1', 'J3', 'J1']}], ['control 5', {'chart': {'equipment': 'asset', 'payable': 'liability', 'rent': 'expense', 'drawings': 'dividend', 'cash': 'asset', 'wages': 'expense', 'capital': 'equity'}, 'entries': [['J5', [['equipment', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J5', [['cash', 'D', 999], ['drawings', 'C', 1000]]], ['J4', [['capital', 'C', 100], ['cash', 'D', 100]]], ['J1', [['payable', 'D', 250], ['cash', 'C', 250], ['wages', 'C', 0], ['wages', 'D', 0]]], ['J4', [['capital', 'D', 999], ['wages', 'C', 999]]], ['J4', [['wages', 'C', 260], ['drawings', 'D', 250]]]]}, {'balances': {'equipment': -100, 'payable': 0, 'rent': 0, 'drawings': 0, 'cash': 100, 'wages': 0, 'capital': 0}, 'rejected': ['J5', 'J1', 'J4', 'J4']}], ['control 6', {'chart': {'rent': 'expense', 'capital': 'equity', 'cash': 'asset', 'drawings': 'dividend', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['rent', 'D', 5000], ['drawings', 'C', 5000]]], ['J4', [['rent', 'C', 100], ['cash', 'D', 100]]], ['J5', []]]}, {'balances': {'rent': 4900, 'capital': 0, 'cash': 100, 'drawings': -5000, 'acc_depr': 0}, 'rejected': ['J5']}]], [['regression: posting sign by side and normal balance', {'chart': {'equipment': 'asset', 'capital': 'equity', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J5', [['sales', 'D', 1200], ['loan', 'C', 1200]]], ['J3', [['capital', 'D', 999], ['sales', 'C', 999]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]], ['J1', [['capital', 'D', 100], ['sales', 'C', 100]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['capital', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'equipment': -5000, 'capital': -1998, 'sales': -201, 'rent': 4101, 'loan': 1300}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'capital': 'equity', 'equipment': 'asset', 'cash': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['acc_depr', 'C', 0], ['acc_depr', 'D', 0], ['drawings', 'C', 999], ['capital', 'D', 999]]], ['J4', [['equipment', 'D', -250], ['drawings', 'C', -250]]], ['J2', [['receivable', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'capital': 0, 'equipment': 0, 'cash': 0, 'drawings': -100, 'rent': 0, 'receivable': 100, 'acc_depr': 0}, 'rejected': ['J4', 'J4']}], ['control 2', {'chart': {'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'rent': 'expense', 'capital': 'equity', 'cash': 'asset'}, 'entries': [['J3', [['cash', 'D', -999], ['rent', 'C', -999]]], ['J3', [['receivable', 'C', 1200], ['drawings', 'D', 1200]]], ['J3', [['drawings', 'C', 0], ['drawings', 'D', 0], ['rent', 'D', 100], ['receivable', 'C', 100]]], ['J2', [['drawings', 'C', 41], ['rent', 'D', 40]]], ['J1', [['drawings', 'D', -5000], ['cash', 'C', -5000]]]]}, {'balances': {'sales': 0, 'drawings': 1200, 'receivable': -1200, 'rent': 0, 'capital': 0, 'cash': 0}, 'rejected': ['J3', 'J3', 'J2', 'J1']}], ['control 3', {'chart': {'rent': 'expense', 'receivable': 'asset', 'drawings': 'dividend', 'loan': 'liability', 'wages': 'expense'}, 'entries': [['J5', [['wages', 'C', 251], ['loan', 'D', 250]]], ['J4', [['wages', 'C', 260], ['rent', 'D', 250]]], ['J4', [['wages', 'D', 999], ['receivable', 'C', 999]]], ['J1', [['drawings', 'D', 969], ['drawings', 'D', 30], ['receivable', 'C', 999]]]]}, {'balances': {'rent': 0, 'receivable': -1998, 'drawings': 999, 'loan': 0, 'wages': 999}, 'rejected': ['J5', 'J4']}], ['control 4', {'chart': {'rent': 'expense', 'cash': 'asset', 'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend'}, 'entries': [['J1', [['equipment', 'D', 5000], ['cash', 'C', 5000]]], ['J5', [['suspense', 'C', 1200], ['sales', 'D', 1200]]], ['J3', [['rent', 'D', 1200], ['drawings', 'C', 0], ['drawings', 'D', 0], ['cash', 'C', 1200]]], ['J4', []], ['J3', []]]}, {'balances': {'rent': 0, 'cash': -5000, 'equipment': 5000, 'sales': 0, 'drawings': 0}, 'rejected': ['J5', 'J3', 'J4', 'J3']}], ['control 5', {'chart': {'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'sales': 'revenue', 'loan': 'liability', 'drawings': 'dividend'}, 'entries': [['J5', [['wages', 'C', 260], ['equipment', 'D', 250]]], ['J3', [['loan', 'C', -250], ['payable', 'D', -250]]], ['J4', [['wages', 'D', 4970], ['wages', 'D', 30], ['equipment', 'C', 5000]]], ['J4', [['drawings', 'C', 40], ['wages', 'D', 30], ['wages', 'D', 10]]], ['J2', [['wages', 'D', 250], ['receivable', 'C', 250]]], ['J5', [['equipment', 'C', 999], ['drawings', 'D', 999]]], ['J2', [['drawings', 'C', 1200], ['receivable', 'D', 1200]]]]}, {'balances': {'payable': 0, 'wages': 5250, 'equipment': -5999, 'receivable': -250, 'sales': 0, 'loan': 0, 'drawings': 999}, 'rejected': ['J5', 'J3', 'J4', 'J2']}], ['control 6', {'chart': {'rent': 'expense', 'cash': 'asset', 'acc_depr': 'contra_asset', 'receivable': 'asset', 'equipment': 'asset'}, 'entries': [['J1', [['cash', 'D', 999], ['equipment', 'C', 999]]], ['J2', [['acc_depr', 'C', 998], ['rent', 'D', 999]]], ['J5', [['equipment', 'D', 1200], ['acc_depr', 'C', 1200]]], ['J5', [['cash', 'C', 100], ['rent', 'D', 70], ['rent', 'D', 30]]], ['J1', [['cash', 'D', 30], ['equipment', 'C', 1200], ['cash', 'D', 1170]]], ['J2', [['acc_depr', 'D', 1200], ['rent', 'C', 1200]]]]}, {'balances': {'rent': -1200, 'cash': 999, 'acc_depr': 0, 'receivable': 0, 'equipment': 201}, 'rejected': ['J2', 'J5', 'J1']}]], [['regression: posting sign by side and normal balance', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'loan': 'liability'}, 'entries': [['J3', [['loan', 'D', 999], ['receivable', 'C', 999]]], ['J5', [['loan', 'C', 5000], ['sales', 'D', 0], ['drawings', 'D', 5000], ['sales', 'C', 0]]], ['J2', [['drawings', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 30], ['equipment', 'C', 100], ['sales', 'D', 70]]]]}, {'balances': {'equipment': -100, 'sales': -100, 'drawings': 0, 'receivable': -999, 'loan': -999}, 'rejected': ['J5', 'J2']}], ['control 1', {'chart': {'rent': 'expense', 'drawings': 'dividend', 'cash': 'asset', 'payable': 'liability', 'wages': 'expense'}, 'entries': [['J2', [['cash', 'D', 5000], ['rent', 'C', 5000]]], ['J4', [['rent', 'C', 250], ['cash', 'D', 250]]], ['J4', [['payable', 'D', 30], ['payable', 'D', 10], ['drawings', 'C', 40]]], ['J4', [['payable', 'D', 30], ['rent', 'C', 999], ['payable', 'D', 969]]], ['J2', [['drawings', 'D', 5000], ['suspense', 'C', 5000]]]]}, {'balances': {'rent': -5250, 'drawings': 0, 'cash': 5250, 'payable': 0, 'wages': 0}, 'rejected': ['J4', 'J4', 'J2']}], ['control 2', {'chart': {'drawings': 'dividend', 'cash': 'asset', 'receivable': 'asset', 'loan': 'liability', 'acc_depr': 'contra_asset', 'equipment': 'asset'}, 'entries': [['J1', [['receivable', 'D', 40], ['acc_depr', 'C', 0], ['drawings', 'C', 40], ['acc_depr', 'D', 0]]], ['J5', [['receivable', 'D', 70], ['receivable', 'D', 30], ['equipment', 'C', 100]]], ['J3', [['cash', 'D', 4970], ['receivable', 'C', 5000], ['cash', 'D', 30]]], ['J3', [['receivable', 'C', 40], ['cash', 'D', 40]]], ['J3', [['receivable', 'D', 220], ['acc_depr', 'C', 250], ['receivable', 'D', 30]]], ['J5', [['drawings', 'D', 999], ['acc_depr', 'C', 999]]]]}, {'balances': {'drawings': 0, 'cash': 5000, 'receivable': -4900, 'loan': 0, 'acc_depr': 0, 'equipment': -100}, 'rejected': ['J1', 'J3', 'J3', 'J5']}], ['control 3', {'chart': {'equipment': 'asset', 'receivable': 'asset', 'loan': 'liability', 'wages': 'expense', 'drawings': 'dividend', 'cash': 'asset'}, 'entries': [['J3', [['cash', 'C', 100], ['equipment', 'D', 100]]], ['J2', [['receivable', 'D', -100], ['cash', 'C', -100]]], ['J1', [['suspense', 'C', 1200], ['cash', 'D', 1200]]], ['J2', [['receivable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['cash', 'D', 40], ['equipment', 'C', 40]]], ['J4', []], ['J2', [['receivable', 'D', 40], ['cash', 'C', 39]]]]}, {'balances': {'equipment': 60, 'receivable': 40, 'loan': 0, 'wages': 0, 'drawings': 0, 'cash': -100}, 'rejected': ['J2', 'J1', 'J3', 'J4', 'J2']}], ['control 4', {'chart': {'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'sales': 'revenue'}, 'entries': [['J4', [['capital', 'D', -999], ['equipment', 'C', -999]]], ['J4', [['suspense', 'C', 5000], ['capital', 'D', 5000]]], ['J5', [['receivable', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'wages': 0, 'equipment': 0, 'receivable': 0, 'drawings': 0, 'capital': 0, 'sales': 0}, 'rejected': ['J4', 'J4', 'J5']}], ['control 5', {'chart': {'receivable': 'asset', 'capital': 'equity', 'sales': 'revenue', 'cash': 'asset', 'wages': 'expense', 'drawings': 'dividend', 'loan': 'liability'}, 'entries': [['J1', [['capital', 'D', -40], ['wages', 'C', -40]]], ['J4', [['cash', 'C', 250], ['receivable', 'D', 250]]], ['J1', [['cash', 'D', 999], ['wages', 'C', 999]]]]}, {'balances': {'receivable': 250, 'capital': 0, 'sales': 0, 'cash': 749, 'wages': -999, 'drawings': 0, 'loan': 0}, 'rejected': ['J1']}], ['control 6', {'chart': {'payable': 'liability', 'receivable': 'asset', 'wages': 'expense', 'drawings': 'dividend', 'loan': 'liability', 'equipment': 'asset', 'capital': 'equity', 'rent': 'expense'}, 'entries': [['J1', [['receivable', 'C', 100], ['equipment', 'D', 100]]], ['J1', [['equipment', 'C', 5000], ['payable', 'D', 4970], ['payable', 'D', 30]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]]]}, {'balances': {'payable': 0, 'receivable': -100, 'wages': 0, 'drawings': 0, 'loan': 0, 'equipment': 100, 'capital': 0, 'rent': 0}, 'rejected': ['J1', 'J1']}]], [['regression: posting sign by side and normal balance', {'chart': {'cash': 'asset', 'acc_depr': 'contra_asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J1', [['loan', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['loan', 'C', 1200]]], ['J2', [['cash', 'C', -250], ['receivable', 'D', -250]]], ['J4', [['capital', 'D', 4970], ['capital', 'D', 30], ['receivable', 'C', 5000]]], ['J3', [['loan', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['cash', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'cash': 999, 'acc_depr': -1200, 'capital': -100, 'rent': -999, 'loan': 2299, 'receivable': 999}, 'rejected': ['J2', 'J4']}], ['control 1', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'payable': 'liability', 'loan': 'liability'}, 'entries': [['J1', [['receivable', 'C', 999], ['equipment', 'D', 999]]], ['J5', []], ['J3', [['sales', 'D', 5000], ['payable', 'C', 5010]]], ['J1', [['loan', 'D', 40], ['receivable', 'C', 40]]]]}, {'balances': {'equipment': 999, 'drawings': 0, 'rent': 0, 'capital': 0, 'receivable': -999, 'sales': 0, 'payable': 0, 'loan': 0}, 'rejected': ['J5', 'J3', 'J1']}], ['control 2', {'chart': {'payable': 'liability', 'acc_depr': 'contra_asset', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset'}, 'entries': [['J5', [['cash', 'D', 1200], ['equipment', 'C', 1200]]], ['J5', [['payable', 'D', 5000], ['sales', 'D', 0], ['equipment', 'C', 5000], ['sales', 'C', 0]]], ['J5', [['sales', 'C', 999], ['cash', 'D', 999]]], ['J2', [['sales', 'C', -5000], ['acc_depr', 'D', -5000]]], ['J3', [['cash', 'D', 1200], ['equipment', 'C', 1200]]], ['J4', [['cash', 'C', 5001], ['payable', 'D', 5000]]], ['J2', [['cash', 'D', 250], ['equipment', 'C', 260]]]]}, {'balances': {'payable': 0, 'acc_depr': 0, 'sales': 0, 'equipment': -2400, 'cash': 2400}, 'rejected': ['J5', 'J5', 'J2', 'J4', 'J2']}], ['control 3', {'chart': {'receivable': 'asset', 'acc_depr': 'contra_asset', 'equipment': 'asset', 'wages': 'expense', 'cash': 'asset', 'loan': 'liability', 'drawings': 'dividend'}, 'entries': [['J4', [['wages', 'C', 5000], ['equipment', 'D', 5000]]], ['J3', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J5', [['receivable', 'D', -5000], ['cash', 'C', -5000]]], ['J5', [['wages', 'C', -40], ['acc_depr', 'D', -40]]]]}, {'balances': {'receivable': -40, 'acc_depr': 0, 'equipment': 5000, 'wages': -5000, 'cash': 0, 'loan': 0, 'drawings': 40}, 'rejected': ['J5', 'J5']}], ['control 4', {'chart': {'cash': 'asset', 'wages': 'expense', 'loan': 'liability', 'sales': 'revenue', 'receivable': 'asset'}, 'entries': [['J3', [['receivable', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['sales', 'C', -250], ['cash', 'D', -250]]], ['J5', [['loan', 'D', 5000], ['sales', 'C', 5001]]], ['J2', [['receivable', 'D', 1170], ['receivable', 'D', 30], ['wages', 'C', 1200]]], ['J2', []], ['J5', [['sales', 'D', 0], ['sales', 'C', 0], ['wages', 'C', 999], ['receivable', 'D', 999]]]]}, {'balances': {'cash': 0, 'wages': -2400, 'loan': 0, 'sales': 0, 'receivable': 2400}, 'rejected': ['J2', 'J5', 'J2', 'J5']}], ['control 5', {'chart': {'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'capital': 'equity', 'payable': 'liability', 'drawings': 'dividend', 'acc_depr': 'contra_asset'}, 'entries': [['J5', [['wages', 'D', 100], ['rent', 'C', 100]]], ['J5', [['receivable', 'D', -1200], ['drawings', 'C', -1200]]], ['J3', [['acc_depr', 'D', 0], ['drawings', 'C', 100], ['receivable', 'D', 100], ['acc_depr', 'C', 0]]], ['J5', [['payable', 'D', 999], ['receivable', 'C', 999]]], ['J1', [['rent', 'D', 999], ['drawings', 'C', 999]]], ['J2', [['drawings', 'D', 40], ['rent', 'C', 40]]]]}, {'balances': {'wages': 100, 'receivable': 0, 'rent': 859, 'capital': 0, 'payable': 0, 'drawings': -959, 'acc_depr': 0}, 'rejected': ['J5', 'J3', 'J5']}], ['control 6', {'chart': {'loan': 'liability', 'receivable': 'asset', 'payable': 'liability', 'drawings': 'dividend', 'wages': 'expense'}, 'entries': [['J5', [['wages', 'D', 5000], ['receivable', 'C', 5000]]], ['J2', [['payable', 'D', 250], ['loan', 'D', 0], ['loan', 'C', 0], ['receivable', 'C', 250]]], ['J1', [['payable', 'C', 39], ['wages', 'D', 40]]]]}, {'balances': {'loan': 0, 'receivable': -5000, 'payable': 0, 'drawings': 0, 'wages': 5000}, 'rejected': ['J2', 'J1']}]]]
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:
Liability and revenue balances come out negative after ordinary credit postings.

x = {'chart': {account: type}, 'entries': [[entry_id, [[account, 'D'|'C', cents], ...]], ...]}. Types asset, expense and dividend are debit-normal; liability, equity, revenue and contra_asset are credit-normal. An entry is posted only if its id has not already been posted, it has at least two lines, every account is in the chart, every side is 'D' or 'C', every amount is a positive integer and total debits equal total credits; otherwise the whole entry is rejected and its id appended to 'rejected' (a rejected id may be resubmitted later). Return {'balances': normal-signed balance of every chart account (zero and negative included), 'rejected': ids in order}.

split: open-access


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

N = 1
observations = []
def solve(x):
    chart = x['chart']
    debit_normal = {'asset', 'expense', 'dividend'}
    bal = {a: 0 for a in chart}
    rejected = []
    posted = set()
    for eid, lines in x['entries']:
        ok = eid not in posted and len(lines) >= 2
        posted.add(eid)
        dr = cr = 0
        for acct, side, amt in lines:
            if acct not in chart or side not in ('D', 'C') or amt <= 0:
                ok = False
            elif side == 'D':
                dr += amt
            else:
                cr += amt
        if not ok or dr != cr:
            rejected.append(eid)
            continue
        posted.add(eid)
        for acct, side, amt in lines:
            sign = 1 if (side == 'D') == (chart[acct] in debit_normal) else -1
            bal[acct] += sign * amt
    return {'balances': bal, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: duplicate id bookkeeping', {'chart': {'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 999], ['sales', 'D', 999]]], ['J5', [['wages', 'C', 250], ['equipment', 'D', 250]]], ['J3', [['wages', 'C', 40], ['rent', 'D', 40]]], ['J5', [['drawings', 'C', 100], ['wages', 'C', 0], ['sales', 'D', 100], ['wages', 'D', 0]]], ['J4', [['equipment', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['rent', 'D', 100], ['equipment', 'C', 100]]]]}, {'balances': {'capital': 0, 'rent': 140, 'cash': 0, 'receivable': 0, 'drawings': 0, 'equipment': 1350, 'wages': -1490, 'sales': 0}, 'rejected': ['J2', 'J5']}], ['control 1', {'chart': {'acc_depr': 'contra_asset', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'capital': 'equity'}, 'entries': [['J1', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['equipment', 'C', 5000], ['payable', 'D', 5000]]], ['J1', [['acc_depr', 'C', 1200], ['payable', 'D', 1170], ['payable', 'D', 30]]], ['J4', [['equipment', 'C', 5000], ['acc_depr', 'D', 4970], ['acc_depr', 'D', 30]]], ['J3', [['acc_depr', 'D', -40], ['equipment', 'C', -40]]]]}, {'balances': {'acc_depr': -5000, 'drawings': 0, 'payable': -5040, 'equipment': -10040, 'capital': 0}, 'rejected': ['J1', 'J3']}], ['control 2', {'chart': {'wages': 'expense', 'acc_depr': 'contra_asset', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['equipment', 'D', 100], ['wages', 'C', 100]]], ['J2', [['receivable', 'C', 250], ['acc_depr', 'D', 250]]], ['J1', [['acc_depr', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['equipment', 'D', -250], ['cash', 'C', -250]]], ['J4', [['acc_depr', 'D', -1200], ['cash', 'C', -1200]]], ['J5', [['suspense', 'C', 40], ['receivable', 'D', 40]]]]}, {'balances': {'wages': -100, 'acc_depr': 749, 'equipment': 100, 'cash': 0, 'receivable': 749}, 'rejected': ['J5', 'J4', 'J5']}], ['control 3', {'chart': {'drawings': 'dividend', 'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J4', [['receivable', 'C', 5000], ['cash', 'D', 4970], ['cash', 'D', 30]]], ['J1', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J3', []]]}, {'balances': {'drawings': 40, 'wages': 0, 'receivable': -5040, 'rent': 0, 'cash': 5000}, 'rejected': ['J3']}], ['control 4', {'chart': {'equipment': 'asset', 'payable': 'liability', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['equipment', 'C', 250], ['payable', 'D', 250]]], ['J2', [['payable', 'C', 999], ['cash', 'D', 999]]], ['J5', [['drawings', 'C', 40], ['capital', 'D', 30], ['capital', 'D', 10]]], ['J1', [['equipment', 'D', 5000], ['suspense', 'C', 5000]]]]}, {'balances': {'equipment': -250, 'payable': 749, 'cash': 999, 'drawings': -40, 'capital': -40, 'acc_depr': 0}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'capital': 'equity', 'rent': 'expense', 'payable': 'liability', 'receivable': 'asset', 'loan': 'liability', 'equipment': 'asset'}, 'entries': [['J1', [['capital', 'D', -100], ['drawings', 'C', -100]]], ['J2', [['payable', 'C', 5000], ['rent', 'D', 30], ['rent', 'D', 4970]]], ['J2', [['loan', 'C', 5000], ['equipment', 'D', 5000]]]]}, {'balances': {'drawings': 0, 'capital': 0, 'rent': 5000, 'payable': 5000, 'receivable': 0, 'loan': 0, 'equipment': 0}, 'rejected': ['J1', 'J2']}], ['control 6', {'chart': {'loan': 'liability', 'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset'}, 'entries': [['J2', [['sales', 'D', 100], ['loan', 'C', 100]]], ['J5', [['drawings', 'D', 30], ['drawings', 'D', 969], ['sales', 'C', 999]]], ['J3', []], ['J4', []], ['J4', []], ['J2', [['cash', 'C', 1200], ['rent', 'D', 1200]]]]}, {'balances': {'loan': 100, 'capital': 0, 'rent': 0, 'cash': 0, 'sales': 899, 'drawings': 999, 'receivable': 0}, 'rejected': ['J3', 'J4', 'J4', 'J2']}]], [['regression: duplicate id bookkeeping', {'chart': {'rent': 'expense', 'receivable': 'asset', 'equipment': 'asset', 'sales': 'revenue', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity'}, 'entries': [['J2', [['cash', 'D', 30], ['drawings', 'C', 5000], ['cash', 'D', 4970]]], ['J5', [['cash', 'C', 1200], ['drawings', 'D', 1200]]], ['J2', [['drawings', 'D', 1200], ['sales', 'C', 1200]]], ['J4', [['capital', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['rent', 'C', 998], ['sales', 'D', 999]]]]}, {'balances': {'rent': 0, 'receivable': 0, 'equipment': -40, 'sales': -40, 'cash': 3800, 'drawings': -3800, 'capital': 0}, 'rejected': ['J2', 'J4', 'J3']}], ['control 1', {'chart': {'acc_depr': 'contra_asset', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense'}, 'entries': [['J3', [['acc_depr', 'D', 30], ['acc_depr', 'D', 4970], ['loan', 'C', 5000]]], ['J2', [['loan', 'D', 4970], ['loan', 'D', 30], ['acc_depr', 'C', 5000]]], ['J3', [['loan', 'D', 5000], ['wages', 'C', 4999]]], ['J4', [['sales', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['loan', 'C', 40], ['sales', 'D', 40]]]]}, {'balances': {'acc_depr': 999, 'loan': 0, 'equipment': 0, 'sales': -999, 'wages': 0}, 'rejected': ['J3', 'J3']}], ['control 2', {'chart': {'drawings': 'dividend', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['drawings', 'C', 1200], ['equipment', 'D', 1200]]], ['J3', [['receivable', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['drawings', 'C', 999]]]]}, {'balances': {'drawings': -1949, 'sales': 0, 'equipment': 1200, 'cash': 0, 'receivable': 749}, 'rejected': []}], ['control 3', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'payable': 'liability', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['payable', 'C', 40], ['capital', 'D', 40]]], ['J5', [['acc_depr', 'C', 250], ['payable', 'D', 30], ['payable', 'D', 220]]], ['J1', [['cash', 'D', 999], ['acc_depr', 'C', 999]]]]}, {'balances': {'equipment': 0, 'sales': 0, 'payable': -210, 'cash': 999, 'drawings': 0, 'capital': -40, 'receivable': 0, 'acc_depr': 1249}, 'rejected': []}], ['control 4', {'chart': {'payable': 'liability', 'rent': 'expense', 'equipment': 'asset', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'capital': 'equity', 'cash': 'asset', 'drawings': 'dividend'}, 'entries': [['J3', [['equipment', 'C', 100], ['payable', 'D', 100]]], ['J3', [['drawings', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['capital', 'D', 250], ['sales', 'C', 250]]], ['J1', [['equipment', 'D', 30], ['acc_depr', 'C', 5000], ['equipment', 'D', 4970]]], ['J4', [['sales', 'D', 40], ['cash', 'C', 40]]], ['J5', [['payable', 'D', 1170], ['cash', 'C', 1200], ['payable', 'D', 30]]]]}, {'balances': {'payable': -1300, 'rent': 0, 'equipment': 4900, 'sales': 250, 'acc_depr': 5000, 'capital': -250, 'cash': -1200, 'drawings': 0}, 'rejected': ['J3', 'J4']}], ['control 5', {'chart': {'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'cash': 'asset', 'wages': 'expense', 'loan': 'liability', 'acc_depr': 'contra_asset'}, 'entries': [['J1', [['loan', 'C', 5000], ['drawings', 'D', 30], ['drawings', 'D', 4970]]], ['J5', [['cash', 'C', 999], ['acc_depr', 'D', 999]]], ['J3', [['acc_depr', 'D', 250], ['drawings', 'C', 250]]]]}, {'balances': {'sales': 0, 'drawings': 4750, 'receivable': 0, 'cash': -999, 'wages': 0, 'loan': 5000, 'acc_depr': -1249}, 'rejected': []}], ['control 6', {'chart': {'receivable': 'asset', 'payable': 'liability', 'capital': 'equity', 'acc_depr': 'contra_asset', 'drawings': 'dividend'}, 'entries': [['J4', [['capital', 'D', 10], ['capital', 'D', 30], ['drawings', 'C', 40]]], ['J4', [['drawings', 'D', 1200], ['capital', 'C', 1200]]], ['J2', [['capital', 'C', 100], ['drawings', 'D', 100]]], ['J4', [['capital', 'D', 220], ['capital', 'D', 30], ['drawings', 'C', 250]]], ['J5', [['payable', 'C', 1200], ['capital', 'D', 1170], ['capital', 'D', 30]]], ['J3', [['payable', 'D', 999], ['suspense', 'C', 999]]]]}, {'balances': {'receivable': 0, 'payable': 1200, 'capital': -1140, 'acc_depr': 0, 'drawings': 60}, 'rejected': ['J4', 'J4', 'J3']}]], [['regression: duplicate id bookkeeping', {'chart': {'cash': 'asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'acc_depr': 'contra_asset', 'payable': 'liability', 'receivable': 'asset', 'wages': 'expense'}, 'entries': [['J4', [['capital', 'D', 1200], ['cash', 'C', 1200]]], ['J1', []], ['J3', [['cash', 'C', 1200], ['rent', 'D', 1200]]], ['J3', [['rent', 'D', 30], ['cash', 'C', 999], ['rent', 'D', 969]]], ['J1', [['receivable', 'D', 40], ['rent', 'C', 40]]]]}, {'balances': {'cash': -2400, 'capital': -1200, 'rent': 1160, 'loan': 0, 'acc_depr': 0, 'payable': 0, 'receivable': 40, 'wages': 0}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'equipment': 'asset', 'capital': 'equity', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J5', [['sales', 'D', 1200], ['loan', 'C', 1200]]], ['J3', [['capital', 'D', 999], ['sales', 'C', 999]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]], ['J1', [['capital', 'D', 100], ['sales', 'C', 100]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['capital', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'equipment': -5000, 'capital': -1998, 'sales': -201, 'rent': 4101, 'loan': 1300}, 'rejected': ['J1', 'J3']}], ['control 2', {'chart': {'payable': 'liability', 'acc_depr': 'contra_asset', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J4', [['equipment', 'D', 0], ['payable', 'C', 999], ['equipment', 'C', 0], ['capital', 'D', 999]]], ['J5', [['payable', 'C', 0], ['acc_depr', 'D', 250], ['payable', 'D', 0], ['receivable', 'C', 250]]], ['J1', [['payable', 'C', 1200], ['equipment', 'D', 1200]]]]}, {'balances': {'payable': 1200, 'acc_depr': 0, 'receivable': 0, 'equipment': 1200, 'cash': 0, 'capital': 0}, 'rejected': ['J4', 'J5']}], ['control 3', {'chart': {'capital': 'equity', 'equipment': 'asset', 'cash': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['acc_depr', 'C', 0], ['acc_depr', 'D', 0], ['drawings', 'C', 999], ['capital', 'D', 999]]], ['J4', [['equipment', 'D', -250], ['drawings', 'C', -250]]], ['J2', [['receivable', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'capital': 0, 'equipment': 0, 'cash': 0, 'drawings': -100, 'rent': 0, 'receivable': 100, 'acc_depr': 0}, 'rejected': ['J4', 'J4']}], ['control 4', {'chart': {'receivable': 'asset', 'drawings': 'dividend', 'loan': 'liability', 'acc_depr': 'contra_asset', 'rent': 'expense', 'sales': 'revenue'}, 'entries': [['J3', [['receivable', 'C', 999], ['acc_depr', 'D', 999]]], ['J1', [['rent', 'D', 30], ['drawings', 'C', 250], ['rent', 'D', 220]]], ['J5', [['drawings', 'C', 5000], ['receivable', 'D', 0], ['loan', 'D', 5000], ['receivable', 'C', 0]]]]}, {'balances': {'receivable': -999, 'drawings': -250, 'loan': 0, 'acc_depr': -999, 'rent': 250, 'sales': 0}, 'rejected': ['J5']}], ['control 5', {'chart': {'wages': 'expense', 'receivable': 'asset', 'loan': 'liability', 'drawings': 'dividend', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J1', [['cash', 'D', 999], ['loan', 'C', 999]]], ['J2', [['cash', 'D', 0], ['cash', 'C', 0], ['rent', 'C', 250], ['loan', 'D', 250]]], ['J1', [['receivable', 'D', 220], ['rent', 'C', 250], ['receivable', 'D', 30]]], ['J1', [['receivable', 'C', 250], ['loan', 'D', 250]]]]}, {'balances': {'wages': 0, 'receivable': 0, 'loan': 999, 'drawings': 0, 'rent': 0, 'cash': 999}, 'rejected': ['J2', 'J1', 'J1']}], ['control 6', {'chart': {'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue'}, 'entries': [['J4', [['loan', 'D', 30], ['equipment', 'C', 999], ['loan', 'D', 969]]], ['J2', [['suspense', 'C', 100], ['equipment', 'D', 100]]], ['J3', [['receivable', 'D', 1170], ['wages', 'C', 1200], ['receivable', 'D', 30]]], ['J4', [['receivable', 'D', 30], ['receivable', 'D', 220], ['wages', 'C', 250]]]]}, {'balances': {'wages': -1200, 'receivable': 1200, 'rent': 0, 'loan': -999, 'equipment': -999, 'sales': 0}, 'rejected': ['J2', 'J4']}]], [['regression: duplicate id bookkeeping', {'chart': {'receivable': 'asset', 'cash': 'asset', 'capital': 'equity', 'acc_depr': 'contra_asset', 'payable': 'liability'}, 'entries': [['J2', [['acc_depr', 'D', 1200], ['cash', 'C', 1200]]], ['J4', [['acc_depr', 'D', 999], ['suspense', 'C', 999]]], ['J5', [['acc_depr', 'C', 5000], ['capital', 'D', 4970], ['capital', 'D', 30]]], ['J3', [['capital', 'C', 5000], ['cash', 'D', 5000]]], ['J4', [['payable', 'D', 220], ['receivable', 'C', 250], ['payable', 'D', 30]]], ['J4', [['cash', 'D', 30], ['cash', 'D', 969], ['payable', 'C', 999]]]]}, {'balances': {'receivable': -250, 'cash': 3800, 'capital': 0, 'acc_depr': 3800, 'payable': -250}, 'rejected': ['J4', 'J4']}], ['control 1', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'loan': 'liability'}, 'entries': [['J3', [['loan', 'D', 999], ['receivable', 'C', 999]]], ['J5', [['loan', 'C', 5000], ['sales', 'D', 0], ['drawings', 'D', 5000], ['sales', 'C', 0]]], ['J2', [['drawings', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 30], ['equipment', 'C', 100], ['sales', 'D', 70]]]]}, {'balances': {'equipment': -100, 'sales': -100, 'drawings': 0, 'receivable': -999, 'loan': -999}, 'rejected': ['J5', 'J2']}], ['control 2', {'chart': {'loan': 'liability', 'receivable': 'asset', 'drawings': 'dividend', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J3', [['drawings', 'D', 5000], ['acc_depr', 'C', 5001]]], ['J5', [['loan', 'C', 1200], ['receivable', 'D', 1200]]], ['J4', [['receivable', 'D', 30], ['receivable', 'D', 10], ['drawings', 'C', 40]]], ['J2', [['drawings', 'C', 250], ['sales', 'D', 250]]]]}, {'balances': {'loan': 1200, 'receivable': 1240, 'drawings': -290, 'sales': -250, 'acc_depr': 0, 'rent': 0}, 'rejected': ['J3']}], ['control 3', {'chart': {'acc_depr': 'contra_asset', 'capital': 'equity', 'loan': 'liability', 'payable': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense', 'drawings': 'dividend'}, 'entries': [['J5', [['drawings', 'C', 1200], ['wages', 'D', 1170], ['wages', 'D', 30]]], ['J5', [['equipment', 'D', 1200], ['drawings', 'C', 1200]]], ['J3', [['capital', 'D', 250], ['loan', 'C', 250]]], ['J3', [['loan', 'D', 250], ['drawings', 'C', 250]]], ['J1', [['equipment', 'C', 100], ['payable', 'C', 0], ['payable', 'D', 0], ['loan', 'D', 100]]], ['J5', [['sales', 'D', 5000], ['loan', 'C', 5000]]]]}, {'balances': {'acc_depr': 0, 'capital': -250, 'loan': 250, 'payable': 0, 'equipment': 0, 'sales': 0, 'wages': 1200, 'drawings': -1200}, 'rejected': ['J5', 'J3', 'J1', 'J5']}], ['control 4', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'cash': 'asset', 'receivable': 'asset', 'payable': 'liability', 'equipment': 'asset', 'loan': 'liability'}, 'entries': [['J4', [['loan', 'C', 1200], ['receivable', 'D', 1200]]], ['J5', [['drawings', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['cash', 'C', 5000], ['acc_depr', 'D', 30], ['acc_depr', 'D', 4970]]]]}, {'balances': {'drawings': 999, 'acc_depr': -4001, 'cash': -5000, 'receivable': 1200, 'payable': 0, 'equipment': 0, 'loan': 1200}, 'rejected': []}], ['control 5', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'receivable': 'asset', 'wages': 'expense', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J5', [['wages', 'C', 5000], ['capital', 'D', 5000]]], ['J2', [['equipment', 'D', 40], ['receivable', 'C', 40]]], ['J4', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['wages', 'C', 5010], ['drawings', 'D', 5000]]]]}, {'balances': {'equipment': 40, 'drawings': 0, 'receivable': -40, 'wages': -5000, 'cash': 0, 'capital': -5000}, 'rejected': ['J4', 'J2']}], ['control 6', {'chart': {'cash': 'asset', 'rent': 'expense', 'acc_depr': 'contra_asset', 'loan': 'liability', 'drawings': 'dividend', 'equipment': 'asset'}, 'entries': [['J3', [['loan', 'D', 999], ['equipment', 'C', 999]]], ['J4', [['equipment', 'C', 100], ['rent', 'D', 100]]], ['J5', [['equipment', 'C', 40], ['drawings', 'D', 30], ['drawings', 'D', 10]]], ['J4', [['equipment', 'C', 1200], ['cash', 'D', 1200]]], ['J3', [['loan', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'cash': 0, 'rent': 100, 'acc_depr': 0, 'loan': -999, 'drawings': 40, 'equipment': -1139}, 'rejected': ['J4', 'J3']}]], [['regression: duplicate id bookkeeping', {'chart': {'equipment': 'asset', 'wages': 'expense', 'capital': 'equity', 'drawings': 'dividend', 'rent': 'expense', 'payable': 'liability', 'loan': 'liability', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['wages', 'C', 100], ['acc_depr', 'D', 70], ['acc_depr', 'D', 30]]], ['J2', []], ['J5', [['suspense', 'C', 999], ['drawings', 'D', 999]]], ['J4', [['payable', 'D', 999], ['drawings', 'C', 999]]], ['J5', [['rent', 'D', 100], ['acc_depr', 'C', 100]]], ['J3', [['loan', 'C', 999], ['wages', 'D', 999]]], ['J3', [['acc_depr', 'D', 30], ['payable', 'C', 5000], ['acc_depr', 'D', 4970]]]]}, {'balances': {'equipment': 0, 'wages': 899, 'capital': 0, 'drawings': -999, 'rent': 100, 'payable': -999, 'loan': 999, 'acc_depr': 0}, 'rejected': ['J2', 'J5', 'J3']}], ['control 1', {'chart': {'cash': 'asset', 'acc_depr': 'contra_asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J1', [['loan', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['loan', 'C', 1200]]], ['J2', [['cash', 'C', -250], ['receivable', 'D', -250]]], ['J4', [['capital', 'D', 4970], ['capital', 'D', 30], ['receivable', 'C', 5000]]], ['J3', [['loan', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['cash', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'cash': 999, 'acc_depr': -1200, 'capital': -100, 'rent': -999, 'loan': 2299, 'receivable': 999}, 'rejected': ['J2', 'J4']}], ['control 2', {'chart': {'sales': 'revenue', 'rent': 'expense', 'equipment': 'asset', 'wages': 'expense', 'drawings': 'dividend'}, 'entries': [['J1', [['sales', 'C', 40], ['rent', 'D', 30], ['rent', 'D', 10]]], ['J1', [['sales', 'D', -40], ['drawings', 'C', -40]]], ['J3', [['wages', 'D', 250], ['drawings', 'C', 250]]]]}, {'balances': {'sales': 40, 'rent': 40, 'equipment': 0, 'wages': 250, 'drawings': -250}, 'rejected': ['J1']}], ['control 3', {'chart': {'receivable': 'asset', 'payable': 'liability', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'wages': 'expense', 'loan': 'liability', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J1', [['cash', 'D', 100], ['sales', 'C', 100]]], ['J1', []], ['J1', [['wages', 'C', 40], ['sales', 'D', 30], ['sales', 'D', 10]]], ['J2', [['payable', 'D', 999], ['rent', 'C', 999]]], ['J5', [['receivable', 'C', 999], ['cash', 'D', 969], ['cash', 'D', 30]]]]}, {'balances': {'receivable': -999, 'payable': -999, 'sales': 100, 'acc_depr': 0, 'wages': 0, 'loan': 0, 'rent': -999, 'cash': 1099}, 'rejected': ['J1', 'J1']}], ['control 4', {'chart': {'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'payable': 'liability', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J2', [['wages', 'C', 999], ['cash', 'D', 999]]], ['J4', [['equipment', 'D', 5000], ['payable', 'C', 5000]]], ['J2', [['suspense', 'C', 999], ['payable', 'D', 999]]], ['J5', [['equipment', 'D', 250], ['receivable', 'C', 250]]], ['J4', [['equipment', 'C', 1200], ['cash', 'D', 1200]]], ['J2', [['payable', 'D', 999], ['rent', 'C', 999]]], ['J4', [['payable', 'C', 100], ['wages', 'D', 30], ['wages', 'D', 70]]]]}, {'balances': {'wages': -999, 'equipment': 5250, 'receivable': -250, 'payable': 5000, 'cash': 999, 'rent': 0}, 'rejected': ['J2', 'J4', 'J2', 'J4']}], ['control 5', {'chart': {'wages': 'expense', 'rent': 'expense', 'cash': 'asset', 'capital': 'equity', 'receivable': 'asset'}, 'entries': [['J4', [['wages', 'C', 1200], ['cash', 'D', 1200]]], ['J5', [['wages', 'C', 999], ['capital', 'D', 999]]], ['J3', [['rent', 'C', 100], ['capital', 'D', 30], ['capital', 'D', 70]]], ['J2', [['capital', 'D', 30], ['capital', 'D', 1170], ['receivable', 'C', 1200]]], ['J1', [['wages', 'D', 40], ['cash', 'C', 40]]]]}, {'balances': {'wages': -2159, 'rent': -100, 'cash': 1160, 'capital': -2299, 'receivable': -1200}, 'rejected': []}], ['control 6', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'payable': 'liability', 'loan': 'liability'}, 'entries': [['J1', [['receivable', 'C', 999], ['equipment', 'D', 999]]], ['J5', []], ['J3', [['sales', 'D', 5000], ['payable', 'C', 5010]]], ['J1', [['loan', 'D', 40], ['receivable', 'C', 40]]]]}, {'balances': {'equipment': 999, 'drawings': 0, 'rent': 0, 'capital': 0, 'receivable': -999, 'sales': 0, 'payable': 0, 'loan': 0}, 'rejected': ['J5', 'J3', 'J1']}]]]
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):
    chart = x['chart']
    debit_normal = {'asset', 'expense', 'dividend'}
    bal = {a: 0 for a in chart}
    rejected = []
    posted = set()
    for eid, lines in x['entries']:
        ok = eid not in posted and eid not in rejected and len(lines) >= 2
        dr = cr = 0
        for acct, side, amt in lines:
            if acct not in chart or side not in ('D', 'C') or amt <= 0:
                ok = False
            elif side == 'D':
                dr += amt
            else:
                cr += amt
        if not ok or dr != cr:
            rejected.append(eid)
            continue
        posted.add(eid)
        for acct, side, amt in lines:
            sign = 1 if (side == 'D') == (chart[acct] in debit_normal) else -1
            bal[acct] += sign * amt
    return {'balances': bal, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: duplicate id bookkeeping', {'chart': {'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'receivable': 'asset', 'drawings': 'dividend', 'equipment': 'asset', 'wages': 'expense', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 999], ['sales', 'D', 999]]], ['J5', [['wages', 'C', 250], ['equipment', 'D', 250]]], ['J3', [['wages', 'C', 40], ['rent', 'D', 40]]], ['J5', [['drawings', 'C', 100], ['wages', 'C', 0], ['sales', 'D', 100], ['wages', 'D', 0]]], ['J4', [['equipment', 'D', 1200], ['wages', 'C', 1200]]], ['J2', [['rent', 'D', 100], ['equipment', 'C', 100]]]]}, {'balances': {'capital': 0, 'rent': 140, 'cash': 0, 'receivable': 0, 'drawings': 0, 'equipment': 1350, 'wages': -1490, 'sales': 0}, 'rejected': ['J2', 'J5']}], ['control 1', {'chart': {'acc_depr': 'contra_asset', 'drawings': 'dividend', 'payable': 'liability', 'equipment': 'asset', 'capital': 'equity'}, 'entries': [['J1', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['equipment', 'C', 5000], ['payable', 'D', 5000]]], ['J1', [['acc_depr', 'C', 1200], ['payable', 'D', 1170], ['payable', 'D', 30]]], ['J4', [['equipment', 'C', 5000], ['acc_depr', 'D', 4970], ['acc_depr', 'D', 30]]], ['J3', [['acc_depr', 'D', -40], ['equipment', 'C', -40]]]]}, {'balances': {'acc_depr': -5000, 'drawings': 0, 'payable': -5040, 'equipment': -10040, 'capital': 0}, 'rejected': ['J1', 'J3']}], ['control 2', {'chart': {'wages': 'expense', 'acc_depr': 'contra_asset', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['equipment', 'D', 100], ['wages', 'C', 100]]], ['J2', [['receivable', 'C', 250], ['acc_depr', 'D', 250]]], ['J1', [['acc_depr', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['equipment', 'D', -250], ['cash', 'C', -250]]], ['J4', [['acc_depr', 'D', -1200], ['cash', 'C', -1200]]], ['J5', [['suspense', 'C', 40], ['receivable', 'D', 40]]]]}, {'balances': {'wages': -100, 'acc_depr': 749, 'equipment': 100, 'cash': 0, 'receivable': 749}, 'rejected': ['J5', 'J4', 'J5']}], ['control 3', {'chart': {'drawings': 'dividend', 'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J4', [['receivable', 'C', 5000], ['cash', 'D', 4970], ['cash', 'D', 30]]], ['J1', [['drawings', 'D', 40], ['receivable', 'C', 40]]], ['J3', []]]}, {'balances': {'drawings': 40, 'wages': 0, 'receivable': -5040, 'rent': 0, 'cash': 5000}, 'rejected': ['J3']}], ['control 4', {'chart': {'equipment': 'asset', 'payable': 'liability', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['equipment', 'C', 250], ['payable', 'D', 250]]], ['J2', [['payable', 'C', 999], ['cash', 'D', 999]]], ['J5', [['drawings', 'C', 40], ['capital', 'D', 30], ['capital', 'D', 10]]], ['J1', [['equipment', 'D', 5000], ['suspense', 'C', 5000]]]]}, {'balances': {'equipment': -250, 'payable': 749, 'cash': 999, 'drawings': -40, 'capital': -40, 'acc_depr': 0}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'capital': 'equity', 'rent': 'expense', 'payable': 'liability', 'receivable': 'asset', 'loan': 'liability', 'equipment': 'asset'}, 'entries': [['J1', [['capital', 'D', -100], ['drawings', 'C', -100]]], ['J2', [['payable', 'C', 5000], ['rent', 'D', 30], ['rent', 'D', 4970]]], ['J2', [['loan', 'C', 5000], ['equipment', 'D', 5000]]]]}, {'balances': {'drawings': 0, 'capital': 0, 'rent': 5000, 'payable': 5000, 'receivable': 0, 'loan': 0, 'equipment': 0}, 'rejected': ['J1', 'J2']}], ['control 6', {'chart': {'loan': 'liability', 'capital': 'equity', 'rent': 'expense', 'cash': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset'}, 'entries': [['J2', [['sales', 'D', 100], ['loan', 'C', 100]]], ['J5', [['drawings', 'D', 30], ['drawings', 'D', 969], ['sales', 'C', 999]]], ['J3', []], ['J4', []], ['J4', []], ['J2', [['cash', 'C', 1200], ['rent', 'D', 1200]]]]}, {'balances': {'loan': 100, 'capital': 0, 'rent': 0, 'cash': 0, 'sales': 899, 'drawings': 999, 'receivable': 0}, 'rejected': ['J3', 'J4', 'J4', 'J2']}]], [['regression: duplicate id bookkeeping', {'chart': {'rent': 'expense', 'receivable': 'asset', 'equipment': 'asset', 'sales': 'revenue', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity'}, 'entries': [['J2', [['cash', 'D', 30], ['drawings', 'C', 5000], ['cash', 'D', 4970]]], ['J5', [['cash', 'C', 1200], ['drawings', 'D', 1200]]], ['J2', [['drawings', 'D', 1200], ['sales', 'C', 1200]]], ['J4', [['capital', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 40], ['equipment', 'C', 40]]], ['J3', [['rent', 'C', 998], ['sales', 'D', 999]]]]}, {'balances': {'rent': 0, 'receivable': 0, 'equipment': -40, 'sales': -40, 'cash': 3800, 'drawings': -3800, 'capital': 0}, 'rejected': ['J2', 'J4', 'J3']}], ['control 1', {'chart': {'acc_depr': 'contra_asset', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense'}, 'entries': [['J3', [['acc_depr', 'D', 30], ['acc_depr', 'D', 4970], ['loan', 'C', 5000]]], ['J2', [['loan', 'D', 4970], ['loan', 'D', 30], ['acc_depr', 'C', 5000]]], ['J3', [['loan', 'D', 5000], ['wages', 'C', 4999]]], ['J4', [['sales', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['loan', 'C', 40], ['sales', 'D', 40]]]]}, {'balances': {'acc_depr': 999, 'loan': 0, 'equipment': 0, 'sales': -999, 'wages': 0}, 'rejected': ['J3', 'J3']}], ['control 2', {'chart': {'drawings': 'dividend', 'sales': 'revenue', 'equipment': 'asset', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['drawings', 'C', 1200], ['equipment', 'D', 1200]]], ['J3', [['receivable', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['drawings', 'C', 999]]]]}, {'balances': {'drawings': -1949, 'sales': 0, 'equipment': 1200, 'cash': 0, 'receivable': 749}, 'rejected': []}], ['control 3', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'payable': 'liability', 'cash': 'asset', 'drawings': 'dividend', 'capital': 'equity', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['payable', 'C', 40], ['capital', 'D', 40]]], ['J5', [['acc_depr', 'C', 250], ['payable', 'D', 30], ['payable', 'D', 220]]], ['J1', [['cash', 'D', 999], ['acc_depr', 'C', 999]]]]}, {'balances': {'equipment': 0, 'sales': 0, 'payable': -210, 'cash': 999, 'drawings': 0, 'capital': -40, 'receivable': 0, 'acc_depr': 1249}, 'rejected': []}], ['control 4', {'chart': {'payable': 'liability', 'rent': 'expense', 'equipment': 'asset', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'capital': 'equity', 'cash': 'asset', 'drawings': 'dividend'}, 'entries': [['J3', [['equipment', 'C', 100], ['payable', 'D', 100]]], ['J3', [['drawings', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['capital', 'D', 250], ['sales', 'C', 250]]], ['J1', [['equipment', 'D', 30], ['acc_depr', 'C', 5000], ['equipment', 'D', 4970]]], ['J4', [['sales', 'D', 40], ['cash', 'C', 40]]], ['J5', [['payable', 'D', 1170], ['cash', 'C', 1200], ['payable', 'D', 30]]]]}, {'balances': {'payable': -1300, 'rent': 0, 'equipment': 4900, 'sales': 250, 'acc_depr': 5000, 'capital': -250, 'cash': -1200, 'drawings': 0}, 'rejected': ['J3', 'J4']}], ['control 5', {'chart': {'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'cash': 'asset', 'wages': 'expense', 'loan': 'liability', 'acc_depr': 'contra_asset'}, 'entries': [['J1', [['loan', 'C', 5000], ['drawings', 'D', 30], ['drawings', 'D', 4970]]], ['J5', [['cash', 'C', 999], ['acc_depr', 'D', 999]]], ['J3', [['acc_depr', 'D', 250], ['drawings', 'C', 250]]]]}, {'balances': {'sales': 0, 'drawings': 4750, 'receivable': 0, 'cash': -999, 'wages': 0, 'loan': 5000, 'acc_depr': -1249}, 'rejected': []}], ['control 6', {'chart': {'receivable': 'asset', 'payable': 'liability', 'capital': 'equity', 'acc_depr': 'contra_asset', 'drawings': 'dividend'}, 'entries': [['J4', [['capital', 'D', 10], ['capital', 'D', 30], ['drawings', 'C', 40]]], ['J4', [['drawings', 'D', 1200], ['capital', 'C', 1200]]], ['J2', [['capital', 'C', 100], ['drawings', 'D', 100]]], ['J4', [['capital', 'D', 220], ['capital', 'D', 30], ['drawings', 'C', 250]]], ['J5', [['payable', 'C', 1200], ['capital', 'D', 1170], ['capital', 'D', 30]]], ['J3', [['payable', 'D', 999], ['suspense', 'C', 999]]]]}, {'balances': {'receivable': 0, 'payable': 1200, 'capital': -1140, 'acc_depr': 0, 'drawings': 60}, 'rejected': ['J4', 'J4', 'J3']}]], [['regression: duplicate id bookkeeping', {'chart': {'cash': 'asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'acc_depr': 'contra_asset', 'payable': 'liability', 'receivable': 'asset', 'wages': 'expense'}, 'entries': [['J4', [['capital', 'D', 1200], ['cash', 'C', 1200]]], ['J1', []], ['J3', [['cash', 'C', 1200], ['rent', 'D', 1200]]], ['J3', [['rent', 'D', 30], ['cash', 'C', 999], ['rent', 'D', 969]]], ['J1', [['receivable', 'D', 40], ['rent', 'C', 40]]]]}, {'balances': {'cash': -2400, 'capital': -1200, 'rent': 1160, 'loan': 0, 'acc_depr': 0, 'payable': 0, 'receivable': 40, 'wages': 0}, 'rejected': ['J1', 'J3']}], ['control 1', {'chart': {'equipment': 'asset', 'capital': 'equity', 'sales': 'revenue', 'rent': 'expense', 'loan': 'liability'}, 'entries': [['J5', [['sales', 'D', 1200], ['loan', 'C', 1200]]], ['J3', [['capital', 'D', 999], ['sales', 'C', 999]]], ['J1', [['loan', 'C', 100], ['rent', 'D', 100]]], ['J1', [['capital', 'D', 100], ['sales', 'C', 100]]], ['J4', [['equipment', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['capital', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'equipment': -5000, 'capital': -1998, 'sales': -201, 'rent': 4101, 'loan': 1300}, 'rejected': ['J1', 'J3']}], ['control 2', {'chart': {'payable': 'liability', 'acc_depr': 'contra_asset', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J4', [['equipment', 'D', 0], ['payable', 'C', 999], ['equipment', 'C', 0], ['capital', 'D', 999]]], ['J5', [['payable', 'C', 0], ['acc_depr', 'D', 250], ['payable', 'D', 0], ['receivable', 'C', 250]]], ['J1', [['payable', 'C', 1200], ['equipment', 'D', 1200]]]]}, {'balances': {'payable': 1200, 'acc_depr': 0, 'receivable': 0, 'equipment': 1200, 'cash': 0, 'capital': 0}, 'rejected': ['J4', 'J5']}], ['control 3', {'chart': {'capital': 'equity', 'equipment': 'asset', 'cash': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['acc_depr', 'C', 0], ['acc_depr', 'D', 0], ['drawings', 'C', 999], ['capital', 'D', 999]]], ['J4', [['equipment', 'D', -250], ['drawings', 'C', -250]]], ['J2', [['receivable', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'capital': 0, 'equipment': 0, 'cash': 0, 'drawings': -100, 'rent': 0, 'receivable': 100, 'acc_depr': 0}, 'rejected': ['J4', 'J4']}], ['control 4', {'chart': {'receivable': 'asset', 'drawings': 'dividend', 'loan': 'liability', 'acc_depr': 'contra_asset', 'rent': 'expense', 'sales': 'revenue'}, 'entries': [['J3', [['receivable', 'C', 999], ['acc_depr', 'D', 999]]], ['J1', [['rent', 'D', 30], ['drawings', 'C', 250], ['rent', 'D', 220]]], ['J5', [['drawings', 'C', 5000], ['receivable', 'D', 0], ['loan', 'D', 5000], ['receivable', 'C', 0]]]]}, {'balances': {'receivable': -999, 'drawings': -250, 'loan': 0, 'acc_depr': -999, 'rent': 250, 'sales': 0}, 'rejected': ['J5']}], ['control 5', {'chart': {'wages': 'expense', 'receivable': 'asset', 'loan': 'liability', 'drawings': 'dividend', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J1', [['cash', 'D', 999], ['loan', 'C', 999]]], ['J2', [['cash', 'D', 0], ['cash', 'C', 0], ['rent', 'C', 250], ['loan', 'D', 250]]], ['J1', [['receivable', 'D', 220], ['rent', 'C', 250], ['receivable', 'D', 30]]], ['J1', [['receivable', 'C', 250], ['loan', 'D', 250]]]]}, {'balances': {'wages': 0, 'receivable': 0, 'loan': 999, 'drawings': 0, 'rent': 0, 'cash': 999}, 'rejected': ['J2', 'J1', 'J1']}], ['control 6', {'chart': {'wages': 'expense', 'receivable': 'asset', 'rent': 'expense', 'loan': 'liability', 'equipment': 'asset', 'sales': 'revenue'}, 'entries': [['J4', [['loan', 'D', 30], ['equipment', 'C', 999], ['loan', 'D', 969]]], ['J2', [['suspense', 'C', 100], ['equipment', 'D', 100]]], ['J3', [['receivable', 'D', 1170], ['wages', 'C', 1200], ['receivable', 'D', 30]]], ['J4', [['receivable', 'D', 30], ['receivable', 'D', 220], ['wages', 'C', 250]]]]}, {'balances': {'wages': -1200, 'receivable': 1200, 'rent': 0, 'loan': -999, 'equipment': -999, 'sales': 0}, 'rejected': ['J2', 'J4']}]], [['regression: duplicate id bookkeeping', {'chart': {'receivable': 'asset', 'cash': 'asset', 'capital': 'equity', 'acc_depr': 'contra_asset', 'payable': 'liability'}, 'entries': [['J2', [['acc_depr', 'D', 1200], ['cash', 'C', 1200]]], ['J4', [['acc_depr', 'D', 999], ['suspense', 'C', 999]]], ['J5', [['acc_depr', 'C', 5000], ['capital', 'D', 4970], ['capital', 'D', 30]]], ['J3', [['capital', 'C', 5000], ['cash', 'D', 5000]]], ['J4', [['payable', 'D', 220], ['receivable', 'C', 250], ['payable', 'D', 30]]], ['J4', [['cash', 'D', 30], ['cash', 'D', 969], ['payable', 'C', 999]]]]}, {'balances': {'receivable': -250, 'cash': 3800, 'capital': 0, 'acc_depr': 3800, 'payable': -250}, 'rejected': ['J4', 'J4']}], ['control 1', {'chart': {'equipment': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'receivable': 'asset', 'loan': 'liability'}, 'entries': [['J3', [['loan', 'D', 999], ['receivable', 'C', 999]]], ['J5', [['loan', 'C', 5000], ['sales', 'D', 0], ['drawings', 'D', 5000], ['sales', 'C', 0]]], ['J2', [['drawings', 'D', 100], ['suspense', 'C', 100]]], ['J4', [['sales', 'D', 30], ['equipment', 'C', 100], ['sales', 'D', 70]]]]}, {'balances': {'equipment': -100, 'sales': -100, 'drawings': 0, 'receivable': -999, 'loan': -999}, 'rejected': ['J5', 'J2']}], ['control 2', {'chart': {'loan': 'liability', 'receivable': 'asset', 'drawings': 'dividend', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'rent': 'expense'}, 'entries': [['J3', [['drawings', 'D', 5000], ['acc_depr', 'C', 5001]]], ['J5', [['loan', 'C', 1200], ['receivable', 'D', 1200]]], ['J4', [['receivable', 'D', 30], ['receivable', 'D', 10], ['drawings', 'C', 40]]], ['J2', [['drawings', 'C', 250], ['sales', 'D', 250]]]]}, {'balances': {'loan': 1200, 'receivable': 1240, 'drawings': -290, 'sales': -250, 'acc_depr': 0, 'rent': 0}, 'rejected': ['J3']}], ['control 3', {'chart': {'acc_depr': 'contra_asset', 'capital': 'equity', 'loan': 'liability', 'payable': 'liability', 'equipment': 'asset', 'sales': 'revenue', 'wages': 'expense', 'drawings': 'dividend'}, 'entries': [['J5', [['drawings', 'C', 1200], ['wages', 'D', 1170], ['wages', 'D', 30]]], ['J5', [['equipment', 'D', 1200], ['drawings', 'C', 1200]]], ['J3', [['capital', 'D', 250], ['loan', 'C', 250]]], ['J3', [['loan', 'D', 250], ['drawings', 'C', 250]]], ['J1', [['equipment', 'C', 100], ['payable', 'C', 0], ['payable', 'D', 0], ['loan', 'D', 100]]], ['J5', [['sales', 'D', 5000], ['loan', 'C', 5000]]]]}, {'balances': {'acc_depr': 0, 'capital': -250, 'loan': 250, 'payable': 0, 'equipment': 0, 'sales': 0, 'wages': 1200, 'drawings': -1200}, 'rejected': ['J5', 'J3', 'J1', 'J5']}], ['control 4', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'cash': 'asset', 'receivable': 'asset', 'payable': 'liability', 'equipment': 'asset', 'loan': 'liability'}, 'entries': [['J4', [['loan', 'C', 1200], ['receivable', 'D', 1200]]], ['J5', [['drawings', 'D', 999], ['acc_depr', 'C', 999]]], ['J3', [['cash', 'C', 5000], ['acc_depr', 'D', 30], ['acc_depr', 'D', 4970]]]]}, {'balances': {'drawings': 999, 'acc_depr': -4001, 'cash': -5000, 'receivable': 1200, 'payable': 0, 'equipment': 0, 'loan': 1200}, 'rejected': []}], ['control 5', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'receivable': 'asset', 'wages': 'expense', 'cash': 'asset', 'capital': 'equity'}, 'entries': [['J5', [['wages', 'C', 5000], ['capital', 'D', 5000]]], ['J2', [['equipment', 'D', 40], ['receivable', 'C', 40]]], ['J4', [['equipment', 'D', 999], ['suspense', 'C', 999]]], ['J2', [['wages', 'C', 5010], ['drawings', 'D', 5000]]]]}, {'balances': {'equipment': 40, 'drawings': 0, 'receivable': -40, 'wages': -5000, 'cash': 0, 'capital': -5000}, 'rejected': ['J4', 'J2']}], ['control 6', {'chart': {'cash': 'asset', 'rent': 'expense', 'acc_depr': 'contra_asset', 'loan': 'liability', 'drawings': 'dividend', 'equipment': 'asset'}, 'entries': [['J3', [['loan', 'D', 999], ['equipment', 'C', 999]]], ['J4', [['equipment', 'C', 100], ['rent', 'D', 100]]], ['J5', [['equipment', 'C', 40], ['drawings', 'D', 30], ['drawings', 'D', 10]]], ['J4', [['equipment', 'C', 1200], ['cash', 'D', 1200]]], ['J3', [['loan', 'D', 100], ['drawings', 'C', 100]]]]}, {'balances': {'cash': 0, 'rent': 100, 'acc_depr': 0, 'loan': -999, 'drawings': 40, 'equipment': -1139}, 'rejected': ['J4', 'J3']}]], [['regression: duplicate id bookkeeping', {'chart': {'equipment': 'asset', 'wages': 'expense', 'capital': 'equity', 'drawings': 'dividend', 'rent': 'expense', 'payable': 'liability', 'loan': 'liability', 'acc_depr': 'contra_asset'}, 'entries': [['J2', [['wages', 'C', 100], ['acc_depr', 'D', 70], ['acc_depr', 'D', 30]]], ['J2', []], ['J5', [['suspense', 'C', 999], ['drawings', 'D', 999]]], ['J4', [['payable', 'D', 999], ['drawings', 'C', 999]]], ['J5', [['rent', 'D', 100], ['acc_depr', 'C', 100]]], ['J3', [['loan', 'C', 999], ['wages', 'D', 999]]], ['J3', [['acc_depr', 'D', 30], ['payable', 'C', 5000], ['acc_depr', 'D', 4970]]]]}, {'balances': {'equipment': 0, 'wages': 899, 'capital': 0, 'drawings': -999, 'rent': 100, 'payable': -999, 'loan': 999, 'acc_depr': 0}, 'rejected': ['J2', 'J5', 'J3']}], ['control 1', {'chart': {'cash': 'asset', 'acc_depr': 'contra_asset', 'capital': 'equity', 'rent': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J1', [['loan', 'C', 100], ['capital', 'D', 70], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['loan', 'C', 1200]]], ['J2', [['cash', 'C', -250], ['receivable', 'D', -250]]], ['J4', [['capital', 'D', 4970], ['capital', 'D', 30], ['receivable', 'C', 5000]]], ['J3', [['loan', 'C', 999], ['receivable', 'D', 999]]], ['J5', [['cash', 'D', 999], ['rent', 'C', 999]]]]}, {'balances': {'cash': 999, 'acc_depr': -1200, 'capital': -100, 'rent': -999, 'loan': 2299, 'receivable': 999}, 'rejected': ['J2', 'J4']}], ['control 2', {'chart': {'sales': 'revenue', 'rent': 'expense', 'equipment': 'asset', 'wages': 'expense', 'drawings': 'dividend'}, 'entries': [['J1', [['sales', 'C', 40], ['rent', 'D', 30], ['rent', 'D', 10]]], ['J1', [['sales', 'D', -40], ['drawings', 'C', -40]]], ['J3', [['wages', 'D', 250], ['drawings', 'C', 250]]]]}, {'balances': {'sales': 40, 'rent': 40, 'equipment': 0, 'wages': 250, 'drawings': -250}, 'rejected': ['J1']}], ['control 3', {'chart': {'receivable': 'asset', 'payable': 'liability', 'sales': 'revenue', 'acc_depr': 'contra_asset', 'wages': 'expense', 'loan': 'liability', 'rent': 'expense', 'cash': 'asset'}, 'entries': [['J1', [['cash', 'D', 100], ['sales', 'C', 100]]], ['J1', []], ['J1', [['wages', 'C', 40], ['sales', 'D', 30], ['sales', 'D', 10]]], ['J2', [['payable', 'D', 999], ['rent', 'C', 999]]], ['J5', [['receivable', 'C', 999], ['cash', 'D', 969], ['cash', 'D', 30]]]]}, {'balances': {'receivable': -999, 'payable': -999, 'sales': 100, 'acc_depr': 0, 'wages': 0, 'loan': 0, 'rent': -999, 'cash': 1099}, 'rejected': ['J1', 'J1']}], ['control 4', {'chart': {'wages': 'expense', 'equipment': 'asset', 'receivable': 'asset', 'payable': 'liability', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J2', [['wages', 'C', 999], ['cash', 'D', 999]]], ['J4', [['equipment', 'D', 5000], ['payable', 'C', 5000]]], ['J2', [['suspense', 'C', 999], ['payable', 'D', 999]]], ['J5', [['equipment', 'D', 250], ['receivable', 'C', 250]]], ['J4', [['equipment', 'C', 1200], ['cash', 'D', 1200]]], ['J2', [['payable', 'D', 999], ['rent', 'C', 999]]], ['J4', [['payable', 'C', 100], ['wages', 'D', 30], ['wages', 'D', 70]]]]}, {'balances': {'wages': -999, 'equipment': 5250, 'receivable': -250, 'payable': 5000, 'cash': 999, 'rent': 0}, 'rejected': ['J2', 'J4', 'J2', 'J4']}], ['control 5', {'chart': {'wages': 'expense', 'rent': 'expense', 'cash': 'asset', 'capital': 'equity', 'receivable': 'asset'}, 'entries': [['J4', [['wages', 'C', 1200], ['cash', 'D', 1200]]], ['J5', [['wages', 'C', 999], ['capital', 'D', 999]]], ['J3', [['rent', 'C', 100], ['capital', 'D', 30], ['capital', 'D', 70]]], ['J2', [['capital', 'D', 30], ['capital', 'D', 1170], ['receivable', 'C', 1200]]], ['J1', [['wages', 'D', 40], ['cash', 'C', 40]]]]}, {'balances': {'wages': -2159, 'rent': -100, 'cash': 1160, 'capital': -2299, 'receivable': -1200}, 'rejected': []}], ['control 6', {'chart': {'equipment': 'asset', 'drawings': 'dividend', 'rent': 'expense', 'capital': 'equity', 'receivable': 'asset', 'sales': 'revenue', 'payable': 'liability', 'loan': 'liability'}, 'entries': [['J1', [['receivable', 'C', 999], ['equipment', 'D', 999]]], ['J5', []], ['J3', [['sales', 'D', 5000], ['payable', 'C', 5010]]], ['J1', [['loan', 'D', 40], ['receivable', 'C', 40]]]]}, {'balances': {'equipment': 999, 'drawings': 0, 'rent': 0, 'capital': 0, 'receivable': -999, 'sales': 0, 'payable': 0, 'loan': 0}, 'rejected': ['J5', 'J3', 'J1']}]]]
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:
A corrected resubmission of a previously rejected entry is refused as a duplicate.

x = {'chart': {account: type}, 'entries': [[entry_id, [[account, 'D'|'C', cents], ...]], ...]}. Types asset, expense and dividend are debit-normal; liability, equity, revenue and contra_asset are credit-normal. An entry is posted only if its id has not already been posted, it has at least two lines, every account is in the chart, every side is 'D' or 'C', every amount is a positive integer and total debits equal total credits; otherwise the whole entry is rejected and its id appended to 'rejected' (a rejected id may be resubmitted later). Return {'balances': normal-signed balance of every chart account (zero and negative included), 'rejected': ids in order}.

split: open-access