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') == (chart[acct] in debit_normal) else -1
            bal[acct] += sign * amt
    return {'balances': {a: v for a, v in bal.items() if v}, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: zero and abnormal balance reporting', {'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': {'payable': 'liability', 'equipment': 'asset', 'rent': 'expense', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J1', [['capital', 'D', 1200], ['acc_depr', 'C', 1200]]], ['J1', []], ['J5', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J1', []], ['J2', [['capital', 'D', 30], ['acc_depr', 'C', 1200], ['capital', 'D', 1170]]], ['J2', [['acc_depr', 'D', 999], ['equipment', 'C', 999]]], ['J3', [['rent', 'C', 5000], ['payable', 'D', 5000]]]]}, {'balances': {'payable': -5040, 'equipment': -40, 'rent': -5000, 'capital': -2400, 'acc_depr': 2400}, 'rejected': ['J1', 'J1', 'J2']}], ['control 2', {'chart': {'acc_depr': 'contra_asset', 'receivable': 'asset', 'cash': 'asset', 'rent': 'expense', 'wages': 'expense'}, 'entries': [['J5', [['receivable', 'C', 5000], ['acc_depr', 'D', 30], ['acc_depr', 'D', 4970]]], ['J2', [['cash', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['wages', 'C', 40], ['rent', 'D', 40]]]]}, {'balances': {'acc_depr': -4750, 'receivable': -5000, 'cash': 250, 'rent': 40, 'wages': -40}, 'rejected': []}], ['control 3', {'chart': {'receivable': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'rent': 'expense', 'acc_depr': 'contra_asset'}, 'entries': [['J3', [['receivable', 'D', 1200], ['rent', 'C', 1200]]], ['J5', [['acc_depr', 'C', 100], ['drawings', 'D', 100]]], ['J4', [['rent', 'C', 999], ['acc_depr', 'D', 999]]], ['J5', [['drawings', 'D', 250], ['receivable', 'C', 250]]], ['J4', [['rent', 'C', 100], ['acc_depr', 'D', 100]]], ['J2', [['sales', 'C', 100], ['receivable', 'D', 100]]]]}, {'balances': {'receivable': 1300, 'sales': 100, 'drawings': 100, 'rent': -2199, 'acc_depr': -899}, 'rejected': ['J5', 'J4']}], ['control 4', {'chart': {'receivable': 'asset', 'acc_depr': 'contra_asset', 'payable': 'liability', 'equipment': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['receivable', 'C', 249], ['wages', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['wages', 'C', 999]]], ['J2', [['acc_depr', 'D', 999], ['wages', 'C', 999]]], ['J3', [['equipment', 'D', 999], ['payable', 'C', 999]]]]}, {'balances': {'receivable': 999, 'acc_depr': -999, 'payable': 999, 'equipment': 999, 'wages': -1998}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J4', [['receivable', 'D', 30], ['receivable', 'D', 70], ['cash', 'C', 100]]], ['J3', [['wages', 'C', 100], ['drawings', 'D', 100]]], ['J2', [['equipment', 'D', 70], ['wages', 'C', 100], ['equipment', 'D', 30]]], ['J5', [['drawings', 'D', 4970], ['equipment', 'C', 5000], ['drawings', 'D', 30]]], ['J1', [['wages', 'D', 999], ['drawings', 'C', 1009]]]]}, {'balances': {'drawings': 5100, 'receivable': 100, 'equipment': -4900, 'cash': -100, 'wages': -200}, 'rejected': ['J1']}], ['control 6', {'chart': {'rent': 'expense', 'sales': 'revenue', 'equipment': 'asset', 'capital': 'equity', 'loan': 'liability'}, 'entries': [['J5', [['equipment', 'C', 999], ['sales', 'D', 999], ['loan', 'D', 0], ['loan', 'C', 0]]], ['J5', [['loan', 'C', 250], ['rent', 'D', 250]]], ['J1', [['loan', 'C', 40], ['equipment', 'D', 30], ['equipment', 'D', 10]]], ['J3', [['sales', 'C', 1200], ['capital', 'D', 1200]]], ['J1', [['sales', 'D', 999], ['equipment', 'C', 1000]]], ['J4', [['suspense', 'C', 40], ['capital', 'D', 40]]]]}, {'balances': {'rent': 250, 'sales': 1200, 'equipment': 40, 'capital': -1200, 'loan': 290}, 'rejected': ['J5', 'J1', 'J4']}]], [['regression: zero and abnormal balance reporting', {'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': {'cash': 'asset', 'acc_depr': 'contra_asset', 'sales': 'revenue', 'receivable': 'asset', 'rent': 'expense'}, 'entries': [['J2', [['cash', 'C', 100], ['sales', 'D', 100]]], ['J5', [['cash', 'C', 1210], ['receivable', 'D', 1200]]], ['J4', [['sales', 'C', 5000], ['receivable', 'D', 5000]]], ['J2', [['cash', 'C', 40], ['sales', 'D', 40]]], ['J5', [['rent', 'D', 999], ['acc_depr', 'C', 999]]], ['J5', [['sales', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'cash': -100, 'acc_depr': 999, 'sales': 4900, 'receivable': 5000, 'rent': 999}, 'rejected': ['J5', 'J2', 'J5']}], ['control 2', {'chart': {'loan': 'liability', 'acc_depr': 'contra_asset', 'drawings': 'dividend', 'sales': 'revenue', 'capital': 'equity'}, 'entries': [['J1', [['sales', 'C', 999], ['acc_depr', 'D', 969], ['acc_depr', 'D', 30]]], ['J3', [['drawings', 'C', 5000], ['loan', 'D', 5000]]], ['J2', [['capital', 'D', 30], ['sales', 'C', 1200], ['capital', 'D', 1170]]]]}, {'balances': {'loan': -5000, 'acc_depr': -999, 'drawings': -5000, 'sales': 2199, 'capital': -1200}, 'rejected': []}], ['control 3', {'chart': {'cash': 'asset', 'loan': 'liability', 'sales': 'revenue', 'payable': 'liability', 'drawings': 'dividend'}, 'entries': [['J1', [['loan', 'C', 1200], ['cash', 'D', 1200], ['payable', 'C', 0], ['payable', 'D', 0]]], ['J1', [['drawings', 'C', -40], ['payable', 'D', -40]]], ['J2', [['drawings', 'C', 5000], ['loan', 'D', 5000]]], ['J3', [['payable', 'D', 40], ['cash', 'C', 40]]], ['J5', [['sales', 'D', 40], ['drawings', 'C', 40]]], ['J3', [['loan', 'D', 250], ['sales', 'C', 250]]]]}, {'balances': {'cash': -40, 'loan': -5000, 'sales': -40, 'payable': -40, 'drawings': -5040}, 'rejected': ['J1', 'J1', 'J3']}], ['control 4', {'chart': {'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'drawings': 'dividend', 'loan': 'liability'}, 'entries': [['J3', [['equipment', 'D', 220], ['equipment', 'D', 30], ['loan', 'C', 250]]], ['J2', [['wages', 'C', 5000], ['loan', 'D', 5000]]], ['J3', [['payable', 'D', 40], ['suspense', 'C', 40]]], ['J4', [['equipment', 'C', 999], ['payable', 'D', 999]]], ['J1', [['drawings', 'C', 40], ['loan', 'D', 40]]], ['J5', []], ['J4', [['wages', 'C', 5000], ['payable', 'D', 5000]]]]}, {'balances': {'payable': -999, 'wages': -5000, 'equipment': -749, 'drawings': -40, 'loan': -4790}, 'rejected': ['J3', 'J5', 'J4']}], ['control 5', {'chart': {'rent': 'expense', 'equipment': 'asset', 'wages': 'expense', 'loan': 'liability', 'sales': 'revenue'}, 'entries': [['J3', [['rent', 'D', 30], ['rent', 'D', 220], ['loan', 'C', 250]]], ['J2', [['loan', 'D', 30], ['sales', 'C', 100], ['loan', 'D', 70]]], ['J1', [['rent', 'D', 4970], ['wages', 'C', 5000], ['rent', 'D', 30]]], ['J2', [['equipment', 'D', 1200], ['loan', 'C', 1201]]], ['J1', [['equipment', 'D', 969], ['rent', 'C', 999], ['equipment', 'D', 30]]], ['J5', [['wages', 'D', 30], ['equipment', 'C', 1200], ['wages', 'D', 1170]]], ['J5', [['equipment', 'D', 40], ['suspense', 'C', 40]]]]}, {'balances': {'rent': 5250, 'equipment': -1200, 'wages': -3800, 'loan': 150, 'sales': 100}, 'rejected': ['J2', 'J1', 'J5']}], ['control 6', {'chart': {'sales': 'revenue', 'wages': 'expense', 'payable': 'liability', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['sales', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['capital', 'C', 101], ['wages', 'D', 100]]], ['J3', [['capital', 'D', 10], ['wages', 'C', 40], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 5000], ['suspense', 'C', 5000]]], ['J5', [['acc_depr', 'D', 40], ['payable', 'C', 40]]], ['J1', [['sales', 'D', 250], ['capital', 'C', 250]]], ['J3', [['wages', 'C', 40], ['capital', 'D', 40]]]]}, {'balances': {'sales': -500, 'wages': -40, 'payable': 40, 'capital': 210, 'acc_depr': 210}, 'rejected': ['J4', 'J4', 'J3']}]], [['regression: zero and abnormal balance reporting', {'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': {'drawings': 'dividend', 'capital': 'equity', 'acc_depr': 'contra_asset', 'wages': 'expense', 'rent': 'expense'}, 'entries': [['J4', [['rent', 'D', 1200], ['capital', 'C', 1200]]], ['J5', [['wages', 'C', 999], ['rent', 'D', 969], ['rent', 'D', 30]]], ['J2', [['acc_depr', 'C', 100], ['drawings', 'D', 70], ['drawings', 'D', 30]]], ['J3', [['drawings', 'D', 5000], ['wages', 'C', 5000]]], ['J2', [['rent', 'D', 30], ['capital', 'C', 40], ['rent', 'D', 10]]], ['J1', [['rent', 'C', 999], ['acc_depr', 'D', 999]]], ['J2', [['capital', 'D', 250], ['acc_depr', 'C', 250], ['rent', 'C', 0], ['rent', 'D', 0]]]]}, {'balances': {'drawings': 5100, 'capital': 1200, 'acc_depr': -899, 'wages': -5999, 'rent': 1200}, 'rejected': ['J2', 'J2']}], ['control 3', {'chart': {'drawings': 'dividend', 'rent': 'expense', 'equipment': 'asset', 'acc_depr': 'contra_asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 1200], ['drawings', 'D', 30], ['drawings', 'D', 1170]]], ['J2', []], ['J2', [['acc_depr', 'D', 30], ['acc_depr', 'D', 10], ['equipment', 'C', 40]]], ['J3', [['acc_depr', 'D', -5000], ['equipment', 'C', -5000]]], ['J3', [['equipment', 'C', 999], ['rent', 'D', 30], ['rent', 'D', 969]]], ['J5', [['rent', 'D', 969], ['drawings', 'C', 999], ['rent', 'D', 30]]], ['J5', [['rent', 'D', 5000], ['wages', 'C', 5000]]]]}, {'balances': {'drawings': 201, 'rent': 1998, 'equipment': -1039, 'acc_depr': -40, 'wages': -1200}, 'rejected': ['J2', 'J3', 'J5']}], ['control 4', {'chart': {'wages': 'expense', 'capital': 'equity', 'equipment': 'asset', 'payable': 'liability', 'sales': 'revenue'}, 'entries': [['J4', [['capital', 'D', 30], ['capital', 'D', 1170], ['equipment', 'C', 1200]]], ['J4', [['equipment', 'D', 30], ['equipment', 'D', 1170], ['payable', 'C', 1200]]], ['J4', [['payable', 'C', -1200], ['capital', 'D', -1200]]], ['J4', []], ['J5', [['sales', 'C', 250], ['capital', 'D', 250]]], ['J1', [['payable', 'C', 5000], ['wages', 'D', 5000]]]]}, {'balances': {'wages': 5000, 'capital': -1450, 'equipment': -1200, 'payable': 5000, 'sales': 250}, 'rejected': ['J4', 'J4', 'J4']}], ['control 5', {'chart': {'payable': 'liability', 'sales': 'revenue', 'loan': 'liability', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 999], ['payable', 'D', 999]]], ['J5', [['sales', 'D', 999], ['cash', 'C', 999]]], ['J1', [['wages', 'C', 100], ['payable', 'D', 30], ['payable', 'D', 70]]], ['J4', [['loan', 'D', 30], ['loan', 'D', 70], ['payable', 'C', 100]]], ['J2', [['cash', 'D', 100], ['loan', 'C', 100]]], ['J3', [['wages', 'D', 100], ['loan', 'C', 100]]]]}, {'balances': {'payable': -899, 'sales': -999, 'loan': 100, 'cash': -899, 'wages': -899}, 'rejected': ['J1']}], ['control 6', {'chart': {'acc_depr': 'contra_asset', 'sales': 'revenue', 'drawings': 'dividend', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J4', [['drawings', 'D', 5000], ['acc_depr', 'C', 4999]]], ['J4', [['sales', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['acc_depr', 'D', 250], ['rent', 'C', 250]]], ['J1', [['drawings', 'C', 100], ['cash', 'D', 100]]], ['J3', [['rent', 'D', -999], ['acc_depr', 'C', -999]]], ['J3', [['acc_depr', 'C', 5000], ['rent', 'D', 5000]]], ['J4', [['sales', 'D', 999], ['drawings', 'C', 0], ['drawings', 'D', 0], ['cash', 'C', 999]]]]}, {'balances': {'acc_depr': -250, 'sales': 5000, 'drawings': -100, 'cash': 100, 'rent': 4750}, 'rejected': ['J4', 'J3', 'J3', 'J4']}]], [['regression: zero and abnormal balance reporting', {'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': {'sales': 'revenue', 'capital': 'equity', 'receivable': 'asset', 'equipment': 'asset', 'wages': 'expense', 'payable': 'liability'}, 'entries': [['J3', [['equipment', 'D', 999], ['payable', 'C', 999]]], ['J3', [['capital', 'C', 250], ['equipment', 'D', 250]]], ['J1', [['receivable', 'D', 100], ['capital', 'C', 100]]], ['J4', [['wages', 'C', 40], ['capital', 'D', 30], ['capital', 'D', 10]]], ['J2', [['sales', 'C', 250], ['receivable', 'D', 250]]], ['J3', [['sales', 'C', -100], ['equipment', 'D', -100]]]]}, {'balances': {'sales': 250, 'capital': 60, 'receivable': 350, 'equipment': 999, 'wages': -40, 'payable': 999}, 'rejected': ['J3', 'J3']}], ['control 2', {'chart': {'drawings': 'dividend', 'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 1200], ['wages', 'D', 1200]]], ['J4', [['wages', 'C', 1200], ['drawings', 'D', 1200]]], ['J2', [['sales', 'D', 250], ['equipment', 'C', 250]]], ['J1', [['wages', 'C', 999], ['payable', 'D', 999]]], ['J3', [['sales', 'D', 1170], ['wages', 'C', 1200], ['sales', 'D', 30]]], ['J2', [['wages', 'D', 5000], ['equipment', 'C', 5001]]], ['J2', [['equipment', 'D', 1200], ['suspense', 'C', 1200]]]]}, {'balances': {'drawings': 1200, 'payable': -999, 'wages': -3399, 'equipment': -250, 'sales': -1450}, 'rejected': ['J2', 'J2', 'J2']}], ['control 3', {'chart': {'sales': 'revenue', 'acc_depr': 'contra_asset', 'capital': 'equity', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['cash', 'D', 30], ['cash', 'D', 70], ['sales', 'C', 100]]], ['J2', [['receivable', 'D', 1200], ['capital', 'C', 1200]]], ['J2', [['capital', 'C', 1200], ['acc_depr', 'D', 1170], ['acc_depr', 'D', 30]]], ['J2', [['acc_depr', 'C', 100], ['sales', 'D', 70], ['sales', 'D', 30]]], ['J3', []], ['J1', [['receivable', 'C', 40], ['acc_depr', 'D', 40]]]]}, {'balances': {'sales': 100, 'acc_depr': -40, 'capital': 1200, 'cash': 100, 'receivable': 1160}, 'rejected': ['J2', 'J2', 'J3']}], ['control 4', {'chart': {'loan': 'liability', 'sales': 'revenue', 'wages': 'expense', 'drawings': 'dividend', 'equipment': 'asset'}, 'entries': [['J1', [['loan', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['wages', 'D', 10], ['sales', 'C', 40], ['wages', 'D', 30]]], ['J3', [['equipment', 'D', 4970], ['equipment', 'D', 30], ['loan', 'C', 5000]]]]}, {'balances': {'loan': 5250, 'sales': 40, 'wages': 40, 'drawings': 250, 'equipment': 5000}, 'rejected': []}], ['control 5', {'chart': {'sales': 'revenue', 'payable': 'liability', 'rent': 'expense', 'cash': 'asset', 'loan': 'liability'}, 'entries': [['J2', [['loan', 'C', 40], ['payable', 'D', 40]]], ['J3', []], ['J4', [['rent', 'C', 100], ['payable', 'D', 100]]], ['J1', [['cash', 'D', 30], ['cash', 'D', 10], ['sales', 'C', 40]]], ['J2', [['rent', 'C', 40], ['sales', 'D', 40]]], ['J1', [['cash', 'C', 5000], ['loan', 'D', 5000]]], ['J2', [['payable', 'D', -999], ['rent', 'C', -999]]]]}, {'balances': {'sales': 40, 'payable': -140, 'rent': -100, 'cash': 40, 'loan': 40}, 'rejected': ['J3', 'J2', 'J1', 'J2']}], ['control 6', {'chart': {'drawings': 'dividend', 'cash': 'asset', 'rent': 'expense', 'wages': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J2', [['receivable', 'C', 100], ['drawings', 'D', 30], ['drawings', 'D', 70]]], ['J3', [['rent', 'D', 1170], ['rent', 'D', 30], ['wages', 'C', 1200]]], ['J5', [['wages', 'C', 1200], ['loan', 'D', 30], ['loan', 'D', 1170]]], ['J4', [['drawings', 'D', 30], ['drawings', 'D', 969], ['cash', 'C', 999]]], ['J5', [['cash', 'D', 5000], ['suspense', 'C', 5000]]], ['J5', [['wages', 'C', 100], ['cash', 'D', 100]]], ['J2', [['suspense', 'C', 40], ['loan', 'D', 40]]]]}, {'balances': {'drawings': 1099, 'cash': -999, 'rent': 1200, 'wages': -2400, 'loan': -1200, 'receivable': -100}, 'rejected': ['J5', 'J5', 'J2']}]], [['regression: zero and abnormal balance reporting', {'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 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': {'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 3', {'chart': {'capital': 'equity', 'rent': 'expense', 'acc_depr': 'contra_asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J2', [['rent', 'D', 999], ['cash', 'C', 999]]], ['J3', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['wages', 'C', 1200]]], ['J5', [['rent', 'D', 30], ['rent', 'D', 969], ['capital', 'C', 999]]], ['J4', [['cash', 'D', 0], ['wages', 'C', 5000], ['cash', 'C', 0], ['rent', 'D', 5000]]], ['J1', [['acc_depr', 'C', 0], ['capital', 'C', 5000], ['acc_depr', 'D', 0], ['cash', 'D', 5000]]], ['J5', []], ['J5', [['wages', 'C', 1200], ['rent', 'D', 30], ['rent', 'D', 1170]]]]}, {'balances': {'capital': 999, 'rent': 1998, 'acc_depr': -1200, 'cash': -999, 'wages': -1200}, 'rejected': ['J4', 'J1', 'J5', 'J5']}], ['control 4', {'chart': {'loan': 'liability', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 41], ['cash', 'D', 40]]], ['J4', [['receivable', 'D', 40], ['cash', 'C', 40]]], ['J3', [['loan', 'D', 969], ['equipment', 'C', 999], ['loan', 'D', 30]]], ['J5', [['equipment', 'C', 250], ['wages', 'D', 250]]], ['J2', [['cash', 'D', 30], ['receivable', 'C', 100], ['cash', 'D', 70]]], ['J1', [['equipment', 'D', 1200], ['loan', 'C', 1200]]]]}, {'balances': {'loan': 201, 'receivable': -60, 'equipment': -49, 'cash': 60, 'wages': 250}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'rent': 'expense', 'cash': 'asset', 'loan': 'liability'}, 'entries': [['J2', []], ['J5', [['drawings', 'C', 250], ['acc_depr', 'D', 250]]], ['J1', [['acc_depr', 'C', 1200], ['loan', 'D', 1200]]], ['J3', [['rent', 'C', 100], ['cash', 'D', 100]]], ['J1', [['drawings', 'C', 250], ['acc_depr', 'D', 30], ['acc_depr', 'D', 220]]]]}, {'balances': {'drawings': -250, 'acc_depr': 950, 'rent': -100, 'cash': 100, 'loan': -1200}, 'rejected': ['J2', 'J1']}], ['control 6', {'chart': {'wages': 'expense', 'capital': 'equity', 'drawings': 'dividend', 'sales': 'revenue', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J3', [['wages', 'C', 5000], ['sales', 'D', 30], ['sales', 'D', 4970]]], ['J5', [['receivable', 'C', -999], ['acc_depr', 'D', -999]]], ['J4', [['capital', 'D', 70], ['drawings', 'C', 100], ['capital', 'D', 30]]], ['J3', [['wages', 'C', 1200], ['capital', 'D', 30], ['capital', 'D', 1170]]], ['J3', [['wages', 'C', 100], ['receivable', 'D', 70], ['receivable', 'D', 30]]], ['J5', [['receivable', 'D', 4970], ['acc_depr', 'C', 5000], ['receivable', 'D', 30]]]]}, {'balances': {'wages': -5000, 'capital': -100, 'drawings': -100, 'sales': -5000, 'receivable': 5000, 'acc_depr': 5000}, 'rejected': ['J5', 'J3', 'J3']}]]]
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') == (chart[acct] in debit_normal) else -1
            bal[acct] += sign * amt
    return {'balances': {a: v for a, v in bal.items() if v >= 0}, 'rejected': rejected}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: zero and abnormal balance reporting', {'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': {'payable': 'liability', 'equipment': 'asset', 'rent': 'expense', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J1', [['capital', 'D', 1200], ['acc_depr', 'C', 1200]]], ['J1', []], ['J5', [['payable', 'D', 40], ['equipment', 'C', 40]]], ['J1', []], ['J2', [['capital', 'D', 30], ['acc_depr', 'C', 1200], ['capital', 'D', 1170]]], ['J2', [['acc_depr', 'D', 999], ['equipment', 'C', 999]]], ['J3', [['rent', 'C', 5000], ['payable', 'D', 5000]]]]}, {'balances': {'payable': -5040, 'equipment': -40, 'rent': -5000, 'capital': -2400, 'acc_depr': 2400}, 'rejected': ['J1', 'J1', 'J2']}], ['control 2', {'chart': {'acc_depr': 'contra_asset', 'receivable': 'asset', 'cash': 'asset', 'rent': 'expense', 'wages': 'expense'}, 'entries': [['J5', [['receivable', 'C', 5000], ['acc_depr', 'D', 30], ['acc_depr', 'D', 4970]]], ['J2', [['cash', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['wages', 'C', 40], ['rent', 'D', 40]]]]}, {'balances': {'acc_depr': -4750, 'receivable': -5000, 'cash': 250, 'rent': 40, 'wages': -40}, 'rejected': []}], ['control 3', {'chart': {'receivable': 'asset', 'sales': 'revenue', 'drawings': 'dividend', 'rent': 'expense', 'acc_depr': 'contra_asset'}, 'entries': [['J3', [['receivable', 'D', 1200], ['rent', 'C', 1200]]], ['J5', [['acc_depr', 'C', 100], ['drawings', 'D', 100]]], ['J4', [['rent', 'C', 999], ['acc_depr', 'D', 999]]], ['J5', [['drawings', 'D', 250], ['receivable', 'C', 250]]], ['J4', [['rent', 'C', 100], ['acc_depr', 'D', 100]]], ['J2', [['sales', 'C', 100], ['receivable', 'D', 100]]]]}, {'balances': {'receivable': 1300, 'sales': 100, 'drawings': 100, 'rent': -2199, 'acc_depr': -899}, 'rejected': ['J5', 'J4']}], ['control 4', {'chart': {'receivable': 'asset', 'acc_depr': 'contra_asset', 'payable': 'liability', 'equipment': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['receivable', 'C', 249], ['wages', 'D', 250]]], ['J4', [['receivable', 'D', 999], ['wages', 'C', 999]]], ['J2', [['acc_depr', 'D', 999], ['wages', 'C', 999]]], ['J3', [['equipment', 'D', 999], ['payable', 'C', 999]]]]}, {'balances': {'receivable': 999, 'acc_depr': -999, 'payable': 999, 'equipment': 999, 'wages': -1998}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J4', [['receivable', 'D', 30], ['receivable', 'D', 70], ['cash', 'C', 100]]], ['J3', [['wages', 'C', 100], ['drawings', 'D', 100]]], ['J2', [['equipment', 'D', 70], ['wages', 'C', 100], ['equipment', 'D', 30]]], ['J5', [['drawings', 'D', 4970], ['equipment', 'C', 5000], ['drawings', 'D', 30]]], ['J1', [['wages', 'D', 999], ['drawings', 'C', 1009]]]]}, {'balances': {'drawings': 5100, 'receivable': 100, 'equipment': -4900, 'cash': -100, 'wages': -200}, 'rejected': ['J1']}], ['control 6', {'chart': {'rent': 'expense', 'sales': 'revenue', 'equipment': 'asset', 'capital': 'equity', 'loan': 'liability'}, 'entries': [['J5', [['equipment', 'C', 999], ['sales', 'D', 999], ['loan', 'D', 0], ['loan', 'C', 0]]], ['J5', [['loan', 'C', 250], ['rent', 'D', 250]]], ['J1', [['loan', 'C', 40], ['equipment', 'D', 30], ['equipment', 'D', 10]]], ['J3', [['sales', 'C', 1200], ['capital', 'D', 1200]]], ['J1', [['sales', 'D', 999], ['equipment', 'C', 1000]]], ['J4', [['suspense', 'C', 40], ['capital', 'D', 40]]]]}, {'balances': {'rent': 250, 'sales': 1200, 'equipment': 40, 'capital': -1200, 'loan': 290}, 'rejected': ['J5', 'J1', 'J4']}]], [['regression: zero and abnormal balance reporting', {'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': {'cash': 'asset', 'acc_depr': 'contra_asset', 'sales': 'revenue', 'receivable': 'asset', 'rent': 'expense'}, 'entries': [['J2', [['cash', 'C', 100], ['sales', 'D', 100]]], ['J5', [['cash', 'C', 1210], ['receivable', 'D', 1200]]], ['J4', [['sales', 'C', 5000], ['receivable', 'D', 5000]]], ['J2', [['cash', 'C', 40], ['sales', 'D', 40]]], ['J5', [['rent', 'D', 999], ['acc_depr', 'C', 999]]], ['J5', [['sales', 'D', 100], ['suspense', 'C', 100]]]]}, {'balances': {'cash': -100, 'acc_depr': 999, 'sales': 4900, 'receivable': 5000, 'rent': 999}, 'rejected': ['J5', 'J2', 'J5']}], ['control 2', {'chart': {'loan': 'liability', 'acc_depr': 'contra_asset', 'drawings': 'dividend', 'sales': 'revenue', 'capital': 'equity'}, 'entries': [['J1', [['sales', 'C', 999], ['acc_depr', 'D', 969], ['acc_depr', 'D', 30]]], ['J3', [['drawings', 'C', 5000], ['loan', 'D', 5000]]], ['J2', [['capital', 'D', 30], ['sales', 'C', 1200], ['capital', 'D', 1170]]]]}, {'balances': {'loan': -5000, 'acc_depr': -999, 'drawings': -5000, 'sales': 2199, 'capital': -1200}, 'rejected': []}], ['control 3', {'chart': {'cash': 'asset', 'loan': 'liability', 'sales': 'revenue', 'payable': 'liability', 'drawings': 'dividend'}, 'entries': [['J1', [['loan', 'C', 1200], ['cash', 'D', 1200], ['payable', 'C', 0], ['payable', 'D', 0]]], ['J1', [['drawings', 'C', -40], ['payable', 'D', -40]]], ['J2', [['drawings', 'C', 5000], ['loan', 'D', 5000]]], ['J3', [['payable', 'D', 40], ['cash', 'C', 40]]], ['J5', [['sales', 'D', 40], ['drawings', 'C', 40]]], ['J3', [['loan', 'D', 250], ['sales', 'C', 250]]]]}, {'balances': {'cash': -40, 'loan': -5000, 'sales': -40, 'payable': -40, 'drawings': -5040}, 'rejected': ['J1', 'J1', 'J3']}], ['control 4', {'chart': {'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'drawings': 'dividend', 'loan': 'liability'}, 'entries': [['J3', [['equipment', 'D', 220], ['equipment', 'D', 30], ['loan', 'C', 250]]], ['J2', [['wages', 'C', 5000], ['loan', 'D', 5000]]], ['J3', [['payable', 'D', 40], ['suspense', 'C', 40]]], ['J4', [['equipment', 'C', 999], ['payable', 'D', 999]]], ['J1', [['drawings', 'C', 40], ['loan', 'D', 40]]], ['J5', []], ['J4', [['wages', 'C', 5000], ['payable', 'D', 5000]]]]}, {'balances': {'payable': -999, 'wages': -5000, 'equipment': -749, 'drawings': -40, 'loan': -4790}, 'rejected': ['J3', 'J5', 'J4']}], ['control 5', {'chart': {'rent': 'expense', 'equipment': 'asset', 'wages': 'expense', 'loan': 'liability', 'sales': 'revenue'}, 'entries': [['J3', [['rent', 'D', 30], ['rent', 'D', 220], ['loan', 'C', 250]]], ['J2', [['loan', 'D', 30], ['sales', 'C', 100], ['loan', 'D', 70]]], ['J1', [['rent', 'D', 4970], ['wages', 'C', 5000], ['rent', 'D', 30]]], ['J2', [['equipment', 'D', 1200], ['loan', 'C', 1201]]], ['J1', [['equipment', 'D', 969], ['rent', 'C', 999], ['equipment', 'D', 30]]], ['J5', [['wages', 'D', 30], ['equipment', 'C', 1200], ['wages', 'D', 1170]]], ['J5', [['equipment', 'D', 40], ['suspense', 'C', 40]]]]}, {'balances': {'rent': 5250, 'equipment': -1200, 'wages': -3800, 'loan': 150, 'sales': 100}, 'rejected': ['J2', 'J1', 'J5']}], ['control 6', {'chart': {'sales': 'revenue', 'wages': 'expense', 'payable': 'liability', 'capital': 'equity', 'acc_depr': 'contra_asset'}, 'entries': [['J4', [['sales', 'D', 250], ['acc_depr', 'C', 250]]], ['J4', [['capital', 'C', 101], ['wages', 'D', 100]]], ['J3', [['capital', 'D', 10], ['wages', 'C', 40], ['capital', 'D', 30]]], ['J4', [['acc_depr', 'D', 5000], ['suspense', 'C', 5000]]], ['J5', [['acc_depr', 'D', 40], ['payable', 'C', 40]]], ['J1', [['sales', 'D', 250], ['capital', 'C', 250]]], ['J3', [['wages', 'C', 40], ['capital', 'D', 40]]]]}, {'balances': {'sales': -500, 'wages': -40, 'payable': 40, 'capital': 210, 'acc_depr': 210}, 'rejected': ['J4', 'J4', 'J3']}]], [['regression: zero and abnormal balance reporting', {'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': {'drawings': 'dividend', 'capital': 'equity', 'acc_depr': 'contra_asset', 'wages': 'expense', 'rent': 'expense'}, 'entries': [['J4', [['rent', 'D', 1200], ['capital', 'C', 1200]]], ['J5', [['wages', 'C', 999], ['rent', 'D', 969], ['rent', 'D', 30]]], ['J2', [['acc_depr', 'C', 100], ['drawings', 'D', 70], ['drawings', 'D', 30]]], ['J3', [['drawings', 'D', 5000], ['wages', 'C', 5000]]], ['J2', [['rent', 'D', 30], ['capital', 'C', 40], ['rent', 'D', 10]]], ['J1', [['rent', 'C', 999], ['acc_depr', 'D', 999]]], ['J2', [['capital', 'D', 250], ['acc_depr', 'C', 250], ['rent', 'C', 0], ['rent', 'D', 0]]]]}, {'balances': {'drawings': 5100, 'capital': 1200, 'acc_depr': -899, 'wages': -5999, 'rent': 1200}, 'rejected': ['J2', 'J2']}], ['control 3', {'chart': {'drawings': 'dividend', 'rent': 'expense', 'equipment': 'asset', 'acc_depr': 'contra_asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 1200], ['drawings', 'D', 30], ['drawings', 'D', 1170]]], ['J2', []], ['J2', [['acc_depr', 'D', 30], ['acc_depr', 'D', 10], ['equipment', 'C', 40]]], ['J3', [['acc_depr', 'D', -5000], ['equipment', 'C', -5000]]], ['J3', [['equipment', 'C', 999], ['rent', 'D', 30], ['rent', 'D', 969]]], ['J5', [['rent', 'D', 969], ['drawings', 'C', 999], ['rent', 'D', 30]]], ['J5', [['rent', 'D', 5000], ['wages', 'C', 5000]]]]}, {'balances': {'drawings': 201, 'rent': 1998, 'equipment': -1039, 'acc_depr': -40, 'wages': -1200}, 'rejected': ['J2', 'J3', 'J5']}], ['control 4', {'chart': {'wages': 'expense', 'capital': 'equity', 'equipment': 'asset', 'payable': 'liability', 'sales': 'revenue'}, 'entries': [['J4', [['capital', 'D', 30], ['capital', 'D', 1170], ['equipment', 'C', 1200]]], ['J4', [['equipment', 'D', 30], ['equipment', 'D', 1170], ['payable', 'C', 1200]]], ['J4', [['payable', 'C', -1200], ['capital', 'D', -1200]]], ['J4', []], ['J5', [['sales', 'C', 250], ['capital', 'D', 250]]], ['J1', [['payable', 'C', 5000], ['wages', 'D', 5000]]]]}, {'balances': {'wages': 5000, 'capital': -1450, 'equipment': -1200, 'payable': 5000, 'sales': 250}, 'rejected': ['J4', 'J4', 'J4']}], ['control 5', {'chart': {'payable': 'liability', 'sales': 'revenue', 'loan': 'liability', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 999], ['payable', 'D', 999]]], ['J5', [['sales', 'D', 999], ['cash', 'C', 999]]], ['J1', [['wages', 'C', 100], ['payable', 'D', 30], ['payable', 'D', 70]]], ['J4', [['loan', 'D', 30], ['loan', 'D', 70], ['payable', 'C', 100]]], ['J2', [['cash', 'D', 100], ['loan', 'C', 100]]], ['J3', [['wages', 'D', 100], ['loan', 'C', 100]]]]}, {'balances': {'payable': -899, 'sales': -999, 'loan': 100, 'cash': -899, 'wages': -899}, 'rejected': ['J1']}], ['control 6', {'chart': {'acc_depr': 'contra_asset', 'sales': 'revenue', 'drawings': 'dividend', 'cash': 'asset', 'rent': 'expense'}, 'entries': [['J4', [['drawings', 'D', 5000], ['acc_depr', 'C', 4999]]], ['J4', [['sales', 'C', 5000], ['rent', 'D', 5000]]], ['J3', [['acc_depr', 'D', 250], ['rent', 'C', 250]]], ['J1', [['drawings', 'C', 100], ['cash', 'D', 100]]], ['J3', [['rent', 'D', -999], ['acc_depr', 'C', -999]]], ['J3', [['acc_depr', 'C', 5000], ['rent', 'D', 5000]]], ['J4', [['sales', 'D', 999], ['drawings', 'C', 0], ['drawings', 'D', 0], ['cash', 'C', 999]]]]}, {'balances': {'acc_depr': -250, 'sales': 5000, 'drawings': -100, 'cash': 100, 'rent': 4750}, 'rejected': ['J4', 'J3', 'J3', 'J4']}]], [['regression: zero and abnormal balance reporting', {'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': {'sales': 'revenue', 'capital': 'equity', 'receivable': 'asset', 'equipment': 'asset', 'wages': 'expense', 'payable': 'liability'}, 'entries': [['J3', [['equipment', 'D', 999], ['payable', 'C', 999]]], ['J3', [['capital', 'C', 250], ['equipment', 'D', 250]]], ['J1', [['receivable', 'D', 100], ['capital', 'C', 100]]], ['J4', [['wages', 'C', 40], ['capital', 'D', 30], ['capital', 'D', 10]]], ['J2', [['sales', 'C', 250], ['receivable', 'D', 250]]], ['J3', [['sales', 'C', -100], ['equipment', 'D', -100]]]]}, {'balances': {'sales': 250, 'capital': 60, 'receivable': 350, 'equipment': 999, 'wages': -40, 'payable': 999}, 'rejected': ['J3', 'J3']}], ['control 2', {'chart': {'drawings': 'dividend', 'payable': 'liability', 'wages': 'expense', 'equipment': 'asset', 'sales': 'revenue'}, 'entries': [['J2', [['suspense', 'C', 1200], ['wages', 'D', 1200]]], ['J4', [['wages', 'C', 1200], ['drawings', 'D', 1200]]], ['J2', [['sales', 'D', 250], ['equipment', 'C', 250]]], ['J1', [['wages', 'C', 999], ['payable', 'D', 999]]], ['J3', [['sales', 'D', 1170], ['wages', 'C', 1200], ['sales', 'D', 30]]], ['J2', [['wages', 'D', 5000], ['equipment', 'C', 5001]]], ['J2', [['equipment', 'D', 1200], ['suspense', 'C', 1200]]]]}, {'balances': {'drawings': 1200, 'payable': -999, 'wages': -3399, 'equipment': -250, 'sales': -1450}, 'rejected': ['J2', 'J2', 'J2']}], ['control 3', {'chart': {'sales': 'revenue', 'acc_depr': 'contra_asset', 'capital': 'equity', 'cash': 'asset', 'receivable': 'asset'}, 'entries': [['J5', [['cash', 'D', 30], ['cash', 'D', 70], ['sales', 'C', 100]]], ['J2', [['receivable', 'D', 1200], ['capital', 'C', 1200]]], ['J2', [['capital', 'C', 1200], ['acc_depr', 'D', 1170], ['acc_depr', 'D', 30]]], ['J2', [['acc_depr', 'C', 100], ['sales', 'D', 70], ['sales', 'D', 30]]], ['J3', []], ['J1', [['receivable', 'C', 40], ['acc_depr', 'D', 40]]]]}, {'balances': {'sales': 100, 'acc_depr': -40, 'capital': 1200, 'cash': 100, 'receivable': 1160}, 'rejected': ['J2', 'J2', 'J3']}], ['control 4', {'chart': {'loan': 'liability', 'sales': 'revenue', 'wages': 'expense', 'drawings': 'dividend', 'equipment': 'asset'}, 'entries': [['J1', [['loan', 'C', 250], ['drawings', 'D', 250]]], ['J4', [['wages', 'D', 10], ['sales', 'C', 40], ['wages', 'D', 30]]], ['J3', [['equipment', 'D', 4970], ['equipment', 'D', 30], ['loan', 'C', 5000]]]]}, {'balances': {'loan': 5250, 'sales': 40, 'wages': 40, 'drawings': 250, 'equipment': 5000}, 'rejected': []}], ['control 5', {'chart': {'sales': 'revenue', 'payable': 'liability', 'rent': 'expense', 'cash': 'asset', 'loan': 'liability'}, 'entries': [['J2', [['loan', 'C', 40], ['payable', 'D', 40]]], ['J3', []], ['J4', [['rent', 'C', 100], ['payable', 'D', 100]]], ['J1', [['cash', 'D', 30], ['cash', 'D', 10], ['sales', 'C', 40]]], ['J2', [['rent', 'C', 40], ['sales', 'D', 40]]], ['J1', [['cash', 'C', 5000], ['loan', 'D', 5000]]], ['J2', [['payable', 'D', -999], ['rent', 'C', -999]]]]}, {'balances': {'sales': 40, 'payable': -140, 'rent': -100, 'cash': 40, 'loan': 40}, 'rejected': ['J3', 'J2', 'J1', 'J2']}], ['control 6', {'chart': {'drawings': 'dividend', 'cash': 'asset', 'rent': 'expense', 'wages': 'expense', 'loan': 'liability', 'receivable': 'asset'}, 'entries': [['J2', [['receivable', 'C', 100], ['drawings', 'D', 30], ['drawings', 'D', 70]]], ['J3', [['rent', 'D', 1170], ['rent', 'D', 30], ['wages', 'C', 1200]]], ['J5', [['wages', 'C', 1200], ['loan', 'D', 30], ['loan', 'D', 1170]]], ['J4', [['drawings', 'D', 30], ['drawings', 'D', 969], ['cash', 'C', 999]]], ['J5', [['cash', 'D', 5000], ['suspense', 'C', 5000]]], ['J5', [['wages', 'C', 100], ['cash', 'D', 100]]], ['J2', [['suspense', 'C', 40], ['loan', 'D', 40]]]]}, {'balances': {'drawings': 1099, 'cash': -999, 'rent': 1200, 'wages': -2400, 'loan': -1200, 'receivable': -100}, 'rejected': ['J5', 'J5', 'J2']}]], [['regression: zero and abnormal balance reporting', {'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 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': {'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 3', {'chart': {'capital': 'equity', 'rent': 'expense', 'acc_depr': 'contra_asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J2', [['rent', 'D', 999], ['cash', 'C', 999]]], ['J3', [['acc_depr', 'D', 1170], ['acc_depr', 'D', 30], ['wages', 'C', 1200]]], ['J5', [['rent', 'D', 30], ['rent', 'D', 969], ['capital', 'C', 999]]], ['J4', [['cash', 'D', 0], ['wages', 'C', 5000], ['cash', 'C', 0], ['rent', 'D', 5000]]], ['J1', [['acc_depr', 'C', 0], ['capital', 'C', 5000], ['acc_depr', 'D', 0], ['cash', 'D', 5000]]], ['J5', []], ['J5', [['wages', 'C', 1200], ['rent', 'D', 30], ['rent', 'D', 1170]]]]}, {'balances': {'capital': 999, 'rent': 1998, 'acc_depr': -1200, 'cash': -999, 'wages': -1200}, 'rejected': ['J4', 'J1', 'J5', 'J5']}], ['control 4', {'chart': {'loan': 'liability', 'receivable': 'asset', 'equipment': 'asset', 'cash': 'asset', 'wages': 'expense'}, 'entries': [['J1', [['wages', 'C', 41], ['cash', 'D', 40]]], ['J4', [['receivable', 'D', 40], ['cash', 'C', 40]]], ['J3', [['loan', 'D', 969], ['equipment', 'C', 999], ['loan', 'D', 30]]], ['J5', [['equipment', 'C', 250], ['wages', 'D', 250]]], ['J2', [['cash', 'D', 30], ['receivable', 'C', 100], ['cash', 'D', 70]]], ['J1', [['equipment', 'D', 1200], ['loan', 'C', 1200]]]]}, {'balances': {'loan': 201, 'receivable': -60, 'equipment': -49, 'cash': 60, 'wages': 250}, 'rejected': ['J1']}], ['control 5', {'chart': {'drawings': 'dividend', 'acc_depr': 'contra_asset', 'rent': 'expense', 'cash': 'asset', 'loan': 'liability'}, 'entries': [['J2', []], ['J5', [['drawings', 'C', 250], ['acc_depr', 'D', 250]]], ['J1', [['acc_depr', 'C', 1200], ['loan', 'D', 1200]]], ['J3', [['rent', 'C', 100], ['cash', 'D', 100]]], ['J1', [['drawings', 'C', 250], ['acc_depr', 'D', 30], ['acc_depr', 'D', 220]]]]}, {'balances': {'drawings': -250, 'acc_depr': 950, 'rent': -100, 'cash': 100, 'loan': -1200}, 'rejected': ['J2', 'J1']}], ['control 6', {'chart': {'wages': 'expense', 'capital': 'equity', 'drawings': 'dividend', 'sales': 'revenue', 'receivable': 'asset', 'acc_depr': 'contra_asset'}, 'entries': [['J3', [['wages', 'C', 5000], ['sales', 'D', 30], ['sales', 'D', 4970]]], ['J5', [['receivable', 'C', -999], ['acc_depr', 'D', -999]]], ['J4', [['capital', 'D', 70], ['drawings', 'C', 100], ['capital', 'D', 30]]], ['J3', [['wages', 'C', 1200], ['capital', 'D', 30], ['capital', 'D', 1170]]], ['J3', [['wages', 'C', 100], ['receivable', 'D', 70], ['receivable', 'D', 30]]], ['J5', [['receivable', 'D', 4970], ['acc_depr', 'C', 5000], ['receivable', 'D', 30]]]]}, {'balances': {'wages': -5000, 'capital': -100, 'drawings': -100, 'sales': -5000, 'receivable': 5000, 'acc_depr': 5000}, 'rejected': ['J5', 'J3', 'J3']}]]]
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:
Chart accounts with no activity disappear from the balance report.

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


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
An overdrawn cash account appears as a negative number in the debit column.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


prompt:
Fully offset accounts clutter the trial balance as all-zero rows.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


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

N = 1
observations = []
def solve(x):
    debit_normal = ('asset', 'expense', 'dividend')
    rows = []
    td = tc = 0
    abnormal = []
    for acct, kind, dr, cr in x:
        net = dr - cr
        if net == 0:
            continue
        if net > 0:
            rows.append([acct, net, 0])
            td += net
        else:
            rows.append([acct, 0, -net])
            tc += -net
        if net < 0:
            abnormal.append(acct)
    rows.sort(key=lambda r: int(r[0]))
    return {'rows': rows, 'totals': [td, tc], 'balanced': td == tc, 'abnormal': sorted(abnormal, key=int)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: abnormal balance flag', [['4000', 'dividend', 250, 0], ['7200', 'dividend', 5000, 0], ['1500', 'equity', 0, 1]], {'rows': [['1500', 0, 1], ['4000', 250, 0], ['7200', 5000, 0]], 'totals': [5250, 1], 'balanced': False, 'abnormal': []}], ['regression: abnormal balance flag, partial-repair probe', [['99', 'expense', 0, -1], ['205', 'asset', 5000, 0], ['510', 'liability', 1234, 100]], {'rows': [['99', 1, 0], ['205', 5000, 0], ['510', 1134, 0]], 'totals': [6135, 0], 'balanced': False, 'abnormal': ['510']}], ['control 1', [['150', 'liability', 1234, 1234], ['101', 'asset', 0, -1], ['205', 'equity', 0, 0], ['7200', 'dividend', 900, 250]], {'rows': [['101', 1, 0], ['7200', 650, 0]], 'totals': [651, 0], 'balanced': False, 'abnormal': []}], ['control 2', [['2100', 'revenue', 0, 0], ['4000', 'revenue', 0, 0], ['99', 'equity', 5000, 5000], ['510', 'asset', 0, 0]], {'rows': [], 'totals': [0, 0], 'balanced': True, 'abnormal': []}], ['control 3', [['30', 'dividend', 1234, 1234], ['150', 'asset', 0, 250], ['4000', 'dividend', 1234, 0], ['101', 'dividend', 900, 0]], {'rows': [['101', 900, 0], ['150', 0, 250], ['4000', 1234, 0]], 'totals': [2134, 250], 'balanced': False, 'abnormal': ['150']}], ['control 4', [['510', 'asset', 250, 251], ['99', 'asset', 0, 5000], ['7200', 'equity', 900, 900], ['1500', 'asset', 0, 250], ['2100', 'asset', 900, 899]], {'rows': [['99', 0, 5000], ['510', 0, 1], ['1500', 0, 250], ['2100', 1, 0]], 'totals': [1, 5251], 'balanced': False, 'abnormal': ['99', '510', '1500']}], ['control 5', [['1010', 'dividend', 0, 100], ['205', 'liability', 5000, 5000], ['510', 'asset', 0, 0], ['1500', 'expense', 250, 1234]], {'rows': [['1010', 0, 100], ['1500', 0, 984]], 'totals': [0, 1084], 'balanced': False, 'abnormal': ['1010', '1500']}]], [['regression: abnormal balance flag', [['6', 'expense', 0, 0], ['30', 'asset', 250, 249], ['7200', 'expense', 5000, 5000], ['150', 'expense', 100, 100], ['2100', 'dividend', 900, 901], ['205', 'equity', 100, 101]], {'rows': [['30', 1, 0], ['205', 0, 1], ['2100', 0, 1]], 'totals': [1, 2], 'balanced': False, 'abnormal': ['2100']}], ['regression: abnormal balance flag, partial-repair probe', [['150', 'liability', 5000, 250], ['2100', 'dividend', 1234, 250], ['4000', 'asset', 250, 1234], ['99', 'equity', 900, 100], ['101', 'equity', 1234, 1233]], {'rows': [['99', 800, 0], ['101', 1, 0], ['150', 4750, 0], ['2100', 984, 0], ['4000', 0, 984]], 'totals': [6535, 984], 'balanced': False, 'abnormal': ['99', '101', '150', '4000']}], ['control 1', [['510', 'expense', 900, 5000], ['6', 'dividend', 0, 0], ['150', 'expense', 1234, 1234]], {'rows': [['510', 0, 4100]], 'totals': [0, 4100], 'balanced': False, 'abnormal': ['510']}], ['control 2', [['150', 'asset', 5000, 0], ['30', 'expense', 100, 100], ['1010', 'expense', 900, 900], ['99', 'dividend', 1234, 1233], ['4000', 'asset', 1234, 1235]], {'rows': [['99', 1, 0], ['150', 5000, 0], ['4000', 0, 1]], 'totals': [5001, 1], 'balanced': False, 'abnormal': ['4000']}], ['control 3', [['99', 'asset', 100, 250], ['4000', 'dividend', 100, 0], ['6', 'dividend', 1234, 0]], {'rows': [['6', 1234, 0], ['99', 0, 150], ['4000', 100, 0]], 'totals': [1334, 150], 'balanced': False, 'abnormal': ['99']}], ['control 4', [['7200', 'asset', 5000, 4999], ['205', 'asset', 1234, 5000], ['1500', 'dividend', 0, 0]], {'rows': [['205', 0, 3766], ['7200', 1, 0]], 'totals': [1, 3766], 'balanced': False, 'abnormal': ['205']}], ['control 5', [['1010', 'asset', 250, 0], ['510', 'expense', 5000, 1234], ['7200', 'dividend', 100, 100]], {'rows': [['510', 3766, 0], ['1010', 250, 0]], 'totals': [4016, 0], 'balanced': False, 'abnormal': []}]], [['regression: abnormal balance flag', [['2100', 'expense', 100, 5000], ['7200', 'liability', 5000, 100], ['6', 'dividend', 250, 1234], ['99', 'dividend', 0, 1234], ['205', 'expense', 5000, 5001], ['101', 'equity', 0, 1234], ['4000', 'revenue', 250, 5000]], {'rows': [['6', 0, 984], ['99', 0, 1234], ['101', 0, 1234], ['205', 0, 1], ['2100', 0, 4900], ['4000', 0, 4750], ['7200', 4900, 0]], 'totals': [4900, 13103], 'balanced': False, 'abnormal': ['6', '99', '205', '2100', '7200']}], ['control 1', [['7200', 'revenue', 250, 250], ['99', 'asset', 1234, 250], ['205', 'asset', 5000, 0]], {'rows': [['99', 984, 0], ['205', 5000, 0]], 'totals': [5984, 0], 'balanced': False, 'abnormal': []}], ['control 2', [['150', 'asset', 5000, 900], ['205', 'expense', 0, 1234], ['7200', 'asset', 0, 5000]], {'rows': [['150', 4100, 0], ['205', 0, 1234], ['7200', 0, 5000]], 'totals': [4100, 6234], 'balanced': False, 'abnormal': ['205', '7200']}], ['control 3', [['2100', 'dividend', 1234, 0], ['99', 'revenue', 5000, 5000], ['205', 'dividend', 5000, 5001]], {'rows': [['205', 0, 1], ['2100', 1234, 0]], 'totals': [1234, 1], 'balanced': False, 'abnormal': ['205']}], ['control 4', [['6', 'dividend', 0, 5000], ['1500', 'asset', 100, 100], ['30', 'expense', 900, 250], ['510', 'expense', 1234, 0], ['101', 'asset', 5000, 5001], ['4000', 'asset', 0, 5000]], {'rows': [['6', 0, 5000], ['30', 650, 0], ['101', 0, 1], ['510', 1234, 0], ['4000', 0, 5000]], 'totals': [1884, 10001], 'balanced': False, 'abnormal': ['6', '101', '4000']}], ['control 5', [['4000', 'equity', 250, 250], ['1010', 'expense', 1234, 1233], ['30', 'dividend', 100, 100], ['510', 'asset', 250, 0], ['7200', 'liability', 0, 0]], {'rows': [['510', 250, 0], ['1010', 1, 0]], 'totals': [251, 0], 'balanced': False, 'abnormal': []}], ['control 6', [['1500', 'expense', 5000, 100], ['205', 'dividend', 900, 5000], ['2100', 'revenue', 0, 0], ['1010', 'expense', 0, 900]], {'rows': [['205', 0, 4100], ['1010', 0, 900], ['1500', 4900, 0]], 'totals': [4900, 5000], 'balanced': False, 'abnormal': ['205', '1010']}]], [['regression: abnormal balance flag', [['99', 'liability', 1234, 1233], ['30', 'dividend', 5000, 900], ['150', 'liability', 1234, 1234], ['1010', 'liability', 250, 1234], ['510', 'liability', 100, 0], ['4000', 'expense', 100, 100]], {'rows': [['30', 4100, 0], ['99', 1, 0], ['510', 100, 0], ['1010', 0, 984]], 'totals': [4201, 984], 'balanced': False, 'abnormal': ['99', '510']}], ['control 1', [['30', 'asset', 5000, 0], ['510', 'expense', 100, 100], ['6', 'dividend', 100, 900]], {'rows': [['6', 0, 800], ['30', 5000, 0]], 'totals': [5000, 800], 'balanced': False, 'abnormal': ['6']}], ['control 2', [['99', 'expense', 900, 100], ['4000', 'dividend', 5000, 0], ['2100', 'expense', 250, 250], ['510', 'expense', 900, 5000], ['6', 'expense', 5000, 250], ['1500', 'liability', 0, 0]], {'rows': [['6', 4750, 0], ['99', 800, 0], ['510', 0, 4100], ['4000', 5000, 0]], 'totals': [10550, 4100], 'balanced': False, 'abnormal': ['510']}], ['control 3', [['6', 'asset', 5000, 900], ['30', 'asset', 100, 0], ['1500', 'liability', 100, 100]], {'rows': [['6', 4100, 0], ['30', 100, 0]], 'totals': [4200, 0], 'balanced': False, 'abnormal': []}], ['control 4', [['2100', 'expense', 0, 100], ['1010', 'expense', 100, 99], ['101', 'expense', 900, 5000], ['7200', 'dividend', 1234, 900], ['205', 'liability', 0, 0], ['4000', 'revenue', 900, 900]], {'rows': [['101', 0, 4100], ['1010', 1, 0], ['2100', 0, 100], ['7200', 334, 0]], 'totals': [335, 4200], 'balanced': False, 'abnormal': ['101', '2100']}], ['control 5', [['150', 'dividend', 100, 0], ['6', 'dividend', 900, 0], ['1500', 'revenue', 1234, 1234], ['30', 'equity', 100, 100]], {'rows': [['6', 900, 0], ['150', 100, 0]], 'totals': [1000, 0], 'balanced': False, 'abnormal': []}], ['control 6', [['101', 'dividend', 5000, 4999], ['99', 'asset', 100, 100], ['30', 'expense', 250, 249]], {'rows': [['30', 1, 0], ['101', 1, 0]], 'totals': [2, 0], 'balanced': False, 'abnormal': []}]], [['regression: abnormal balance flag', [['4000', 'revenue', 0, 1], ['30', 'expense', 250, 250], ['2100', 'asset', 900, 100]], {'rows': [['2100', 800, 0], ['4000', 0, 1]], 'totals': [800, 1], 'balanced': False, 'abnormal': []}], ['regression: abnormal balance flag, partial-repair probe', [['99', 'liability', 5000, 0], ['30', 'liability', 0, 0], ['4000', 'expense', 0, 900], ['205', 'revenue', 900, 5000], ['1010', 'liability', 0, 250]], {'rows': [['99', 5000, 0], ['205', 0, 4100], ['1010', 0, 250], ['4000', 0, 900]], 'totals': [5000, 5250], 'balanced': False, 'abnormal': ['99', '4000']}], ['control 1', [['510', 'asset', 0, 1234], ['1500', 'asset', 1234, 1233], ['99', 'expense', 0, 1], ['101', 'asset', 900, 900], ['30', 'expense', 1234, 1234]], {'rows': [['99', 0, 1], ['510', 0, 1234], ['1500', 1, 0]], 'totals': [1, 1235], 'balanced': False, 'abnormal': ['99', '510']}], ['control 2', [['30', 'asset', 100, 0], ['205', 'dividend', 250, 249], ['6', 'asset', 250, 900], ['150', 'expense', 0, 1234]], {'rows': [['6', 0, 650], ['30', 100, 0], ['150', 0, 1234], ['205', 1, 0]], 'totals': [101, 1884], 'balanced': False, 'abnormal': ['6', '150']}], ['control 3', [['7200', 'expense', 250, 251], ['150', 'expense', 5000, 1234], ['30', 'asset', 100, 99]], {'rows': [['30', 1, 0], ['150', 3766, 0], ['7200', 0, 1]], 'totals': [3767, 1], 'balanced': False, 'abnormal': ['7200']}], ['control 4', [['1500', 'asset', 0, 5000], ['1010', 'equity', 5000, 5000], ['99', 'asset', 250, 249]], {'rows': [['99', 1, 0], ['1500', 0, 5000]], 'totals': [1, 5000], 'balanced': False, 'abnormal': ['1500']}], ['control 5', [['150', 'expense', 100, 0], ['101', 'liability', 250, 250], ['99', 'liability', 100, 100], ['205', 'equity', 100, 100], ['510', 'expense', 100, 0], ['7200', 'asset', 5000, 5000]], {'rows': [['150', 100, 0], ['510', 100, 0]], 'totals': [200, 0], 'balanced': False, 'abnormal': []}]]]
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):
    debit_normal = ('asset', 'expense', 'dividend')
    rows = []
    td = tc = 0
    abnormal = []
    for acct, kind, dr, cr in x:
        net = dr - cr
        if net == 0:
            continue
        if net > 0:
            rows.append([acct, net, 0])
            td += net
        else:
            rows.append([acct, 0, -net])
            tc += -net
        if net < 0 and kind in debit_normal:
            abnormal.append(acct)
    rows.sort(key=lambda r: int(r[0]))
    return {'rows': rows, 'totals': [td, tc], 'balanced': td == tc, 'abnormal': sorted(abnormal, key=int)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: abnormal balance flag', [['4000', 'dividend', 250, 0], ['7200', 'dividend', 5000, 0], ['1500', 'equity', 0, 1]], {'rows': [['1500', 0, 1], ['4000', 250, 0], ['7200', 5000, 0]], 'totals': [5250, 1], 'balanced': False, 'abnormal': []}], ['regression: abnormal balance flag, partial-repair probe', [['99', 'expense', 0, -1], ['205', 'asset', 5000, 0], ['510', 'liability', 1234, 100]], {'rows': [['99', 1, 0], ['205', 5000, 0], ['510', 1134, 0]], 'totals': [6135, 0], 'balanced': False, 'abnormal': ['510']}], ['control 1', [['150', 'liability', 1234, 1234], ['101', 'asset', 0, -1], ['205', 'equity', 0, 0], ['7200', 'dividend', 900, 250]], {'rows': [['101', 1, 0], ['7200', 650, 0]], 'totals': [651, 0], 'balanced': False, 'abnormal': []}], ['control 2', [['2100', 'revenue', 0, 0], ['4000', 'revenue', 0, 0], ['99', 'equity', 5000, 5000], ['510', 'asset', 0, 0]], {'rows': [], 'totals': [0, 0], 'balanced': True, 'abnormal': []}], ['control 3', [['30', 'dividend', 1234, 1234], ['150', 'asset', 0, 250], ['4000', 'dividend', 1234, 0], ['101', 'dividend', 900, 0]], {'rows': [['101', 900, 0], ['150', 0, 250], ['4000', 1234, 0]], 'totals': [2134, 250], 'balanced': False, 'abnormal': ['150']}], ['control 4', [['510', 'asset', 250, 251], ['99', 'asset', 0, 5000], ['7200', 'equity', 900, 900], ['1500', 'asset', 0, 250], ['2100', 'asset', 900, 899]], {'rows': [['99', 0, 5000], ['510', 0, 1], ['1500', 0, 250], ['2100', 1, 0]], 'totals': [1, 5251], 'balanced': False, 'abnormal': ['99', '510', '1500']}], ['control 5', [['1010', 'dividend', 0, 100], ['205', 'liability', 5000, 5000], ['510', 'asset', 0, 0], ['1500', 'expense', 250, 1234]], {'rows': [['1010', 0, 100], ['1500', 0, 984]], 'totals': [0, 1084], 'balanced': False, 'abnormal': ['1010', '1500']}]], [['regression: abnormal balance flag', [['6', 'expense', 0, 0], ['30', 'asset', 250, 249], ['7200', 'expense', 5000, 5000], ['150', 'expense', 100, 100], ['2100', 'dividend', 900, 901], ['205', 'equity', 100, 101]], {'rows': [['30', 1, 0], ['205', 0, 1], ['2100', 0, 1]], 'totals': [1, 2], 'balanced': False, 'abnormal': ['2100']}], ['regression: abnormal balance flag, partial-repair probe', [['150', 'liability', 5000, 250], ['2100', 'dividend', 1234, 250], ['4000', 'asset', 250, 1234], ['99', 'equity', 900, 100], ['101', 'equity', 1234, 1233]], {'rows': [['99', 800, 0], ['101', 1, 0], ['150', 4750, 0], ['2100', 984, 0], ['4000', 0, 984]], 'totals': [6535, 984], 'balanced': False, 'abnormal': ['99', '101', '150', '4000']}], ['control 1', [['510', 'expense', 900, 5000], ['6', 'dividend', 0, 0], ['150', 'expense', 1234, 1234]], {'rows': [['510', 0, 4100]], 'totals': [0, 4100], 'balanced': False, 'abnormal': ['510']}], ['control 2', [['150', 'asset', 5000, 0], ['30', 'expense', 100, 100], ['1010', 'expense', 900, 900], ['99', 'dividend', 1234, 1233], ['4000', 'asset', 1234, 1235]], {'rows': [['99', 1, 0], ['150', 5000, 0], ['4000', 0, 1]], 'totals': [5001, 1], 'balanced': False, 'abnormal': ['4000']}], ['control 3', [['99', 'asset', 100, 250], ['4000', 'dividend', 100, 0], ['6', 'dividend', 1234, 0]], {'rows': [['6', 1234, 0], ['99', 0, 150], ['4000', 100, 0]], 'totals': [1334, 150], 'balanced': False, 'abnormal': ['99']}], ['control 4', [['7200', 'asset', 5000, 4999], ['205', 'asset', 1234, 5000], ['1500', 'dividend', 0, 0]], {'rows': [['205', 0, 3766], ['7200', 1, 0]], 'totals': [1, 3766], 'balanced': False, 'abnormal': ['205']}], ['control 5', [['1010', 'asset', 250, 0], ['510', 'expense', 5000, 1234], ['7200', 'dividend', 100, 100]], {'rows': [['510', 3766, 0], ['1010', 250, 0]], 'totals': [4016, 0], 'balanced': False, 'abnormal': []}]], [['regression: abnormal balance flag', [['2100', 'expense', 100, 5000], ['7200', 'liability', 5000, 100], ['6', 'dividend', 250, 1234], ['99', 'dividend', 0, 1234], ['205', 'expense', 5000, 5001], ['101', 'equity', 0, 1234], ['4000', 'revenue', 250, 5000]], {'rows': [['6', 0, 984], ['99', 0, 1234], ['101', 0, 1234], ['205', 0, 1], ['2100', 0, 4900], ['4000', 0, 4750], ['7200', 4900, 0]], 'totals': [4900, 13103], 'balanced': False, 'abnormal': ['6', '99', '205', '2100', '7200']}], ['control 1', [['7200', 'revenue', 250, 250], ['99', 'asset', 1234, 250], ['205', 'asset', 5000, 0]], {'rows': [['99', 984, 0], ['205', 5000, 0]], 'totals': [5984, 0], 'balanced': False, 'abnormal': []}], ['control 2', [['150', 'asset', 5000, 900], ['205', 'expense', 0, 1234], ['7200', 'asset', 0, 5000]], {'rows': [['150', 4100, 0], ['205', 0, 1234], ['7200', 0, 5000]], 'totals': [4100, 6234], 'balanced': False, 'abnormal': ['205', '7200']}], ['control 3', [['2100', 'dividend', 1234, 0], ['99', 'revenue', 5000, 5000], ['205', 'dividend', 5000, 5001]], {'rows': [['205', 0, 1], ['2100', 1234, 0]], 'totals': [1234, 1], 'balanced': False, 'abnormal': ['205']}], ['control 4', [['6', 'dividend', 0, 5000], ['1500', 'asset', 100, 100], ['30', 'expense', 900, 250], ['510', 'expense', 1234, 0], ['101', 'asset', 5000, 5001], ['4000', 'asset', 0, 5000]], {'rows': [['6', 0, 5000], ['30', 650, 0], ['101', 0, 1], ['510', 1234, 0], ['4000', 0, 5000]], 'totals': [1884, 10001], 'balanced': False, 'abnormal': ['6', '101', '4000']}], ['control 5', [['4000', 'equity', 250, 250], ['1010', 'expense', 1234, 1233], ['30', 'dividend', 100, 100], ['510', 'asset', 250, 0], ['7200', 'liability', 0, 0]], {'rows': [['510', 250, 0], ['1010', 1, 0]], 'totals': [251, 0], 'balanced': False, 'abnormal': []}], ['control 6', [['1500', 'expense', 5000, 100], ['205', 'dividend', 900, 5000], ['2100', 'revenue', 0, 0], ['1010', 'expense', 0, 900]], {'rows': [['205', 0, 4100], ['1010', 0, 900], ['1500', 4900, 0]], 'totals': [4900, 5000], 'balanced': False, 'abnormal': ['205', '1010']}]], [['regression: abnormal balance flag', [['99', 'liability', 1234, 1233], ['30', 'dividend', 5000, 900], ['150', 'liability', 1234, 1234], ['1010', 'liability', 250, 1234], ['510', 'liability', 100, 0], ['4000', 'expense', 100, 100]], {'rows': [['30', 4100, 0], ['99', 1, 0], ['510', 100, 0], ['1010', 0, 984]], 'totals': [4201, 984], 'balanced': False, 'abnormal': ['99', '510']}], ['control 1', [['30', 'asset', 5000, 0], ['510', 'expense', 100, 100], ['6', 'dividend', 100, 900]], {'rows': [['6', 0, 800], ['30', 5000, 0]], 'totals': [5000, 800], 'balanced': False, 'abnormal': ['6']}], ['control 2', [['99', 'expense', 900, 100], ['4000', 'dividend', 5000, 0], ['2100', 'expense', 250, 250], ['510', 'expense', 900, 5000], ['6', 'expense', 5000, 250], ['1500', 'liability', 0, 0]], {'rows': [['6', 4750, 0], ['99', 800, 0], ['510', 0, 4100], ['4000', 5000, 0]], 'totals': [10550, 4100], 'balanced': False, 'abnormal': ['510']}], ['control 3', [['6', 'asset', 5000, 900], ['30', 'asset', 100, 0], ['1500', 'liability', 100, 100]], {'rows': [['6', 4100, 0], ['30', 100, 0]], 'totals': [4200, 0], 'balanced': False, 'abnormal': []}], ['control 4', [['2100', 'expense', 0, 100], ['1010', 'expense', 100, 99], ['101', 'expense', 900, 5000], ['7200', 'dividend', 1234, 900], ['205', 'liability', 0, 0], ['4000', 'revenue', 900, 900]], {'rows': [['101', 0, 4100], ['1010', 1, 0], ['2100', 0, 100], ['7200', 334, 0]], 'totals': [335, 4200], 'balanced': False, 'abnormal': ['101', '2100']}], ['control 5', [['150', 'dividend', 100, 0], ['6', 'dividend', 900, 0], ['1500', 'revenue', 1234, 1234], ['30', 'equity', 100, 100]], {'rows': [['6', 900, 0], ['150', 100, 0]], 'totals': [1000, 0], 'balanced': False, 'abnormal': []}], ['control 6', [['101', 'dividend', 5000, 4999], ['99', 'asset', 100, 100], ['30', 'expense', 250, 249]], {'rows': [['30', 1, 0], ['101', 1, 0]], 'totals': [2, 0], 'balanced': False, 'abnormal': []}]], [['regression: abnormal balance flag', [['4000', 'revenue', 0, 1], ['30', 'expense', 250, 250], ['2100', 'asset', 900, 100]], {'rows': [['2100', 800, 0], ['4000', 0, 1]], 'totals': [800, 1], 'balanced': False, 'abnormal': []}], ['regression: abnormal balance flag, partial-repair probe', [['99', 'liability', 5000, 0], ['30', 'liability', 0, 0], ['4000', 'expense', 0, 900], ['205', 'revenue', 900, 5000], ['1010', 'liability', 0, 250]], {'rows': [['99', 5000, 0], ['205', 0, 4100], ['1010', 0, 250], ['4000', 0, 900]], 'totals': [5000, 5250], 'balanced': False, 'abnormal': ['99', '4000']}], ['control 1', [['510', 'asset', 0, 1234], ['1500', 'asset', 1234, 1233], ['99', 'expense', 0, 1], ['101', 'asset', 900, 900], ['30', 'expense', 1234, 1234]], {'rows': [['99', 0, 1], ['510', 0, 1234], ['1500', 1, 0]], 'totals': [1, 1235], 'balanced': False, 'abnormal': ['99', '510']}], ['control 2', [['30', 'asset', 100, 0], ['205', 'dividend', 250, 249], ['6', 'asset', 250, 900], ['150', 'expense', 0, 1234]], {'rows': [['6', 0, 650], ['30', 100, 0], ['150', 0, 1234], ['205', 1, 0]], 'totals': [101, 1884], 'balanced': False, 'abnormal': ['6', '150']}], ['control 3', [['7200', 'expense', 250, 251], ['150', 'expense', 5000, 1234], ['30', 'asset', 100, 99]], {'rows': [['30', 1, 0], ['150', 3766, 0], ['7200', 0, 1]], 'totals': [3767, 1], 'balanced': False, 'abnormal': ['7200']}], ['control 4', [['1500', 'asset', 0, 5000], ['1010', 'equity', 5000, 5000], ['99', 'asset', 250, 249]], {'rows': [['99', 1, 0], ['1500', 0, 5000]], 'totals': [1, 5000], 'balanced': False, 'abnormal': ['1500']}], ['control 5', [['150', 'expense', 100, 0], ['101', 'liability', 250, 250], ['99', 'liability', 100, 100], ['205', 'equity', 100, 100], ['510', 'expense', 100, 0], ['7200', 'asset', 5000, 5000]], {'rows': [['150', 100, 0], ['510', 100, 0]], 'totals': [200, 0], 'balanced': False, 'abnormal': []}]]]
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:
Every liability and revenue account is flagged as abnormal.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


prompt:
The credit total exceeds the credit column whenever a credit account also has debits.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


prompt:
Account 1010 is listed before account 150.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


prompt:
A trial balance off by one cent is reported as balanced.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access


prompt:
The abnormal-balance list follows input order instead of chart order.

x = [[account_code (digit string), type, total_debits, total_credits], ...]. Net = debits - credits. Zero-net accounts are omitted. A positive net goes in the debit column, a negative net (as a positive number) in the credit column. Rows are ordered by numeric account code. An account is abnormal when its column differs from its normal side (asset, expense, dividend debit-normal; others credit-normal). Return {'rows': [[code, debit, credit]], 'totals': [debits, credits], 'balanced': totals equal exactly, 'abnormal': codes in numeric order}.

split: open-access