FA-60101 / Inventory cost layering / Open access
Standard cost material variances: usage variance pricing · case 01
The usage variance fluctuates with purchase prices even when consumption is unchanged.
ROOT CAUSE
Excess usage is priced at average actual purchase price instead of standard price.
VERIFIED REPAIR
Price the quantity difference at standard price.
Unsuccessful approach: Pricing at the last purchase price is still an actual price.
Case contract
Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.
Why this case matters
Inventory valuation and cost-of-goods decisions depend on this rule.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
allowed = x['std_qty'] * x['good_units']
usage = (x['used'] - allowed) * (sum(tc for q, tc in x['purchases']) // max(1, sum(q for q, tc in x['purchases'])) or x['std_price'])
lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), 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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unfavorable price | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 630, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Failed |
| favorable usage | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -280, 'usage_label': 'F'} | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F'} | Failed |
| two purchases | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 660, 'usage_label': 'U'} | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Failed |
| exact standard | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| scrap heavy | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 795, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U'} | Failed |
| no purchases | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| mixed signs | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -112, 'usage_label': 'F'} | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F'} | Failed |
SHA-256 / 660b14b5c3d0e052c7da14e62ed370834cc9a203cfcd6c21c35caad791fbc93e
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
allowed = x['std_qty'] * x['good_units']
usage = (x['used'] - allowed) * (x['purchases'][-1][1] // x['purchases'][-1][0] if x['purchases'] else x['std_price'])
lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), 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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unfavorable price | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 630, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Failed |
| favorable usage | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -280, 'usage_label': 'F'} | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F'} | Failed |
| two purchases | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 780, 'usage_label': 'U'} | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Failed |
| exact standard | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| scrap heavy | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U'} | Failed |
| no purchases | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| mixed signs | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -140, 'usage_label': 'F'} | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F'} | Failed |
SHA-256 / 32362a242478288d802bdb740f63334053c16adb59056782356edb8eab454d99
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
allowed = x['std_qty'] * x['good_units']
usage = (x['used'] - allowed) * x['std_price']
lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), 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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unfavorable price | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Passed |
| favorable usage | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F'} | {'allowed': 42, 'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F'} | Passed |
| two purchases | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | {'allowed': 20, 'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U'} | Passed |
| exact standard | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 8, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| scrap heavy | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U'} | {'allowed': 30, 'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U'} | Passed |
| no purchases | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | {'allowed': 6, 'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-'} | Passed |
| mixed signs | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F'} | {'allowed': 12, 'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F'} | Passed |
SHA-256 / 8a558d1f9f927d39bf72a22098f39712a55ef4d0ea493447667cfd650e59d78f
Verification & scope
Stipulated bounded teaching model with explicit toy rules; not an accounting-standard implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:42.461523+00:00.
Case digest / 7e423476c60c25058e0dcc74879fa3ab41dcad7a9ca6dfb3e78fd0810b917d78