FAILURE MAP
← Case archive

FA-97141 / Recipe scaling and nutrition / Open access

Shopping list aggregator: pantry name normalization · case 01

A pantry entry "egg" does not cancel recipe rows "eggs".

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

ROOT CAUSE

Pantry names are looked up without the plural normalization applied to recipe rows.

VERIFIED REPAIR

Normalize pantry names with the same function.

Unsuccessful approach: Lower-casing alone still misses plural and whitespace differences.

Case contract

Rows [name, qty, unit]. Names normalize: trim, lower, "-oes" -> drop "es", "-ies" -> "y", other trailing "s" dropped unless "ss". Volume (tsp=1, tbsp=3, cup=48 tsp), mass (g, kg=1000 g) and other units aggregate separately per name. Pantry {name: [qty, unit]} subtracts from the same name and dimension, never below 0. Output sorted by (name, dimension) as [name, str(qty), unit], skipping zero totals; volume shows cup if >=12 tsp, else tbsp if >=3 tsp, else tsp; mass shows kg if >=1000 g.

Why this case matters

Meal planners merge ingredient lists across recipes and subtract what is already in the pantry.

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (name, dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['berries', '3', 'tbsp'], ['flour', '1', 'tbsp'], ['watercress', '3/4', 'tsp'],
      ['tomatoes', '1', 'tsp']],
     [['watercress', '1/2', 'g'], ['berry', '4', 'cup'], ['sugar ', '3/4', 'tsp']],
     [['potatoes', '4', 'kg']]],
    {'berries': ['3/4', 'cup'], 'tomatoes': ['3', 'tbsp']}],
   [['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'],
    ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['egg', '3/4', 'cup'], ['berries', '3', 'each'], ['tomatoes', '3/4', 'cup'], ['grapes', '4', 'kg']]],
    {'berries': ['1/3', 'cup'], 'grapes': ['2', 'kg']}],
   [['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]],
  ['generated control 1',
   [[[['peas', '2', 'tsp'], ['grapes', '2', 'tbsp'], ['potatoes', '1/4', 'cup'], ['sugar ', '1/2', 'each']],
     [['berry', '3/4', 'tsp'], ['sugar ', '1/2', 'tsp'], ['watercress', '3', 'cup'], ['egg', '2', 'g']],
     [['sugar ', '4', 'tsp'], ['grape', '2', 'each'], ['grape', '1/4', 'kg']]],
    {'Tomato': ['2', 'tsp']}],
   [['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'],
    ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'],
    ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]],
  ['generated control 2',
   [[[['sugar ', '1/2', 'tbsp'], ['egg', '1/4', 'tbsp']],
     [['egg', '4', 'tbsp'], ['watercress', '1/3', 'tbsp']],
     [['tomatoes', '3', 'each'], ['peas', '2', 'tsp']]],
    {'peas': ['1/2', 'each'], 'sugar ': ['1/3', 'g']}],
   [['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'],
    ['watercress', '1', 'tsp']]],
  ['generated control 3',
   [[[['berry', '1/2', 'tsp'], ['watercress', '1/3', 'tsp'], ['Tomato', '1/3', 'tsp'], ['grape', '2', 'kg']]],
    {'flour': ['3/4', 'tsp']}],
   [['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: pantry name normalization',
   [[[['peas', '3/4', 'cup'], ['watercress', '2', 'g'], ['berry', '4', 'cup'], ['egg', '1/3', 'cup']]],
    {'eggs': ['1/2', 'tbsp']}],
   [['berry', '4', 'cup'], ['egg', '29/96', 'cup'], ['pea', '3/4', 'cup'], ['watercress', '2', 'g']]],
  ['repair check: pantry name normalization',
   [[[['grapes', '2', 'tbsp'], ['grape', '3/4', 'g']],
     [['grape', '2', 'kg'], ['watercress', '1/3', 'tbsp'], ['egg', '1/4', 'kg'], ['eggs', '1', 'tsp']],
     [['peas', '1/3', 'tbsp']]],
    {'peas': ['1/2', 'cup']}],
   [['egg', '250', 'g'], ['egg', '1', 'tsp'], ['grape', '8003/4000', 'kg'], ['grape', '2', 'tbsp'],
    ['watercress', '1', 'tsp']]],
  ['generated control 1',
   [[[['flour', '3/4', 'tsp'], ['grapes', '1/2', 'cup']],
     [['peas', '1/2', 'tsp'], ['tomatoes', '3/4', 'tbsp'], ['berries', '1', 'cup'], ['eggs', '4', 'kg']]],
    {}],
   [['berry', '1', 'cup'], ['egg', '4', 'kg'], ['flour', '3/4', 'tsp'], ['grape', '1/2', 'cup'],
    ['pea', '1/2', 'tsp'], ['tomato', '9/4', 'tsp']]],
  ['generated control 2',
   [[[['berry', '4', 'each'], ['Tomato', '3/4', 'each'], ['grape', '3', 'g'], ['sugar ', '4', 'tbsp']],
     [['sugar ', '2', 'each'], ['watercress', '3/4', 'tsp']]],
    {'berries': ['1/2', 'tsp']}],
   [['berry', '4', 'each'], ['grape', '3', 'g'], ['sugar', '2', 'each'], ['sugar', '1/4', 'cup'],
    ['tomato', '3/4', 'each'], ['watercress', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['flour', '3', 'g'], ['grape', '3', 'tsp']],
     [['tomatoes', '1', 'g'], ['potatoes', '1/4', 'cup'], ['berries', '1/3', 'cup']]],
    {'berry': ['1/4', 'tsp'], 'sugar ': ['1', 'kg']}],
   [['berry', '21/64', 'cup'], ['flour', '3', 'g'], ['grape', '1', 'tbsp'], ['potato', '1/4', 'cup'],
    ['tomato', '1', 'g']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: pantry name normalization',
   [[[['tomatoes', '3', 'g'], ['Tomato', '1/3', 'cup'], ['grapes', '4', 'tbsp'], ['potatoes', '1/3', 'tsp']],
     [['eggs', '1/2', 'each'], ['tomatoes', '2', 'g']],
     [['tomatoes', '3/4', 'g'], ['egg', '1/3', 'tsp'], ['berries', '2', 'kg'], ['peas', '2', 'cup']]],
    {'berry': ['1/3', 'cup'], 'tomatoes': ['4', 'tbsp']}],
   [['berry', '2', 'kg'], ['egg', '1/2', 'each'], ['egg', '1/3', 'tsp'], ['grape', '1/4', 'cup'],
    ['pea', '2', 'cup'], ['potato', '1/3', 'tsp'], ['tomato', '23/4', 'g'], ['tomato', '4/3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['tomatoes', '4', 'g'], ['tomatoes', '1/2', 'each'], ['Tomato', '3', 'tsp'],
      ['grapes', '1/4', 'tbsp']]],
    {'grapes': ['1', 'tsp']}],
   [['tomato', '1/2', 'each'], ['tomato', '4', 'g'], ['tomato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['grapes', '1/3', 'kg'], ['sugar ', '1/2', 'each'], ['Tomato', '1/2', 'each']]], {}],
   [['grape', '1000/3', 'g'], ['sugar', '1/2', 'each'], ['tomato', '1/2', 'each']]],
  ['generated control 2', [[[['eggs', '4', 'kg'], ['Tomato', '1/3', 'each'], ['berries', '1/4', 'tsp']]], {}],
   [['berry', '1/4', 'tsp'], ['egg', '4', 'kg'], ['tomato', '1/3', 'each']]],
  ['generated control 3',
   [[[['peas', '1/4', 'cup'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'g'], ['egg', '2', 'g']]],
    {'eggs': ['1/4', 'tsp'], 'peas': ['3', 'cup']}],
   [['egg', '2', 'g'], ['sugar', '1/4', 'each'], ['tomato', '4', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: pantry name normalization',
   [[[['egg', '4', 'cup'], ['tomatoes', '3', 'tbsp']], [['peas', '1/3', 'g'], ['sugar ', '1/3', 'each']],
     [['tomatoes', '1', 'g']]],
    {'egg': ['1', 'each'], 'eggs': ['3/4', 'tbsp']}],
   [['egg', '253/64', 'cup'], ['pea', '1/3', 'g'], ['sugar', '1/3', 'each'], ['tomato', '1', 'g'],
    ['tomato', '3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['Tomato', '1/3', 'g'], ['eggs', '3', 'g']], [['watercress', '1/3', 'kg']],
     [['sugar ', '1/3', 'kg'], ['egg', '1/4', 'kg']]],
    {'tomatoes': ['4', 'g'], 'watercress': ['2', 'cup']}],
   [['egg', '253', 'g'], ['sugar', '1000/3', 'g'], ['watercress', '1000/3', 'g']]],
  ['generated control 1',
   [[[['watercress', '2', 'cup'], ['tomatoes', '1/4', 'kg'], ['grape', '1/4', 'tbsp'],
      ['grapes', '3', 'tbsp']],
     [['watercress', '1', 'kg']], [['sugar ', '4', 'each'], ['berries', '1/3', 'tsp']]],
    {}],
   [['berry', '1/3', 'tsp'], ['grape', '13/4', 'tbsp'], ['sugar', '4', 'each'], ['tomato', '250', 'g'],
    ['watercress', '1', 'kg'], ['watercress', '2', 'cup']]],
  ['generated control 2',
   [[[['peas', '1/3', 'each'], ['flour', '4', 'kg'], ['Tomato', '1/2', 'tbsp']]], {'berry': ['4', 'each']}],
   [['flour', '4', 'kg'], ['pea', '1/3', 'each'], ['tomato', '3/2', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '4', 'kg'], ['sugar ', '3/4', 'cup']], [['peas', '3', 'kg'], ['potatoes', '2', 'tbsp']],
     [['watercress', '4', 'each'], ['berry', '3', 'cup'], ['grape', '1/4', 'each']]],
    {'berries': ['2', 'g'], 'berry': ['1/4', 'cup']}],
   [['berry', '11/4', 'cup'], ['grape', '1/4', 'each'], ['pea', '3', 'kg'], ['potato', '4', 'kg'],
    ['potato', '2', 'tbsp'], ['sugar', '3/4', 'cup'], ['watercress', '4', 'each']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['grape', '1/2', 'each'], ['potatoes', '3/4', 'each']],
     [['berry', '3', 'g'], ['tomatoes', '1/2', 'tsp']]],
    {'grapes': ['3/4', 'each']}],
   [['berry', '3', 'g'], ['potato', '3/4', 'each'], ['tomato', '1/2', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['flour', '3/4', 'cup'], ['berries', '2', 'tsp'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '3/4', 'each'], ['watercress', '1', 'cup'], ['sugar ', '1/2', 'tbsp'],
      ['berry', '1/2', 'tbsp']]],
    {'egg': ['1/3', 'each'], 'sugar ': ['1/4', 'cup']}],
   [['berry', '7/6', 'tbsp'], ['flour', '3/4', 'cup'], ['tomato', '3/4', 'each'],
    ['watercress', '33/32', 'cup']]],
  ['generated control 1',
   [[[['egg', '2', 'g'], ['eggs', '4', 'tsp']],
     [['peas', '1/2', 'tbsp'], ['watercress', '1/4', 'tbsp'], ['tomatoes', '4', 'g']],
     [['egg', '4', 'cup']]],
    {'grapes': ['4', 'cup'], 'watercress': ['1/3', 'cup']}],
   [['egg', '2', 'g'], ['egg', '49/12', 'cup'], ['pea', '3/2', 'tsp'], ['tomato', '4', 'g']]],
  ['generated control 2',
   [[[['sugar ', '2', 'kg'], ['grape', '4', 'each'], ['flour', '4', 'kg']],
     [['flour', '1/3', 'tsp'], ['tomatoes', '4', 'each'], ['berries', '1/4', 'tsp'], ['peas', '1/4', 'each']],
     [['tomatoes', '3/4', 'tsp'], ['watercress', '4', 'each'], ['flour', '3/4', 'each'],
      ['eggs', '1/2', 'g']]],
    {'flour': ['2', 'tbsp']}],
   [['berry', '1/4', 'tsp'], ['egg', '1/2', 'g'], ['flour', '3/4', 'each'], ['flour', '4', 'kg'],
    ['grape', '4', 'each'], ['pea', '1/4', 'each'], ['sugar', '2', 'kg'], ['tomato', '4', 'each'],
    ['tomato', '3/4', 'tsp'], ['watercress', '4', 'each']]],
  ['generated control 3',
   [[[['eggs', '4', 'tbsp']], [['berry', '3/4', 'each'], ['tomatoes', '3', 'g'], ['grapes', '1/2', 'kg']]],
    {}],
   [['berry', '3/4', 'each'], ['egg', '1/4', 'cup'], ['grape', '500', 'g'], ['tomato', '3', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: pantry name normalization[['berry', '67/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['tomato', '1', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']][['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]Failed
repair check: pantry name normalization[['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '4', 'kg'], ['tomato', '3/4', 'cup']][['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]Failed
generated control 1[['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']][['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]Passed
generated control 2[['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']][['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']]Passed
generated control 3[['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']][['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]Passed

SHA-256 / cd498604764bd7ef6325611eb4d965bc27432c783132d49d9ba545983381bef1

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (name.lower(), dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['berries', '3', 'tbsp'], ['flour', '1', 'tbsp'], ['watercress', '3/4', 'tsp'],
      ['tomatoes', '1', 'tsp']],
     [['watercress', '1/2', 'g'], ['berry', '4', 'cup'], ['sugar ', '3/4', 'tsp']],
     [['potatoes', '4', 'kg']]],
    {'berries': ['3/4', 'cup'], 'tomatoes': ['3', 'tbsp']}],
   [['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'],
    ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['egg', '3/4', 'cup'], ['berries', '3', 'each'], ['tomatoes', '3/4', 'cup'], ['grapes', '4', 'kg']]],
    {'berries': ['1/3', 'cup'], 'grapes': ['2', 'kg']}],
   [['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]],
  ['generated control 1',
   [[[['peas', '2', 'tsp'], ['grapes', '2', 'tbsp'], ['potatoes', '1/4', 'cup'], ['sugar ', '1/2', 'each']],
     [['berry', '3/4', 'tsp'], ['sugar ', '1/2', 'tsp'], ['watercress', '3', 'cup'], ['egg', '2', 'g']],
     [['sugar ', '4', 'tsp'], ['grape', '2', 'each'], ['grape', '1/4', 'kg']]],
    {'Tomato': ['2', 'tsp']}],
   [['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'],
    ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'],
    ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]],
  ['generated control 2',
   [[[['sugar ', '1/2', 'tbsp'], ['egg', '1/4', 'tbsp']],
     [['egg', '4', 'tbsp'], ['watercress', '1/3', 'tbsp']],
     [['tomatoes', '3', 'each'], ['peas', '2', 'tsp']]],
    {'peas': ['1/2', 'each'], 'sugar ': ['1/3', 'g']}],
   [['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'],
    ['watercress', '1', 'tsp']]],
  ['generated control 3',
   [[[['berry', '1/2', 'tsp'], ['watercress', '1/3', 'tsp'], ['Tomato', '1/3', 'tsp'], ['grape', '2', 'kg']]],
    {'flour': ['3/4', 'tsp']}],
   [['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: pantry name normalization',
   [[[['peas', '3/4', 'cup'], ['watercress', '2', 'g'], ['berry', '4', 'cup'], ['egg', '1/3', 'cup']]],
    {'eggs': ['1/2', 'tbsp']}],
   [['berry', '4', 'cup'], ['egg', '29/96', 'cup'], ['pea', '3/4', 'cup'], ['watercress', '2', 'g']]],
  ['repair check: pantry name normalization',
   [[[['grapes', '2', 'tbsp'], ['grape', '3/4', 'g']],
     [['grape', '2', 'kg'], ['watercress', '1/3', 'tbsp'], ['egg', '1/4', 'kg'], ['eggs', '1', 'tsp']],
     [['peas', '1/3', 'tbsp']]],
    {'peas': ['1/2', 'cup']}],
   [['egg', '250', 'g'], ['egg', '1', 'tsp'], ['grape', '8003/4000', 'kg'], ['grape', '2', 'tbsp'],
    ['watercress', '1', 'tsp']]],
  ['generated control 1',
   [[[['flour', '3/4', 'tsp'], ['grapes', '1/2', 'cup']],
     [['peas', '1/2', 'tsp'], ['tomatoes', '3/4', 'tbsp'], ['berries', '1', 'cup'], ['eggs', '4', 'kg']]],
    {}],
   [['berry', '1', 'cup'], ['egg', '4', 'kg'], ['flour', '3/4', 'tsp'], ['grape', '1/2', 'cup'],
    ['pea', '1/2', 'tsp'], ['tomato', '9/4', 'tsp']]],
  ['generated control 2',
   [[[['berry', '4', 'each'], ['Tomato', '3/4', 'each'], ['grape', '3', 'g'], ['sugar ', '4', 'tbsp']],
     [['sugar ', '2', 'each'], ['watercress', '3/4', 'tsp']]],
    {'berries': ['1/2', 'tsp']}],
   [['berry', '4', 'each'], ['grape', '3', 'g'], ['sugar', '2', 'each'], ['sugar', '1/4', 'cup'],
    ['tomato', '3/4', 'each'], ['watercress', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['flour', '3', 'g'], ['grape', '3', 'tsp']],
     [['tomatoes', '1', 'g'], ['potatoes', '1/4', 'cup'], ['berries', '1/3', 'cup']]],
    {'berry': ['1/4', 'tsp'], 'sugar ': ['1', 'kg']}],
   [['berry', '21/64', 'cup'], ['flour', '3', 'g'], ['grape', '1', 'tbsp'], ['potato', '1/4', 'cup'],
    ['tomato', '1', 'g']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: pantry name normalization',
   [[[['tomatoes', '3', 'g'], ['Tomato', '1/3', 'cup'], ['grapes', '4', 'tbsp'], ['potatoes', '1/3', 'tsp']],
     [['eggs', '1/2', 'each'], ['tomatoes', '2', 'g']],
     [['tomatoes', '3/4', 'g'], ['egg', '1/3', 'tsp'], ['berries', '2', 'kg'], ['peas', '2', 'cup']]],
    {'berry': ['1/3', 'cup'], 'tomatoes': ['4', 'tbsp']}],
   [['berry', '2', 'kg'], ['egg', '1/2', 'each'], ['egg', '1/3', 'tsp'], ['grape', '1/4', 'cup'],
    ['pea', '2', 'cup'], ['potato', '1/3', 'tsp'], ['tomato', '23/4', 'g'], ['tomato', '4/3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['tomatoes', '4', 'g'], ['tomatoes', '1/2', 'each'], ['Tomato', '3', 'tsp'],
      ['grapes', '1/4', 'tbsp']]],
    {'grapes': ['1', 'tsp']}],
   [['tomato', '1/2', 'each'], ['tomato', '4', 'g'], ['tomato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['grapes', '1/3', 'kg'], ['sugar ', '1/2', 'each'], ['Tomato', '1/2', 'each']]], {}],
   [['grape', '1000/3', 'g'], ['sugar', '1/2', 'each'], ['tomato', '1/2', 'each']]],
  ['generated control 2', [[[['eggs', '4', 'kg'], ['Tomato', '1/3', 'each'], ['berries', '1/4', 'tsp']]], {}],
   [['berry', '1/4', 'tsp'], ['egg', '4', 'kg'], ['tomato', '1/3', 'each']]],
  ['generated control 3',
   [[[['peas', '1/4', 'cup'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'g'], ['egg', '2', 'g']]],
    {'eggs': ['1/4', 'tsp'], 'peas': ['3', 'cup']}],
   [['egg', '2', 'g'], ['sugar', '1/4', 'each'], ['tomato', '4', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: pantry name normalization',
   [[[['egg', '4', 'cup'], ['tomatoes', '3', 'tbsp']], [['peas', '1/3', 'g'], ['sugar ', '1/3', 'each']],
     [['tomatoes', '1', 'g']]],
    {'egg': ['1', 'each'], 'eggs': ['3/4', 'tbsp']}],
   [['egg', '253/64', 'cup'], ['pea', '1/3', 'g'], ['sugar', '1/3', 'each'], ['tomato', '1', 'g'],
    ['tomato', '3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['Tomato', '1/3', 'g'], ['eggs', '3', 'g']], [['watercress', '1/3', 'kg']],
     [['sugar ', '1/3', 'kg'], ['egg', '1/4', 'kg']]],
    {'tomatoes': ['4', 'g'], 'watercress': ['2', 'cup']}],
   [['egg', '253', 'g'], ['sugar', '1000/3', 'g'], ['watercress', '1000/3', 'g']]],
  ['generated control 1',
   [[[['watercress', '2', 'cup'], ['tomatoes', '1/4', 'kg'], ['grape', '1/4', 'tbsp'],
      ['grapes', '3', 'tbsp']],
     [['watercress', '1', 'kg']], [['sugar ', '4', 'each'], ['berries', '1/3', 'tsp']]],
    {}],
   [['berry', '1/3', 'tsp'], ['grape', '13/4', 'tbsp'], ['sugar', '4', 'each'], ['tomato', '250', 'g'],
    ['watercress', '1', 'kg'], ['watercress', '2', 'cup']]],
  ['generated control 2',
   [[[['peas', '1/3', 'each'], ['flour', '4', 'kg'], ['Tomato', '1/2', 'tbsp']]], {'berry': ['4', 'each']}],
   [['flour', '4', 'kg'], ['pea', '1/3', 'each'], ['tomato', '3/2', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '4', 'kg'], ['sugar ', '3/4', 'cup']], [['peas', '3', 'kg'], ['potatoes', '2', 'tbsp']],
     [['watercress', '4', 'each'], ['berry', '3', 'cup'], ['grape', '1/4', 'each']]],
    {'berries': ['2', 'g'], 'berry': ['1/4', 'cup']}],
   [['berry', '11/4', 'cup'], ['grape', '1/4', 'each'], ['pea', '3', 'kg'], ['potato', '4', 'kg'],
    ['potato', '2', 'tbsp'], ['sugar', '3/4', 'cup'], ['watercress', '4', 'each']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['grape', '1/2', 'each'], ['potatoes', '3/4', 'each']],
     [['berry', '3', 'g'], ['tomatoes', '1/2', 'tsp']]],
    {'grapes': ['3/4', 'each']}],
   [['berry', '3', 'g'], ['potato', '3/4', 'each'], ['tomato', '1/2', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['flour', '3/4', 'cup'], ['berries', '2', 'tsp'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '3/4', 'each'], ['watercress', '1', 'cup'], ['sugar ', '1/2', 'tbsp'],
      ['berry', '1/2', 'tbsp']]],
    {'egg': ['1/3', 'each'], 'sugar ': ['1/4', 'cup']}],
   [['berry', '7/6', 'tbsp'], ['flour', '3/4', 'cup'], ['tomato', '3/4', 'each'],
    ['watercress', '33/32', 'cup']]],
  ['generated control 1',
   [[[['egg', '2', 'g'], ['eggs', '4', 'tsp']],
     [['peas', '1/2', 'tbsp'], ['watercress', '1/4', 'tbsp'], ['tomatoes', '4', 'g']],
     [['egg', '4', 'cup']]],
    {'grapes': ['4', 'cup'], 'watercress': ['1/3', 'cup']}],
   [['egg', '2', 'g'], ['egg', '49/12', 'cup'], ['pea', '3/2', 'tsp'], ['tomato', '4', 'g']]],
  ['generated control 2',
   [[[['sugar ', '2', 'kg'], ['grape', '4', 'each'], ['flour', '4', 'kg']],
     [['flour', '1/3', 'tsp'], ['tomatoes', '4', 'each'], ['berries', '1/4', 'tsp'], ['peas', '1/4', 'each']],
     [['tomatoes', '3/4', 'tsp'], ['watercress', '4', 'each'], ['flour', '3/4', 'each'],
      ['eggs', '1/2', 'g']]],
    {'flour': ['2', 'tbsp']}],
   [['berry', '1/4', 'tsp'], ['egg', '1/2', 'g'], ['flour', '3/4', 'each'], ['flour', '4', 'kg'],
    ['grape', '4', 'each'], ['pea', '1/4', 'each'], ['sugar', '2', 'kg'], ['tomato', '4', 'each'],
    ['tomato', '3/4', 'tsp'], ['watercress', '4', 'each']]],
  ['generated control 3',
   [[[['eggs', '4', 'tbsp']], [['berry', '3/4', 'each'], ['tomatoes', '3', 'g'], ['grapes', '1/2', 'kg']]],
    {}],
   [['berry', '3/4', 'each'], ['egg', '1/4', 'cup'], ['grape', '500', 'g'], ['tomato', '3', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: pantry name normalization[['berry', '67/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['tomato', '1', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']][['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]Failed
repair check: pantry name normalization[['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '4', 'kg'], ['tomato', '3/4', 'cup']][['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]Failed
generated control 1[['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']][['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]Passed
generated control 2[['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']][['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']]Passed
generated control 3[['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']][['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]Passed

SHA-256 / 08c6702b4eb83c35155891e16c6c36fec25303303a4d20d79ecdf32e8ef8eaa4

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['berries', '3', 'tbsp'], ['flour', '1', 'tbsp'], ['watercress', '3/4', 'tsp'],
      ['tomatoes', '1', 'tsp']],
     [['watercress', '1/2', 'g'], ['berry', '4', 'cup'], ['sugar ', '3/4', 'tsp']],
     [['potatoes', '4', 'kg']]],
    {'berries': ['3/4', 'cup'], 'tomatoes': ['3', 'tbsp']}],
   [['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'],
    ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['egg', '3/4', 'cup'], ['berries', '3', 'each'], ['tomatoes', '3/4', 'cup'], ['grapes', '4', 'kg']]],
    {'berries': ['1/3', 'cup'], 'grapes': ['2', 'kg']}],
   [['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]],
  ['generated control 1',
   [[[['peas', '2', 'tsp'], ['grapes', '2', 'tbsp'], ['potatoes', '1/4', 'cup'], ['sugar ', '1/2', 'each']],
     [['berry', '3/4', 'tsp'], ['sugar ', '1/2', 'tsp'], ['watercress', '3', 'cup'], ['egg', '2', 'g']],
     [['sugar ', '4', 'tsp'], ['grape', '2', 'each'], ['grape', '1/4', 'kg']]],
    {'Tomato': ['2', 'tsp']}],
   [['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'],
    ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'],
    ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]],
  ['generated control 2',
   [[[['sugar ', '1/2', 'tbsp'], ['egg', '1/4', 'tbsp']],
     [['egg', '4', 'tbsp'], ['watercress', '1/3', 'tbsp']],
     [['tomatoes', '3', 'each'], ['peas', '2', 'tsp']]],
    {'peas': ['1/2', 'each'], 'sugar ': ['1/3', 'g']}],
   [['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'],
    ['watercress', '1', 'tsp']]],
  ['generated control 3',
   [[[['berry', '1/2', 'tsp'], ['watercress', '1/3', 'tsp'], ['Tomato', '1/3', 'tsp'], ['grape', '2', 'kg']]],
    {'flour': ['3/4', 'tsp']}],
   [['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: pantry name normalization',
   [[[['peas', '3/4', 'cup'], ['watercress', '2', 'g'], ['berry', '4', 'cup'], ['egg', '1/3', 'cup']]],
    {'eggs': ['1/2', 'tbsp']}],
   [['berry', '4', 'cup'], ['egg', '29/96', 'cup'], ['pea', '3/4', 'cup'], ['watercress', '2', 'g']]],
  ['repair check: pantry name normalization',
   [[[['grapes', '2', 'tbsp'], ['grape', '3/4', 'g']],
     [['grape', '2', 'kg'], ['watercress', '1/3', 'tbsp'], ['egg', '1/4', 'kg'], ['eggs', '1', 'tsp']],
     [['peas', '1/3', 'tbsp']]],
    {'peas': ['1/2', 'cup']}],
   [['egg', '250', 'g'], ['egg', '1', 'tsp'], ['grape', '8003/4000', 'kg'], ['grape', '2', 'tbsp'],
    ['watercress', '1', 'tsp']]],
  ['generated control 1',
   [[[['flour', '3/4', 'tsp'], ['grapes', '1/2', 'cup']],
     [['peas', '1/2', 'tsp'], ['tomatoes', '3/4', 'tbsp'], ['berries', '1', 'cup'], ['eggs', '4', 'kg']]],
    {}],
   [['berry', '1', 'cup'], ['egg', '4', 'kg'], ['flour', '3/4', 'tsp'], ['grape', '1/2', 'cup'],
    ['pea', '1/2', 'tsp'], ['tomato', '9/4', 'tsp']]],
  ['generated control 2',
   [[[['berry', '4', 'each'], ['Tomato', '3/4', 'each'], ['grape', '3', 'g'], ['sugar ', '4', 'tbsp']],
     [['sugar ', '2', 'each'], ['watercress', '3/4', 'tsp']]],
    {'berries': ['1/2', 'tsp']}],
   [['berry', '4', 'each'], ['grape', '3', 'g'], ['sugar', '2', 'each'], ['sugar', '1/4', 'cup'],
    ['tomato', '3/4', 'each'], ['watercress', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['flour', '3', 'g'], ['grape', '3', 'tsp']],
     [['tomatoes', '1', 'g'], ['potatoes', '1/4', 'cup'], ['berries', '1/3', 'cup']]],
    {'berry': ['1/4', 'tsp'], 'sugar ': ['1', 'kg']}],
   [['berry', '21/64', 'cup'], ['flour', '3', 'g'], ['grape', '1', 'tbsp'], ['potato', '1/4', 'cup'],
    ['tomato', '1', 'g']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: pantry name normalization',
   [[[['tomatoes', '3', 'g'], ['Tomato', '1/3', 'cup'], ['grapes', '4', 'tbsp'], ['potatoes', '1/3', 'tsp']],
     [['eggs', '1/2', 'each'], ['tomatoes', '2', 'g']],
     [['tomatoes', '3/4', 'g'], ['egg', '1/3', 'tsp'], ['berries', '2', 'kg'], ['peas', '2', 'cup']]],
    {'berry': ['1/3', 'cup'], 'tomatoes': ['4', 'tbsp']}],
   [['berry', '2', 'kg'], ['egg', '1/2', 'each'], ['egg', '1/3', 'tsp'], ['grape', '1/4', 'cup'],
    ['pea', '2', 'cup'], ['potato', '1/3', 'tsp'], ['tomato', '23/4', 'g'], ['tomato', '4/3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['tomatoes', '4', 'g'], ['tomatoes', '1/2', 'each'], ['Tomato', '3', 'tsp'],
      ['grapes', '1/4', 'tbsp']]],
    {'grapes': ['1', 'tsp']}],
   [['tomato', '1/2', 'each'], ['tomato', '4', 'g'], ['tomato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['grapes', '1/3', 'kg'], ['sugar ', '1/2', 'each'], ['Tomato', '1/2', 'each']]], {}],
   [['grape', '1000/3', 'g'], ['sugar', '1/2', 'each'], ['tomato', '1/2', 'each']]],
  ['generated control 2', [[[['eggs', '4', 'kg'], ['Tomato', '1/3', 'each'], ['berries', '1/4', 'tsp']]], {}],
   [['berry', '1/4', 'tsp'], ['egg', '4', 'kg'], ['tomato', '1/3', 'each']]],
  ['generated control 3',
   [[[['peas', '1/4', 'cup'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'g'], ['egg', '2', 'g']]],
    {'eggs': ['1/4', 'tsp'], 'peas': ['3', 'cup']}],
   [['egg', '2', 'g'], ['sugar', '1/4', 'each'], ['tomato', '4', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: pantry name normalization',
   [[[['egg', '4', 'cup'], ['tomatoes', '3', 'tbsp']], [['peas', '1/3', 'g'], ['sugar ', '1/3', 'each']],
     [['tomatoes', '1', 'g']]],
    {'egg': ['1', 'each'], 'eggs': ['3/4', 'tbsp']}],
   [['egg', '253/64', 'cup'], ['pea', '1/3', 'g'], ['sugar', '1/3', 'each'], ['tomato', '1', 'g'],
    ['tomato', '3', 'tbsp']]],
  ['repair check: pantry name normalization',
   [[[['Tomato', '1/3', 'g'], ['eggs', '3', 'g']], [['watercress', '1/3', 'kg']],
     [['sugar ', '1/3', 'kg'], ['egg', '1/4', 'kg']]],
    {'tomatoes': ['4', 'g'], 'watercress': ['2', 'cup']}],
   [['egg', '253', 'g'], ['sugar', '1000/3', 'g'], ['watercress', '1000/3', 'g']]],
  ['generated control 1',
   [[[['watercress', '2', 'cup'], ['tomatoes', '1/4', 'kg'], ['grape', '1/4', 'tbsp'],
      ['grapes', '3', 'tbsp']],
     [['watercress', '1', 'kg']], [['sugar ', '4', 'each'], ['berries', '1/3', 'tsp']]],
    {}],
   [['berry', '1/3', 'tsp'], ['grape', '13/4', 'tbsp'], ['sugar', '4', 'each'], ['tomato', '250', 'g'],
    ['watercress', '1', 'kg'], ['watercress', '2', 'cup']]],
  ['generated control 2',
   [[[['peas', '1/3', 'each'], ['flour', '4', 'kg'], ['Tomato', '1/2', 'tbsp']]], {'berry': ['4', 'each']}],
   [['flour', '4', 'kg'], ['pea', '1/3', 'each'], ['tomato', '3/2', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '4', 'kg'], ['sugar ', '3/4', 'cup']], [['peas', '3', 'kg'], ['potatoes', '2', 'tbsp']],
     [['watercress', '4', 'each'], ['berry', '3', 'cup'], ['grape', '1/4', 'each']]],
    {'berries': ['2', 'g'], 'berry': ['1/4', 'cup']}],
   [['berry', '11/4', 'cup'], ['grape', '1/4', 'each'], ['pea', '3', 'kg'], ['potato', '4', 'kg'],
    ['potato', '2', 'tbsp'], ['sugar', '3/4', 'cup'], ['watercress', '4', 'each']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: pantry name normalization',
   [[[['grape', '1/2', 'each'], ['potatoes', '3/4', 'each']],
     [['berry', '3', 'g'], ['tomatoes', '1/2', 'tsp']]],
    {'grapes': ['3/4', 'each']}],
   [['berry', '3', 'g'], ['potato', '3/4', 'each'], ['tomato', '1/2', 'tsp']]],
  ['repair check: pantry name normalization',
   [[[['flour', '3/4', 'cup'], ['berries', '2', 'tsp'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '3/4', 'each'], ['watercress', '1', 'cup'], ['sugar ', '1/2', 'tbsp'],
      ['berry', '1/2', 'tbsp']]],
    {'egg': ['1/3', 'each'], 'sugar ': ['1/4', 'cup']}],
   [['berry', '7/6', 'tbsp'], ['flour', '3/4', 'cup'], ['tomato', '3/4', 'each'],
    ['watercress', '33/32', 'cup']]],
  ['generated control 1',
   [[[['egg', '2', 'g'], ['eggs', '4', 'tsp']],
     [['peas', '1/2', 'tbsp'], ['watercress', '1/4', 'tbsp'], ['tomatoes', '4', 'g']],
     [['egg', '4', 'cup']]],
    {'grapes': ['4', 'cup'], 'watercress': ['1/3', 'cup']}],
   [['egg', '2', 'g'], ['egg', '49/12', 'cup'], ['pea', '3/2', 'tsp'], ['tomato', '4', 'g']]],
  ['generated control 2',
   [[[['sugar ', '2', 'kg'], ['grape', '4', 'each'], ['flour', '4', 'kg']],
     [['flour', '1/3', 'tsp'], ['tomatoes', '4', 'each'], ['berries', '1/4', 'tsp'], ['peas', '1/4', 'each']],
     [['tomatoes', '3/4', 'tsp'], ['watercress', '4', 'each'], ['flour', '3/4', 'each'],
      ['eggs', '1/2', 'g']]],
    {'flour': ['2', 'tbsp']}],
   [['berry', '1/4', 'tsp'], ['egg', '1/2', 'g'], ['flour', '3/4', 'each'], ['flour', '4', 'kg'],
    ['grape', '4', 'each'], ['pea', '1/4', 'each'], ['sugar', '2', 'kg'], ['tomato', '4', 'each'],
    ['tomato', '3/4', 'tsp'], ['watercress', '4', 'each']]],
  ['generated control 3',
   [[[['eggs', '4', 'tbsp']], [['berry', '3/4', 'each'], ['tomatoes', '3', 'g'], ['grapes', '1/2', 'kg']]],
    {}],
   [['berry', '3/4', 'each'], ['egg', '1/4', 'cup'], ['grape', '500', 'g'], ['tomato', '3', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: pantry name normalization[['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']][['berry', '55/16', 'cup'], ['flour', '1', 'tbsp'], ['potato', '4', 'kg'], ['sugar', '3/4', 'tsp'], ['watercress', '1/2', 'g'], ['watercress', '3/4', 'tsp']]Passed
repair check: pantry name normalization[['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']][['berry', '3', 'each'], ['egg', '3/4', 'cup'], ['grape', '2', 'kg'], ['tomato', '3/4', 'cup']]Passed
generated control 1[['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']][['berry', '3/4', 'tsp'], ['egg', '2', 'g'], ['grape', '2', 'each'], ['grape', '250', 'g'], ['grape', '2', 'tbsp'], ['pea', '2', 'tsp'], ['potato', '1/4', 'cup'], ['sugar', '1/2', 'each'], ['sugar', '3/2', 'tbsp'], ['watercress', '3', 'cup']]Passed
generated control 2[['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']][['egg', '17/64', 'cup'], ['pea', '2', 'tsp'], ['sugar', '3/2', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1', 'tsp']]Passed
generated control 3[['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']][['berry', '1/2', 'tsp'], ['grape', '2', 'kg'], ['tomato', '1/3', 'tsp'], ['watercress', '1/3', 'tsp']]Passed

SHA-256 / e3e916bb85eaf9dfdc3355e8a28e9a4434254145b18d7cb2f3b73d3c442cf800

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

Case digest / e9221727c3b04c86e214abea977f5faa360a7e2251c315175ad89e45645574bf