FA-97211 / Recipe scaling and nutrition / Open access
Recipe cost per serving: whole pack count · case 01
Needing 1.3 packs buys one pack.
ROOT CAUSE
Pack counts are rounded to nearest instead of up.
VERIFIED REPAIR
Buy the ceiling of packs needed.
Unsuccessful approach: int()+1 buys an extra pack when the need is an exact multiple.
Case contract
Rows [name, ep_qty, pack_price_cents, pack_size, yield_pct, mode]. Edible portion needs as-purchased ap = ep/(yield/100). mode "whole" buys ceil(ap/pack_size) packs at full price; "bulk" pays ap/pack_size*price. total_cents = half-up integer of the exact total; per_serving_cents = ceiling of exact total/servings; packs lists whole-pack counts by name.
Why this case matters
Menu costing converts trimmed edible quantities to purchase quantities and rounds purchases to packs.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, servings):
total = Fraction(0)
packs = {}
for name, ep, price, size, y, mode in items:
ap = Fraction(ep) / Fraction(y, 100)
if mode == 'whole':
n = math.floor(ap / size + Fraction(1, 2))
packs[name] = n
total += n * price
else:
total += ap / size * price
return {'total_cents': math.floor(total + Fraction(1, 2)), 'per_serving_cents': math.ceil(total / servings),
'packs': packs}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 3, 249, 6, 50, 'bulk'], ['cream', 100, 249, 500, 50, 'whole'],
['herbs', 900, 1200, 250, 90, 'bulk'], ['lemon', 6, 99, 250, 90, 'whole']],
1],
{'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397}],
['repair check: whole pack count',
[[['lemon', 400, 99, 500, 80, 'whole'], ['beef', 250, 450, 1000, 85, 'bulk']], 1],
{'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231}],
['generated control 1',
[[['lemon', 6, 450, 12, 90, 'whole'], ['eggs', 3, 99, 6, 80, 'bulk'], ['cream', 3, 1200, 12, 75, 'bulk']],
7],
{'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912}],
['generated control 2', [[['beef', 300, 99, 250, 100, 'whole'], ['herbs', 400, 249, 500, 90, 'whole']], 8],
{'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447}],
['generated control 3', [[['onion', 400, 249, 100, 100, 'bulk'], ['lemon', 300, 1200, 6, 80, 'whole']], 5],
{'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['onion', 300, 1200, 1000, 100, 'whole'], ['eggs', 100, 1200, 100, 50, 'whole']], 6],
{'packs': {'eggs': 2, 'onion': 1}, 'per_serving_cents': 600, 'total_cents': 3600}],
['repair check: whole pack count',
[[['herbs', 900, 249, 6, 85, 'bulk'], ['beef', 50, 1200, 12, 85, 'whole'],
['onion', 300, 450, 1000, 90, 'bulk'], ['lemon', 300, 1200, 6, 100, 'whole']],
6],
{'packs': {'beef': 5, 'lemon': 50}, 'per_serving_cents': 18349, 'total_cents': 110091}],
['generated control 1',
[[['herbs', 6, 450, 12, 80, 'bulk'], ['onion', 100, 249, 12, 75, 'whole'],
['lemon', 3, 450, 1000, 85, 'bulk']],
6],
{'packs': {'onion': 12}, 'per_serving_cents': 546, 'total_cents': 3271}],
['generated control 2', [[['eggs', 250, 450, 12, 50, 'bulk'], ['cream', 900, 249, 12, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 7016, 'total_cents': 42094}],
['generated control 3', [[['eggs', 100, 99, 500, 100, 'whole'], ['onion', 100, 1200, 100, 50, 'bulk']], 4],
{'packs': {'eggs': 1}, 'per_serving_cents': 625, 'total_cents': 2499}]],
[['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['regression: whole pack count',
[[['herbs', 6, 1200, 250, 80, 'whole'], ['beef', 100, 1200, 1000, 85, 'bulk'],
['cream', 6, 450, 100, 50, 'whole']],
2],
{'packs': {'cream': 1, 'herbs': 1}, 'per_serving_cents': 896, 'total_cents': 1791}],
['repair check: whole pack count',
[[['cream', 900, 249, 12, 100, 'whole'], ['lemon', 50, 99, 1000, 85, 'bulk'],
['herbs', 250, 450, 500, 90, 'whole']],
7],
{'packs': {'cream': 75, 'herbs': 1}, 'per_serving_cents': 2733, 'total_cents': 19131}],
['generated control 1',
[[['eggs', 900, 450, 500, 85, 'whole'], ['herbs', 900, 249, 100, 85, 'bulk'],
['onion', 250, 1200, 250, 85, 'bulk'], ['beef', 6, 450, 12, 100, 'whole']],
7],
{'packs': {'beef': 1, 'eggs': 3}, 'per_serving_cents': 836, 'total_cents': 5848}],
['generated control 2',
[[['beef', 250, 1200, 12, 90, 'bulk'], ['eggs', 400, 450, 500, 50, 'whole'],
['cream', 6, 249, 6, 90, 'bulk']],
8],
{'packs': {'eggs': 2}, 'per_serving_cents': 3620, 'total_cents': 28954}],
['generated control 3', [[['onion', 900, 99, 100, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 186, 'total_cents': 1114}]],
[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 100, 1200, 500, 80, 'whole'], ['herbs', 400, 99, 100, 75, 'whole'],
['lemon', 3, 99, 12, 100, 'bulk']],
1],
{'packs': {'beef': 1, 'herbs': 6}, 'per_serving_cents': 1819, 'total_cents': 1819}],
['repair check: whole pack count',
[[['lemon', 250, 99, 6, 50, 'whole'], ['cream', 300, 99, 1000, 50, 'bulk'],
['beef', 250, 249, 100, 50, 'whole'], ['herbs', 6, 450, 100, 75, 'whole']],
4],
{'packs': {'beef': 5, 'herbs': 1, 'lemon': 84}, 'per_serving_cents': 2518, 'total_cents': 10070}],
['generated control 1', [[['lemon', 250, 1200, 12, 75, 'bulk'], ['cream', 400, 450, 100, 90, 'bulk']], 7],
{'packs': {}, 'per_serving_cents': 5048, 'total_cents': 35333}],
['generated control 2', [[['herbs', 3, 1200, 100, 80, 'bulk'], ['eggs', 250, 249, 500, 50, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 98, 'total_cents': 294}],
['generated control 3',
[[['herbs', 6, 450, 12, 50, 'bulk'], ['lemon', 6, 450, 100, 50, 'bulk'],
['eggs', 100, 99, 500, 100, 'bulk']],
5],
{'packs': {}, 'per_serving_cents': 105, 'total_cents': 524}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['cream', 50, 99, 1000, 100, 'whole'], ['eggs', 400, 249, 6, 100, 'whole'],
['onion', 100, 450, 6, 85, 'bulk']],
1],
{'packs': {'cream': 1, 'eggs': 67}, 'per_serving_cents': 25606, 'total_cents': 25606}],
['repair check: whole pack count',
[[['cream', 250, 450, 500, 90, 'whole'], ['eggs', 3, 450, 500, 50, 'whole'],
['onion', 50, 99, 100, 50, 'whole']],
3],
{'packs': {'cream': 1, 'eggs': 1, 'onion': 1}, 'per_serving_cents': 333, 'total_cents': 999}],
['generated control 1', [[['herbs', 300, 249, 100, 90, 'bulk']], 8],
{'packs': {}, 'per_serving_cents': 104, 'total_cents': 830}],
['generated control 2', [[['onion', 6, 99, 12, 75, 'bulk'], ['cream', 6, 450, 1000, 75, 'bulk']], 2],
{'packs': {}, 'per_serving_cents': 35, 'total_cents': 70}],
['generated control 3',
[[['lemon', 400, 1200, 250, 80, 'bulk'], ['onion', 50, 99, 500, 50, 'bulk'],
['beef', 900, 249, 250, 90, 'bulk']],
2],
{'packs': {}, 'per_serving_cents': 1708, 'total_cents': 3416}]]]
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 |
|---|---|---|---|
| exact whole pack | {'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200} | {'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200} | Passed |
| trim loss | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | Passed |
| bulk herbs | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | Passed |
| regression: whole pack count | {'packs': {'cream': 0, 'lemon': 0}, 'per_serving_cents': 5049, 'total_cents': 5049} | {'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397} | Failed |
| repair check: whole pack count | {'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231} | {'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231} | Passed |
| generated control 1 | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | Passed |
| generated control 2 | {'packs': {'beef': 1, 'herbs': 1}, 'per_serving_cents': 44, 'total_cents': 348} | {'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447} | Failed |
| generated control 3 | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | Passed |
SHA-256 / 696abcf5be3a4752f0324ea6939c61e329764647064bc20a7b5dea068b3d4108
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, servings):
total = Fraction(0)
packs = {}
for name, ep, price, size, y, mode in items:
ap = Fraction(ep) / Fraction(y, 100)
if mode == 'whole':
n = int(ap / size) + 1
packs[name] = n
total += n * price
else:
total += ap / size * price
return {'total_cents': math.floor(total + Fraction(1, 2)), 'per_serving_cents': math.ceil(total / servings),
'packs': packs}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 3, 249, 6, 50, 'bulk'], ['cream', 100, 249, 500, 50, 'whole'],
['herbs', 900, 1200, 250, 90, 'bulk'], ['lemon', 6, 99, 250, 90, 'whole']],
1],
{'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397}],
['repair check: whole pack count',
[[['lemon', 400, 99, 500, 80, 'whole'], ['beef', 250, 450, 1000, 85, 'bulk']], 1],
{'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231}],
['generated control 1',
[[['lemon', 6, 450, 12, 90, 'whole'], ['eggs', 3, 99, 6, 80, 'bulk'], ['cream', 3, 1200, 12, 75, 'bulk']],
7],
{'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912}],
['generated control 2', [[['beef', 300, 99, 250, 100, 'whole'], ['herbs', 400, 249, 500, 90, 'whole']], 8],
{'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447}],
['generated control 3', [[['onion', 400, 249, 100, 100, 'bulk'], ['lemon', 300, 1200, 6, 80, 'whole']], 5],
{'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['onion', 300, 1200, 1000, 100, 'whole'], ['eggs', 100, 1200, 100, 50, 'whole']], 6],
{'packs': {'eggs': 2, 'onion': 1}, 'per_serving_cents': 600, 'total_cents': 3600}],
['repair check: whole pack count',
[[['herbs', 900, 249, 6, 85, 'bulk'], ['beef', 50, 1200, 12, 85, 'whole'],
['onion', 300, 450, 1000, 90, 'bulk'], ['lemon', 300, 1200, 6, 100, 'whole']],
6],
{'packs': {'beef': 5, 'lemon': 50}, 'per_serving_cents': 18349, 'total_cents': 110091}],
['generated control 1',
[[['herbs', 6, 450, 12, 80, 'bulk'], ['onion', 100, 249, 12, 75, 'whole'],
['lemon', 3, 450, 1000, 85, 'bulk']],
6],
{'packs': {'onion': 12}, 'per_serving_cents': 546, 'total_cents': 3271}],
['generated control 2', [[['eggs', 250, 450, 12, 50, 'bulk'], ['cream', 900, 249, 12, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 7016, 'total_cents': 42094}],
['generated control 3', [[['eggs', 100, 99, 500, 100, 'whole'], ['onion', 100, 1200, 100, 50, 'bulk']], 4],
{'packs': {'eggs': 1}, 'per_serving_cents': 625, 'total_cents': 2499}]],
[['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['regression: whole pack count',
[[['herbs', 6, 1200, 250, 80, 'whole'], ['beef', 100, 1200, 1000, 85, 'bulk'],
['cream', 6, 450, 100, 50, 'whole']],
2],
{'packs': {'cream': 1, 'herbs': 1}, 'per_serving_cents': 896, 'total_cents': 1791}],
['repair check: whole pack count',
[[['cream', 900, 249, 12, 100, 'whole'], ['lemon', 50, 99, 1000, 85, 'bulk'],
['herbs', 250, 450, 500, 90, 'whole']],
7],
{'packs': {'cream': 75, 'herbs': 1}, 'per_serving_cents': 2733, 'total_cents': 19131}],
['generated control 1',
[[['eggs', 900, 450, 500, 85, 'whole'], ['herbs', 900, 249, 100, 85, 'bulk'],
['onion', 250, 1200, 250, 85, 'bulk'], ['beef', 6, 450, 12, 100, 'whole']],
7],
{'packs': {'beef': 1, 'eggs': 3}, 'per_serving_cents': 836, 'total_cents': 5848}],
['generated control 2',
[[['beef', 250, 1200, 12, 90, 'bulk'], ['eggs', 400, 450, 500, 50, 'whole'],
['cream', 6, 249, 6, 90, 'bulk']],
8],
{'packs': {'eggs': 2}, 'per_serving_cents': 3620, 'total_cents': 28954}],
['generated control 3', [[['onion', 900, 99, 100, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 186, 'total_cents': 1114}]],
[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 100, 1200, 500, 80, 'whole'], ['herbs', 400, 99, 100, 75, 'whole'],
['lemon', 3, 99, 12, 100, 'bulk']],
1],
{'packs': {'beef': 1, 'herbs': 6}, 'per_serving_cents': 1819, 'total_cents': 1819}],
['repair check: whole pack count',
[[['lemon', 250, 99, 6, 50, 'whole'], ['cream', 300, 99, 1000, 50, 'bulk'],
['beef', 250, 249, 100, 50, 'whole'], ['herbs', 6, 450, 100, 75, 'whole']],
4],
{'packs': {'beef': 5, 'herbs': 1, 'lemon': 84}, 'per_serving_cents': 2518, 'total_cents': 10070}],
['generated control 1', [[['lemon', 250, 1200, 12, 75, 'bulk'], ['cream', 400, 450, 100, 90, 'bulk']], 7],
{'packs': {}, 'per_serving_cents': 5048, 'total_cents': 35333}],
['generated control 2', [[['herbs', 3, 1200, 100, 80, 'bulk'], ['eggs', 250, 249, 500, 50, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 98, 'total_cents': 294}],
['generated control 3',
[[['herbs', 6, 450, 12, 50, 'bulk'], ['lemon', 6, 450, 100, 50, 'bulk'],
['eggs', 100, 99, 500, 100, 'bulk']],
5],
{'packs': {}, 'per_serving_cents': 105, 'total_cents': 524}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['cream', 50, 99, 1000, 100, 'whole'], ['eggs', 400, 249, 6, 100, 'whole'],
['onion', 100, 450, 6, 85, 'bulk']],
1],
{'packs': {'cream': 1, 'eggs': 67}, 'per_serving_cents': 25606, 'total_cents': 25606}],
['repair check: whole pack count',
[[['cream', 250, 450, 500, 90, 'whole'], ['eggs', 3, 450, 500, 50, 'whole'],
['onion', 50, 99, 100, 50, 'whole']],
3],
{'packs': {'cream': 1, 'eggs': 1, 'onion': 1}, 'per_serving_cents': 333, 'total_cents': 999}],
['generated control 1', [[['herbs', 300, 249, 100, 90, 'bulk']], 8],
{'packs': {}, 'per_serving_cents': 104, 'total_cents': 830}],
['generated control 2', [[['onion', 6, 99, 12, 75, 'bulk'], ['cream', 6, 450, 1000, 75, 'bulk']], 2],
{'packs': {}, 'per_serving_cents': 35, 'total_cents': 70}],
['generated control 3',
[[['lemon', 400, 1200, 250, 80, 'bulk'], ['onion', 50, 99, 500, 50, 'bulk'],
['beef', 900, 249, 250, 90, 'bulk']],
2],
{'packs': {}, 'per_serving_cents': 1708, 'total_cents': 3416}]]]
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 |
|---|---|---|---|
| exact whole pack | {'packs': {'beef': 2}, 'per_serving_cents': 600, 'total_cents': 2400} | {'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200} | Failed |
| trim loss | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | Passed |
| bulk herbs | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | Passed |
| regression: whole pack count | {'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397} | {'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397} | Passed |
| repair check: whole pack count | {'packs': {'lemon': 2}, 'per_serving_cents': 331, 'total_cents': 330} | {'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231} | Failed |
| generated control 1 | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | Passed |
| generated control 2 | {'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447} | {'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447} | Passed |
| generated control 3 | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | Passed |
SHA-256 / 6d45f51cac4176900e5239e6195aa6ffbc86711235b8cc4a9c391e415547ad1e
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, servings):
total = Fraction(0)
packs = {}
for name, ep, price, size, y, mode in items:
ap = Fraction(ep) / Fraction(y, 100)
if mode == 'whole':
n = math.ceil(ap / size)
packs[name] = n
total += n * price
else:
total += ap / size * price
return {'total_cents': math.floor(total + Fraction(1, 2)), 'per_serving_cents': math.ceil(total / servings),
'packs': packs}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 3, 249, 6, 50, 'bulk'], ['cream', 100, 249, 500, 50, 'whole'],
['herbs', 900, 1200, 250, 90, 'bulk'], ['lemon', 6, 99, 250, 90, 'whole']],
1],
{'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397}],
['repair check: whole pack count',
[[['lemon', 400, 99, 500, 80, 'whole'], ['beef', 250, 450, 1000, 85, 'bulk']], 1],
{'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231}],
['generated control 1',
[[['lemon', 6, 450, 12, 90, 'whole'], ['eggs', 3, 99, 6, 80, 'bulk'], ['cream', 3, 1200, 12, 75, 'bulk']],
7],
{'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912}],
['generated control 2', [[['beef', 300, 99, 250, 100, 'whole'], ['herbs', 400, 249, 500, 90, 'whole']], 8],
{'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447}],
['generated control 3', [[['onion', 400, 249, 100, 100, 'bulk'], ['lemon', 300, 1200, 6, 80, 'whole']], 5],
{'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['onion', 300, 1200, 1000, 100, 'whole'], ['eggs', 100, 1200, 100, 50, 'whole']], 6],
{'packs': {'eggs': 2, 'onion': 1}, 'per_serving_cents': 600, 'total_cents': 3600}],
['repair check: whole pack count',
[[['herbs', 900, 249, 6, 85, 'bulk'], ['beef', 50, 1200, 12, 85, 'whole'],
['onion', 300, 450, 1000, 90, 'bulk'], ['lemon', 300, 1200, 6, 100, 'whole']],
6],
{'packs': {'beef': 5, 'lemon': 50}, 'per_serving_cents': 18349, 'total_cents': 110091}],
['generated control 1',
[[['herbs', 6, 450, 12, 80, 'bulk'], ['onion', 100, 249, 12, 75, 'whole'],
['lemon', 3, 450, 1000, 85, 'bulk']],
6],
{'packs': {'onion': 12}, 'per_serving_cents': 546, 'total_cents': 3271}],
['generated control 2', [[['eggs', 250, 450, 12, 50, 'bulk'], ['cream', 900, 249, 12, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 7016, 'total_cents': 42094}],
['generated control 3', [[['eggs', 100, 99, 500, 100, 'whole'], ['onion', 100, 1200, 100, 50, 'bulk']], 4],
{'packs': {'eggs': 1}, 'per_serving_cents': 625, 'total_cents': 2499}]],
[['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['regression: whole pack count',
[[['herbs', 6, 1200, 250, 80, 'whole'], ['beef', 100, 1200, 1000, 85, 'bulk'],
['cream', 6, 450, 100, 50, 'whole']],
2],
{'packs': {'cream': 1, 'herbs': 1}, 'per_serving_cents': 896, 'total_cents': 1791}],
['repair check: whole pack count',
[[['cream', 900, 249, 12, 100, 'whole'], ['lemon', 50, 99, 1000, 85, 'bulk'],
['herbs', 250, 450, 500, 90, 'whole']],
7],
{'packs': {'cream': 75, 'herbs': 1}, 'per_serving_cents': 2733, 'total_cents': 19131}],
['generated control 1',
[[['eggs', 900, 450, 500, 85, 'whole'], ['herbs', 900, 249, 100, 85, 'bulk'],
['onion', 250, 1200, 250, 85, 'bulk'], ['beef', 6, 450, 12, 100, 'whole']],
7],
{'packs': {'beef': 1, 'eggs': 3}, 'per_serving_cents': 836, 'total_cents': 5848}],
['generated control 2',
[[['beef', 250, 1200, 12, 90, 'bulk'], ['eggs', 400, 450, 500, 50, 'whole'],
['cream', 6, 249, 6, 90, 'bulk']],
8],
{'packs': {'eggs': 2}, 'per_serving_cents': 3620, 'total_cents': 28954}],
['generated control 3', [[['onion', 900, 99, 100, 80, 'bulk']], 6],
{'packs': {}, 'per_serving_cents': 186, 'total_cents': 1114}]],
[['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['regression: whole pack count',
[[['beef', 100, 1200, 500, 80, 'whole'], ['herbs', 400, 99, 100, 75, 'whole'],
['lemon', 3, 99, 12, 100, 'bulk']],
1],
{'packs': {'beef': 1, 'herbs': 6}, 'per_serving_cents': 1819, 'total_cents': 1819}],
['repair check: whole pack count',
[[['lemon', 250, 99, 6, 50, 'whole'], ['cream', 300, 99, 1000, 50, 'bulk'],
['beef', 250, 249, 100, 50, 'whole'], ['herbs', 6, 450, 100, 75, 'whole']],
4],
{'packs': {'beef': 5, 'herbs': 1, 'lemon': 84}, 'per_serving_cents': 2518, 'total_cents': 10070}],
['generated control 1', [[['lemon', 250, 1200, 12, 75, 'bulk'], ['cream', 400, 450, 100, 90, 'bulk']], 7],
{'packs': {}, 'per_serving_cents': 5048, 'total_cents': 35333}],
['generated control 2', [[['herbs', 3, 1200, 100, 80, 'bulk'], ['eggs', 250, 249, 500, 50, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 98, 'total_cents': 294}],
['generated control 3',
[[['herbs', 6, 450, 12, 50, 'bulk'], ['lemon', 6, 450, 100, 50, 'bulk'],
['eggs', 100, 99, 500, 100, 'bulk']],
5],
{'packs': {}, 'per_serving_cents': 105, 'total_cents': 524}]],
[['trim loss', [[['onion', 90, 99, 100, 90, 'bulk']], 1],
{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}],
['bulk herbs', [[['herbs', 30, 450, 100, 75, 'bulk']], 3],
{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}],
['exact whole pack', [[['beef', 500, 1200, 500, 100, 'whole']], 4],
{'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200}],
['regression: whole pack count',
[[['cream', 50, 99, 1000, 100, 'whole'], ['eggs', 400, 249, 6, 100, 'whole'],
['onion', 100, 450, 6, 85, 'bulk']],
1],
{'packs': {'cream': 1, 'eggs': 67}, 'per_serving_cents': 25606, 'total_cents': 25606}],
['repair check: whole pack count',
[[['cream', 250, 450, 500, 90, 'whole'], ['eggs', 3, 450, 500, 50, 'whole'],
['onion', 50, 99, 100, 50, 'whole']],
3],
{'packs': {'cream': 1, 'eggs': 1, 'onion': 1}, 'per_serving_cents': 333, 'total_cents': 999}],
['generated control 1', [[['herbs', 300, 249, 100, 90, 'bulk']], 8],
{'packs': {}, 'per_serving_cents': 104, 'total_cents': 830}],
['generated control 2', [[['onion', 6, 99, 12, 75, 'bulk'], ['cream', 6, 450, 1000, 75, 'bulk']], 2],
{'packs': {}, 'per_serving_cents': 35, 'total_cents': 70}],
['generated control 3',
[[['lemon', 400, 1200, 250, 80, 'bulk'], ['onion', 50, 99, 500, 50, 'bulk'],
['beef', 900, 249, 250, 90, 'bulk']],
2],
{'packs': {}, 'per_serving_cents': 1708, 'total_cents': 3416}]]]
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 |
|---|---|---|---|
| exact whole pack | {'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200} | {'packs': {'beef': 1}, 'per_serving_cents': 300, 'total_cents': 1200} | Passed |
| trim loss | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | {'packs': {}, 'per_serving_cents': 99, 'total_cents': 99} | Passed |
| bulk herbs | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | {'packs': {}, 'per_serving_cents': 60, 'total_cents': 180} | Passed |
| regression: whole pack count | {'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397} | {'packs': {'cream': 1, 'lemon': 1}, 'per_serving_cents': 5397, 'total_cents': 5397} | Passed |
| repair check: whole pack count | {'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231} | {'packs': {'lemon': 1}, 'per_serving_cents': 232, 'total_cents': 231} | Passed |
| generated control 1 | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | {'packs': {'lemon': 1}, 'per_serving_cents': 131, 'total_cents': 912} | Passed |
| generated control 2 | {'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447} | {'packs': {'beef': 2, 'herbs': 1}, 'per_serving_cents': 56, 'total_cents': 447} | Passed |
| generated control 3 | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | {'packs': {'lemon': 63}, 'per_serving_cents': 15320, 'total_cents': 76596} | Passed |
SHA-256 / 4549411215776104559ae7850b766df19e54d1006fe1a6f570348626fc1e5668
Verification & scope
A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards 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:52:29.993817+00:00.
Case digest / 8db410d9584ee96bfc8e929db91e5aa774011c81869a727b314aef19d9d9694b