FAILURE MAP
← Case archive

FA-97206 / Recipe scaling and nutrition / Open access

Recipe cost per serving: trim yield direction · case 01

100 g of trimmed onion at 80% yield is costed as 80 g purchased.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The yield percentage multiplies the edible portion instead of dividing it.

VERIFIED REPAIR

Divide edible portion by the yield fraction.

Unsuccessful approach: Adding the trim percentage of the edible weight under-buys: 100 g at 80% needs 125 g, not 120 g.

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.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: trim yield direction',
   [[['eggs', 400, 450, 1000, 80, 'bulk'], ['onion', 6, 450, 100, 80, 'bulk'],
     ['cream', 300, 1200, 1000, 80, 'whole'], ['herbs', 250, 249, 100, 75, 'whole']],
    7],
   {'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}],
  ['repair check: trim yield direction',
   [[['herbs', 6, 450, 250, 50, 'bulk'], ['eggs', 100, 450, 12, 75, 'bulk'],
     ['lemon', 6, 249, 100, 100, 'whole']],
    5],
   {'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}],
  ['generated control 1',
   [[['beef', 100, 450, 1000, 85, 'whole'], ['onion', 100, 450, 100, 80, 'whole'],
     ['eggs', 900, 249, 250, 100, 'whole'], ['herbs', 6, 99, 250, 100, 'bulk']],
    5],
   {'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}],
  ['generated control 2',
   [[['eggs', 900, 450, 1000, 85, 'bulk'], ['onion', 900, 249, 1000, 50, 'whole'],
     ['herbs', 100, 450, 12, 85, 'whole'], ['beef', 250, 99, 12, 75, 'whole']],
    6],
   {'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}],
  ['generated control 3', [[['onion', 400, 450, 1000, 50, 'bulk'], ['cream', 3, 450, 6, 90, 'whole']], 3],
   {'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}]],
 [['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: trim yield direction',
   [[['herbs', 900, 450, 250, 50, 'bulk'], ['beef', 300, 99, 6, 90, 'bulk'],
     ['cream', 300, 1200, 12, 85, 'bulk'], ['eggs', 900, 1200, 6, 75, 'bulk']],
    2],
   {'packs': {}, 'per_serving_cents': 142018, 'total_cents': 284034}],
  ['repair check: trim yield direction',
   [[['eggs', 100, 1200, 12, 75, 'whole'], ['cream', 3, 1200, 250, 80, 'whole'],
     ['beef', 400, 1200, 1000, 50, 'whole']],
    6],
   {'packs': {'beef': 1, 'cream': 1, 'eggs': 12}, 'per_serving_cents': 2800, 'total_cents': 16800}],
  ['generated control 1',
   [[['onion', 3, 249, 250, 90, 'whole'], ['cream', 400, 249, 100, 90, 'bulk'],
     ['beef', 3, 1200, 1000, 50, 'bulk'], ['herbs', 400, 450, 250, 100, 'bulk']],
    7],
   {'packs': {'onion': 1}, 'per_serving_cents': 298, 'total_cents': 2083}],
  ['generated control 2', [[['onion', 100, 99, 500, 75, 'bulk'], ['cream', 6, 450, 500, 85, 'whole']], 6],
   {'packs': {'cream': 1}, 'per_serving_cents': 80, 'total_cents': 476}],
  ['generated control 3', [[['herbs', 6, 1200, 500, 100, 'whole'], ['cream', 900, 450, 250, 75, 'bulk']], 3],
   {'packs': {'herbs': 1}, 'per_serving_cents': 1120, 'total_cents': 3360}]],
 [['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: trim yield direction',
   [[['onion', 6, 450, 1000, 90, 'whole'], ['cream', 50, 249, 1000, 90, 'bulk']], 8],
   {'packs': {'onion': 1}, 'per_serving_cents': 58, 'total_cents': 464}],
  ['repair check: trim yield direction',
   [[['herbs', 50, 450, 500, 90, 'whole'], ['eggs', 900, 450, 1000, 85, 'bulk'],
     ['lemon', 6, 450, 250, 90, 'whole']],
    7],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 197, 'total_cents': 1376}],
  ['generated control 1',
   [[['herbs', 250, 99, 1000, 85, 'whole'], ['lemon', 3, 99, 100, 85, 'whole'],
     ['eggs', 100, 249, 250, 75, 'bulk'], ['beef', 6, 1200, 1000, 100, 'bulk']],
    2],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 169, 'total_cents': 338}],
  ['generated control 2',
   [[['cream', 6, 450, 12, 50, 'whole'], ['onion', 400, 99, 6, 100, 'whole'],
     ['beef', 6, 1200, 12, 50, 'bulk'], ['herbs', 50, 249, 12, 90, 'whole']],
    1],
   {'packs': {'cream': 1, 'herbs': 5, 'onion': 67}, 'per_serving_cents': 9528, 'total_cents': 9528}],
  ['generated control 3', [[['beef', 100, 99, 1000, 75, 'bulk']], 7],
   {'packs': {}, 'per_serving_cents': 2, 'total_cents': 13}]],
 [['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: trim yield direction',
   [[['lemon', 250, 1200, 100, 75, 'bulk'], ['cream', 100, 99, 100, 50, 'bulk'],
     ['herbs', 6, 99, 12, 90, 'bulk']],
    7],
   {'packs': {}, 'per_serving_cents': 608, 'total_cents': 4253}],
  ['repair check: trim yield direction',
   [[['eggs', 3, 99, 100, 75, 'bulk'], ['herbs', 300, 249, 500, 85, 'whole'],
     ['lemon', 100, 99, 6, 75, 'bulk']],
    5],
   {'packs': {'herbs': 1}, 'per_serving_cents': 491, 'total_cents': 2453}],
  ['generated control 1', [[['beef', 50, 1200, 100, 90, 'whole'], ['eggs', 100, 249, 500, 100, 'bulk']], 4],
   {'packs': {'beef': 1}, 'per_serving_cents': 313, 'total_cents': 1250}],
  ['generated control 2', [[['herbs', 250, 99, 6, 75, 'whole']], 6],
   {'packs': {'herbs': 56}, 'per_serving_cents': 924, 'total_cents': 5544}],
  ['generated control 3', [[['herbs', 6, 450, 6, 75, 'whole'], ['cream', 100, 1200, 1000, 100, 'whole']], 1],
   {'packs': {'cream': 1, 'herbs': 2}, 'per_serving_cents': 2100, 'total_cents': 2100}]],
 [['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: trim yield direction',
   [[['herbs', 300, 1200, 500, 50, 'bulk'], ['eggs', 6, 99, 250, 50, 'whole']], 6],
   {'packs': {'eggs': 1}, 'per_serving_cents': 257, 'total_cents': 1539}],
  ['repair check: trim yield direction', [[['cream', 900, 249, 12, 50, 'whole']], 8],
   {'packs': {'cream': 150}, 'per_serving_cents': 4669, 'total_cents': 37350}],
  ['generated control 1', [[['cream', 250, 99, 100, 100, 'bulk']], 2],
   {'packs': {}, 'per_serving_cents': 124, 'total_cents': 248}],
  ['generated control 2',
   [[['beef', 300, 450, 100, 80, 'whole'], ['herbs', 50, 99, 100, 80, 'whole'],
     ['onion', 900, 99, 100, 75, 'whole'], ['lemon', 50, 450, 6, 90, 'bulk']],
    5],
   {'packs': {'beef': 4, 'herbs': 1, 'onion': 12}, 'per_serving_cents': 1451, 'total_cents': 7254}],
  ['generated control 3',
   [[['beef', 900, 249, 12, 75, 'whole'], ['herbs', 3, 249, 6, 90, 'bulk'],
     ['onion', 6, 249, 250, 90, 'whole']],
    3],
   {'packs': {'beef': 100, 'onion': 1}, 'per_serving_cents': 8430, 'total_cents': 25287}]]]
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 fixtureActualExpectedOutcome
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': 81, 'total_cents': 80}{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}Failed
bulk herbs{'packs': {}, 'per_serving_cents': 34, 'total_cents': 101}{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}Failed
regression: trim yield direction{'packs': {'cream': 1, 'herbs': 2}, 'per_serving_cents': 267, 'total_cents': 1864}{'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}Failed
repair check: trim yield direction{'packs': {'lemon': 1}, 'per_serving_cents': 614, 'total_cents': 3067}{'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}Failed
generated control 1{'packs': {'beef': 1, 'eggs': 4, 'onion': 1}, 'per_serving_cents': 380, 'total_cents': 1898}{'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}Failed
generated control 2{'packs': {'beef': 16, 'herbs': 8, 'onion': 1}, 'per_serving_cents': 963, 'total_cents': 5777}{'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}Failed
generated control 3{'packs': {'cream': 1}, 'per_serving_cents': 180, 'total_cents': 540}{'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}Failed

SHA-256 / 72534e242237d51aee2a52d1c0d97d800bad329f3310e27a387a391c15a32a01

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(ep) * Fraction(100 - 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: trim yield direction',
   [[['eggs', 400, 450, 1000, 80, 'bulk'], ['onion', 6, 450, 100, 80, 'bulk'],
     ['cream', 300, 1200, 1000, 80, 'whole'], ['herbs', 250, 249, 100, 75, 'whole']],
    7],
   {'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}],
  ['repair check: trim yield direction',
   [[['herbs', 6, 450, 250, 50, 'bulk'], ['eggs', 100, 450, 12, 75, 'bulk'],
     ['lemon', 6, 249, 100, 100, 'whole']],
    5],
   {'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}],
  ['generated control 1',
   [[['beef', 100, 450, 1000, 85, 'whole'], ['onion', 100, 450, 100, 80, 'whole'],
     ['eggs', 900, 249, 250, 100, 'whole'], ['herbs', 6, 99, 250, 100, 'bulk']],
    5],
   {'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}],
  ['generated control 2',
   [[['eggs', 900, 450, 1000, 85, 'bulk'], ['onion', 900, 249, 1000, 50, 'whole'],
     ['herbs', 100, 450, 12, 85, 'whole'], ['beef', 250, 99, 12, 75, 'whole']],
    6],
   {'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}],
  ['generated control 3', [[['onion', 400, 450, 1000, 50, 'bulk'], ['cream', 3, 450, 6, 90, 'whole']], 3],
   {'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}]],
 [['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: trim yield direction',
   [[['herbs', 900, 450, 250, 50, 'bulk'], ['beef', 300, 99, 6, 90, 'bulk'],
     ['cream', 300, 1200, 12, 85, 'bulk'], ['eggs', 900, 1200, 6, 75, 'bulk']],
    2],
   {'packs': {}, 'per_serving_cents': 142018, 'total_cents': 284034}],
  ['repair check: trim yield direction',
   [[['eggs', 100, 1200, 12, 75, 'whole'], ['cream', 3, 1200, 250, 80, 'whole'],
     ['beef', 400, 1200, 1000, 50, 'whole']],
    6],
   {'packs': {'beef': 1, 'cream': 1, 'eggs': 12}, 'per_serving_cents': 2800, 'total_cents': 16800}],
  ['generated control 1',
   [[['onion', 3, 249, 250, 90, 'whole'], ['cream', 400, 249, 100, 90, 'bulk'],
     ['beef', 3, 1200, 1000, 50, 'bulk'], ['herbs', 400, 450, 250, 100, 'bulk']],
    7],
   {'packs': {'onion': 1}, 'per_serving_cents': 298, 'total_cents': 2083}],
  ['generated control 2', [[['onion', 100, 99, 500, 75, 'bulk'], ['cream', 6, 450, 500, 85, 'whole']], 6],
   {'packs': {'cream': 1}, 'per_serving_cents': 80, 'total_cents': 476}],
  ['generated control 3', [[['herbs', 6, 1200, 500, 100, 'whole'], ['cream', 900, 450, 250, 75, 'bulk']], 3],
   {'packs': {'herbs': 1}, 'per_serving_cents': 1120, 'total_cents': 3360}]],
 [['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: trim yield direction',
   [[['onion', 6, 450, 1000, 90, 'whole'], ['cream', 50, 249, 1000, 90, 'bulk']], 8],
   {'packs': {'onion': 1}, 'per_serving_cents': 58, 'total_cents': 464}],
  ['repair check: trim yield direction',
   [[['herbs', 50, 450, 500, 90, 'whole'], ['eggs', 900, 450, 1000, 85, 'bulk'],
     ['lemon', 6, 450, 250, 90, 'whole']],
    7],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 197, 'total_cents': 1376}],
  ['generated control 1',
   [[['herbs', 250, 99, 1000, 85, 'whole'], ['lemon', 3, 99, 100, 85, 'whole'],
     ['eggs', 100, 249, 250, 75, 'bulk'], ['beef', 6, 1200, 1000, 100, 'bulk']],
    2],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 169, 'total_cents': 338}],
  ['generated control 2',
   [[['cream', 6, 450, 12, 50, 'whole'], ['onion', 400, 99, 6, 100, 'whole'],
     ['beef', 6, 1200, 12, 50, 'bulk'], ['herbs', 50, 249, 12, 90, 'whole']],
    1],
   {'packs': {'cream': 1, 'herbs': 5, 'onion': 67}, 'per_serving_cents': 9528, 'total_cents': 9528}],
  ['generated control 3', [[['beef', 100, 99, 1000, 75, 'bulk']], 7],
   {'packs': {}, 'per_serving_cents': 2, 'total_cents': 13}]],
 [['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: trim yield direction',
   [[['lemon', 250, 1200, 100, 75, 'bulk'], ['cream', 100, 99, 100, 50, 'bulk'],
     ['herbs', 6, 99, 12, 90, 'bulk']],
    7],
   {'packs': {}, 'per_serving_cents': 608, 'total_cents': 4253}],
  ['repair check: trim yield direction',
   [[['eggs', 3, 99, 100, 75, 'bulk'], ['herbs', 300, 249, 500, 85, 'whole'],
     ['lemon', 100, 99, 6, 75, 'bulk']],
    5],
   {'packs': {'herbs': 1}, 'per_serving_cents': 491, 'total_cents': 2453}],
  ['generated control 1', [[['beef', 50, 1200, 100, 90, 'whole'], ['eggs', 100, 249, 500, 100, 'bulk']], 4],
   {'packs': {'beef': 1}, 'per_serving_cents': 313, 'total_cents': 1250}],
  ['generated control 2', [[['herbs', 250, 99, 6, 75, 'whole']], 6],
   {'packs': {'herbs': 56}, 'per_serving_cents': 924, 'total_cents': 5544}],
  ['generated control 3', [[['herbs', 6, 450, 6, 75, 'whole'], ['cream', 100, 1200, 1000, 100, 'whole']], 1],
   {'packs': {'cream': 1, 'herbs': 2}, 'per_serving_cents': 2100, 'total_cents': 2100}]],
 [['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: trim yield direction',
   [[['herbs', 300, 1200, 500, 50, 'bulk'], ['eggs', 6, 99, 250, 50, 'whole']], 6],
   {'packs': {'eggs': 1}, 'per_serving_cents': 257, 'total_cents': 1539}],
  ['repair check: trim yield direction', [[['cream', 900, 249, 12, 50, 'whole']], 8],
   {'packs': {'cream': 150}, 'per_serving_cents': 4669, 'total_cents': 37350}],
  ['generated control 1', [[['cream', 250, 99, 100, 100, 'bulk']], 2],
   {'packs': {}, 'per_serving_cents': 124, 'total_cents': 248}],
  ['generated control 2',
   [[['beef', 300, 450, 100, 80, 'whole'], ['herbs', 50, 99, 100, 80, 'whole'],
     ['onion', 900, 99, 100, 75, 'whole'], ['lemon', 50, 450, 6, 90, 'bulk']],
    5],
   {'packs': {'beef': 4, 'herbs': 1, 'onion': 12}, 'per_serving_cents': 1451, 'total_cents': 7254}],
  ['generated control 3',
   [[['beef', 900, 249, 12, 75, 'whole'], ['herbs', 3, 249, 6, 90, 'bulk'],
     ['onion', 6, 249, 250, 90, 'whole']],
    3],
   {'packs': {'beef': 100, 'onion': 1}, 'per_serving_cents': 8430, 'total_cents': 25287}]]]
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 fixtureActualExpectedOutcome
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': 98}{'packs': {}, 'per_serving_cents': 99, 'total_cents': 99}Failed
bulk herbs{'packs': {}, 'per_serving_cents': 57, 'total_cents': 169}{'packs': {}, 'per_serving_cents': 60, 'total_cents': 180}Failed
regression: trim yield direction{'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 350, 'total_cents': 2444}{'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}Failed
repair check: trim yield direction{'packs': {'lemon': 1}, 'per_serving_cents': 991, 'total_cents': 4953}{'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}Failed
generated control 1{'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}{'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}Passed
generated control 2{'packs': {'beef': 27, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1357, 'total_cents': 8137}{'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}Failed
generated control 3{'packs': {'cream': 1}, 'per_serving_cents': 240, 'total_cents': 720}{'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}Failed

SHA-256 / 39bcaac969876c83fc6d820c237a92ee576f84f3cce01b4ac720a1f49a49f5d8

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: trim yield direction',
   [[['eggs', 400, 450, 1000, 80, 'bulk'], ['onion', 6, 450, 100, 80, 'bulk'],
     ['cream', 300, 1200, 1000, 80, 'whole'], ['herbs', 250, 249, 100, 75, 'whole']],
    7],
   {'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}],
  ['repair check: trim yield direction',
   [[['herbs', 6, 450, 250, 50, 'bulk'], ['eggs', 100, 450, 12, 75, 'bulk'],
     ['lemon', 6, 249, 100, 100, 'whole']],
    5],
   {'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}],
  ['generated control 1',
   [[['beef', 100, 450, 1000, 85, 'whole'], ['onion', 100, 450, 100, 80, 'whole'],
     ['eggs', 900, 249, 250, 100, 'whole'], ['herbs', 6, 99, 250, 100, 'bulk']],
    5],
   {'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}],
  ['generated control 2',
   [[['eggs', 900, 450, 1000, 85, 'bulk'], ['onion', 900, 249, 1000, 50, 'whole'],
     ['herbs', 100, 450, 12, 85, 'whole'], ['beef', 250, 99, 12, 75, 'whole']],
    6],
   {'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}],
  ['generated control 3', [[['onion', 400, 450, 1000, 50, 'bulk'], ['cream', 3, 450, 6, 90, 'whole']], 3],
   {'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}]],
 [['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: trim yield direction',
   [[['herbs', 900, 450, 250, 50, 'bulk'], ['beef', 300, 99, 6, 90, 'bulk'],
     ['cream', 300, 1200, 12, 85, 'bulk'], ['eggs', 900, 1200, 6, 75, 'bulk']],
    2],
   {'packs': {}, 'per_serving_cents': 142018, 'total_cents': 284034}],
  ['repair check: trim yield direction',
   [[['eggs', 100, 1200, 12, 75, 'whole'], ['cream', 3, 1200, 250, 80, 'whole'],
     ['beef', 400, 1200, 1000, 50, 'whole']],
    6],
   {'packs': {'beef': 1, 'cream': 1, 'eggs': 12}, 'per_serving_cents': 2800, 'total_cents': 16800}],
  ['generated control 1',
   [[['onion', 3, 249, 250, 90, 'whole'], ['cream', 400, 249, 100, 90, 'bulk'],
     ['beef', 3, 1200, 1000, 50, 'bulk'], ['herbs', 400, 450, 250, 100, 'bulk']],
    7],
   {'packs': {'onion': 1}, 'per_serving_cents': 298, 'total_cents': 2083}],
  ['generated control 2', [[['onion', 100, 99, 500, 75, 'bulk'], ['cream', 6, 450, 500, 85, 'whole']], 6],
   {'packs': {'cream': 1}, 'per_serving_cents': 80, 'total_cents': 476}],
  ['generated control 3', [[['herbs', 6, 1200, 500, 100, 'whole'], ['cream', 900, 450, 250, 75, 'bulk']], 3],
   {'packs': {'herbs': 1}, 'per_serving_cents': 1120, 'total_cents': 3360}]],
 [['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: trim yield direction',
   [[['onion', 6, 450, 1000, 90, 'whole'], ['cream', 50, 249, 1000, 90, 'bulk']], 8],
   {'packs': {'onion': 1}, 'per_serving_cents': 58, 'total_cents': 464}],
  ['repair check: trim yield direction',
   [[['herbs', 50, 450, 500, 90, 'whole'], ['eggs', 900, 450, 1000, 85, 'bulk'],
     ['lemon', 6, 450, 250, 90, 'whole']],
    7],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 197, 'total_cents': 1376}],
  ['generated control 1',
   [[['herbs', 250, 99, 1000, 85, 'whole'], ['lemon', 3, 99, 100, 85, 'whole'],
     ['eggs', 100, 249, 250, 75, 'bulk'], ['beef', 6, 1200, 1000, 100, 'bulk']],
    2],
   {'packs': {'herbs': 1, 'lemon': 1}, 'per_serving_cents': 169, 'total_cents': 338}],
  ['generated control 2',
   [[['cream', 6, 450, 12, 50, 'whole'], ['onion', 400, 99, 6, 100, 'whole'],
     ['beef', 6, 1200, 12, 50, 'bulk'], ['herbs', 50, 249, 12, 90, 'whole']],
    1],
   {'packs': {'cream': 1, 'herbs': 5, 'onion': 67}, 'per_serving_cents': 9528, 'total_cents': 9528}],
  ['generated control 3', [[['beef', 100, 99, 1000, 75, 'bulk']], 7],
   {'packs': {}, 'per_serving_cents': 2, 'total_cents': 13}]],
 [['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: trim yield direction',
   [[['lemon', 250, 1200, 100, 75, 'bulk'], ['cream', 100, 99, 100, 50, 'bulk'],
     ['herbs', 6, 99, 12, 90, 'bulk']],
    7],
   {'packs': {}, 'per_serving_cents': 608, 'total_cents': 4253}],
  ['repair check: trim yield direction',
   [[['eggs', 3, 99, 100, 75, 'bulk'], ['herbs', 300, 249, 500, 85, 'whole'],
     ['lemon', 100, 99, 6, 75, 'bulk']],
    5],
   {'packs': {'herbs': 1}, 'per_serving_cents': 491, 'total_cents': 2453}],
  ['generated control 1', [[['beef', 50, 1200, 100, 90, 'whole'], ['eggs', 100, 249, 500, 100, 'bulk']], 4],
   {'packs': {'beef': 1}, 'per_serving_cents': 313, 'total_cents': 1250}],
  ['generated control 2', [[['herbs', 250, 99, 6, 75, 'whole']], 6],
   {'packs': {'herbs': 56}, 'per_serving_cents': 924, 'total_cents': 5544}],
  ['generated control 3', [[['herbs', 6, 450, 6, 75, 'whole'], ['cream', 100, 1200, 1000, 100, 'whole']], 1],
   {'packs': {'cream': 1, 'herbs': 2}, 'per_serving_cents': 2100, 'total_cents': 2100}]],
 [['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: trim yield direction',
   [[['herbs', 300, 1200, 500, 50, 'bulk'], ['eggs', 6, 99, 250, 50, 'whole']], 6],
   {'packs': {'eggs': 1}, 'per_serving_cents': 257, 'total_cents': 1539}],
  ['repair check: trim yield direction', [[['cream', 900, 249, 12, 50, 'whole']], 8],
   {'packs': {'cream': 150}, 'per_serving_cents': 4669, 'total_cents': 37350}],
  ['generated control 1', [[['cream', 250, 99, 100, 100, 'bulk']], 2],
   {'packs': {}, 'per_serving_cents': 124, 'total_cents': 248}],
  ['generated control 2',
   [[['beef', 300, 450, 100, 80, 'whole'], ['herbs', 50, 99, 100, 80, 'whole'],
     ['onion', 900, 99, 100, 75, 'whole'], ['lemon', 50, 450, 6, 90, 'bulk']],
    5],
   {'packs': {'beef': 4, 'herbs': 1, 'onion': 12}, 'per_serving_cents': 1451, 'total_cents': 7254}],
  ['generated control 3',
   [[['beef', 900, 249, 12, 75, 'whole'], ['herbs', 3, 249, 6, 90, 'bulk'],
     ['onion', 6, 249, 250, 90, 'whole']],
    3],
   {'packs': {'beef': 100, 'onion': 1}, 'per_serving_cents': 8430, 'total_cents': 25287}]]]
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 fixtureActualExpectedOutcome
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: trim yield direction{'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}{'packs': {'cream': 1, 'herbs': 4}, 'per_serving_cents': 351, 'total_cents': 2455}Passed
repair check: trim yield direction{'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}{'packs': {'lemon': 1}, 'per_serving_cents': 1055, 'total_cents': 5271}Passed
generated control 1{'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}{'packs': {'beef': 1, 'eggs': 4, 'onion': 2}, 'per_serving_cents': 470, 'total_cents': 2348}Passed
generated control 2{'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}{'packs': {'beef': 28, 'herbs': 10, 'onion': 2}, 'per_serving_cents': 1375, 'total_cents': 8246}Passed
generated control 3{'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}{'packs': {'cream': 1}, 'per_serving_cents': 270, 'total_cents': 810}Passed

SHA-256 / 6b305fa66388a2c2f20cdd9042fa4044ffd76341f3aed7158921b8fa680ae836

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.886425+00:00.

Case digest / 6da6392a93e23a8887dc14ff2ddf05106b43870e6a7ea2d156189cb3b6761b75