FAILURE MAP
← Case archive

FA-97126 / Recipe scaling and nutrition / Open access

Shopping list aggregator: -oes plural rule · case 01

Tomatoes and tomato appear as separate lines "tomatoe" and "tomato".

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

ROOT CAUSE

Words ending "-oes" only lose the final s.

VERIFIED REPAIR

Drop "es" from "-oes" words.

Unsuccessful approach: Dropping "es" from every "-es" word turns grapes into "grap".

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('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: -oes plural rule',
   [[[['Tomato', '1/3', 'tsp'], ['flour', '1', 'kg'], ['tomatoes', '1/2', 'tsp'], ['grape', '3', 'each']],
     [['Tomato', '2', 'g'], ['berry', '1/2', 'tsp'], ['flour', '4', 'tsp'], ['berry', '3/4', 'tsp']],
     [['berry', '3/4', 'g'], ['eggs', '1/4', 'tbsp']]],
    {'watercress': ['4', 'g']}],
   [['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'],
    ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '2', 'each'], ['berry', '2', 'kg'], ['Tomato', '1/4', 'g']],
     [['grape', '2', 'cup'], ['watercress', '1/3', 'tbsp'], ['watercress', '1/4', 'tsp']]],
    {'grape': ['3/4', 'tbsp']}],
   [['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'],
    ['watercress', '5/4', 'tsp']]],
  ['generated control 1', [[[['Tomato', '3/4', 'tsp']]], {'berry': ['2', 'g'], 'egg': ['1/3', 'each']}],
   [['tomato', '3/4', 'tsp']]],
  ['generated control 2',
   [[[['peas', '3', 'g'], ['potatoes', '4', 'tsp'], ['flour', '4', 'g'], ['eggs', '1/2', 'g']],
     [['berry', '3/4', 'each'], ['watercress', '1/3', 'tsp'], ['egg', '1/4', 'each'],
      ['grape', '1/2', 'tsp']],
     [['berry', '1/3', 'tsp']]],
    {'egg': ['3', 'tbsp'], 'eggs': ['3/4', 'g']}],
   [['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'],
    ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['generated control 3',
   [[[['watercress', '1/2', 'cup'], ['potatoes', '4', 'tbsp'], ['watercress', '2', 'each']],
     [['berry', '1/4', 'tbsp']], [['potatoes', '1/4', 'each'], ['watercress', '3/4', 'kg']]],
    {}],
   [['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'],
    ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]]],
 [['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: -oes plural rule',
   [[[['grapes', '2', 'g']], [['potatoes', '1/4', 'kg']]], {'Tomato': ['1/2', 'tsp']}],
   [['grape', '2', 'g'], ['potato', '250', 'g']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '1/2', 'kg']], [['Tomato', '2', 'g']],
     [['berry', '3/4', 'g'], ['tomatoes', '3', 'each'], ['grape', '1', 'tsp'], ['tomatoes', '3', 'cup']]],
    {'eggs': ['1/4', 'g']}],
   [['berry', '3/4', 'g'], ['grape', '500', 'g'], ['grape', '1', 'tsp'], ['tomato', '3', 'each'],
    ['tomato', '2', 'g'], ['tomato', '3', 'cup']]],
  ['generated control 1',
   [[[['berries', '3', 'cup'], ['potatoes', '2', 'g'], ['Tomato', '3', 'tbsp'], ['Tomato', '1/4', 'cup']]],
    {}],
   [['berry', '3', 'cup'], ['potato', '2', 'g'], ['tomato', '7/16', 'cup']]],
  ['generated control 2',
   [[[['Tomato', '1/2', 'cup'], ['Tomato', '2', 'each'], ['sugar ', '2', 'tbsp'],
      ['tomatoes', '1/4', 'each']],
     [['peas', '3/4', 'kg'], ['berries', '2', 'each'], ['tomatoes', '3/4', 'kg']]],
    {'flour': ['3', 'tbsp']}],
   [['berry', '2', 'each'], ['pea', '750', 'g'], ['sugar', '2', 'tbsp'], ['tomato', '9/4', 'each'],
    ['tomato', '750', 'g'], ['tomato', '1/2', 'cup']]],
  ['generated control 3', [[[['flour', '3', 'g'], ['berry', '2', 'each']]], {'flour': ['1/2', 'cup']}],
   [['berry', '2', 'each'], ['flour', '3', '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: -oes plural rule',
   [[[['flour', '2', 'tsp'], ['grapes', '3/4', 'kg'], ['watercress', '1/3', 'tsp']],
     [['potatoes', '4', 'tsp'], ['egg', '3/4', 'tbsp'], ['eggs', '3/4', 'each'], ['grape', '1/4', 'tbsp']]],
    {'flour': ['2', 'cup'], 'grape': ['1/4', 'tsp']}],
   [['egg', '3/4', 'each'], ['egg', '9/4', 'tsp'], ['grape', '750', 'g'], ['grape', '1/2', 'tsp'],
    ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['egg', '1/3', 'cup'], ['berries', '1/4', 'cup'], ['Tomato', '2', 'tsp']]],
    {'grapes': ['1', 'tbsp'], 'watercress': ['1/3', 'tsp']}],
   [['berry', '1/4', 'cup'], ['egg', '1/3', 'cup'], ['tomato', '2', 'tsp']]],
  ['generated control 1',
   [[[['potatoes', '1', 'each'], ['grape', '1/3', 'kg'], ['sugar ', '3', 'cup'], ['watercress', '1', 'each']],
     [['flour', '4', 'tbsp']]],
    {'flour': ['1', 'kg']}],
   [['flour', '1/4', 'cup'], ['grape', '1000/3', 'g'], ['potato', '1', 'each'], ['sugar', '3', 'cup'],
    ['watercress', '1', 'each']]],
  ['generated control 2',
   [[[['eggs', '1/4', 'kg'], ['grapes', '1/4', 'tbsp'], ['watercress', '4', 'cup']],
     [['grape', '4', 'g'], ['flour', '3', 'each']]],
    {'berry': ['1/4', 'tsp'], 'watercress': ['3/4', 'g']}],
   [['egg', '250', 'g'], ['flour', '3', 'each'], ['grape', '4', 'g'], ['grape', '3/4', 'tsp'],
    ['watercress', '4', 'cup']]],
  ['generated control 3',
   [[[['grapes', '1/3', 'g']], [['eggs', '1', 'each'], ['berries', '1/4', 'each']]],
    {'egg': ['3/4', 'each'], 'watercress': ['1', 'cup']}],
   [['berry', '1/4', 'each'], ['egg', '1/4', 'each'], ['grape', '1/3', '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: -oes plural rule',
   [[[['grape', '2', 'kg']], [['sugar ', '3/4', 'tsp'], ['tomatoes', '1/2', 'each']]],
    {'berries': ['3', 'tbsp']}],
   [['grape', '2', 'kg'], ['sugar', '3/4', 'tsp'], ['tomato', '1/2', 'each']]],
  ['repair check: -oes plural rule',
   [[[['egg', '3/4', 'cup'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '1/3', 'tsp'], ['grape', '1/2', 'cup'], ['eggs', '1/2', 'tbsp'],
      ['berries', '1/4', 'each']],
     [['grape', '1/4', 'kg'], ['grapes', '1/3', 'tsp'], ['berry', '3', 'kg'], ['flour', '2', 'tbsp']]],
    {'grapes': ['2', 'kg'], 'sugar ': ['2', 'each']}],
   [['berry', '1/4', 'each'], ['berry', '3', 'kg'], ['egg', '25/32', 'cup'], ['flour', '2', 'tbsp'],
    ['grape', '73/144', 'cup'], ['tomato', '1/3', 'tsp'], ['watercress', '3/2', 'tsp']]],
  ['generated control 1',
   [[[['berry', '1/4', 'tbsp'], ['tomatoes', '1/3', 'kg'], ['sugar ', '1', 'tbsp']],
     [['potatoes', '1/2', 'cup'], ['berry', '3', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '3', 'kg'], ['berry', '3/4', 'tsp'], ['potato', '1/2', 'cup'], ['sugar', '1', 'tbsp'],
    ['tomato', '1000/3', 'g']]],
  ['generated control 2',
   [[[['sugar ', '3', 'g'], ['grape', '1/2', 'each'], ['sugar ', '1', 'cup'], ['egg', '3', 'each']],
     [['peas', '4', 'kg'], ['peas', '3', 'kg'], ['berry', '3/4', 'cup']]],
    {}],
   [['berry', '3/4', 'cup'], ['egg', '3', 'each'], ['grape', '1/2', 'each'], ['pea', '7', 'kg'],
    ['sugar', '3', 'g'], ['sugar', '1', 'cup']]],
  ['generated control 3',
   [[[['flour', '4', 'each'], ['berry', '1/2', 'kg'], ['watercress', '2', 'g']]],
    {'berry': ['1', 'tbsp'], 'grapes': ['4', 'tbsp']}],
   [['berry', '500', 'g'], ['flour', '4', 'each'], ['watercress', '2', 'g']]]],
 [['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: -oes plural rule',
   [[[['peas', '1/2', 'each'], ['Tomato', '1', 'tsp'], ['tomatoes', '1', 'each'], ['flour', '1/3', 'tsp']]],
    {'berry': ['3/4', 'tbsp'], 'watercress': ['1/2', 'tbsp']}],
   [['flour', '1/3', 'tsp'], ['pea', '1/2', 'each'], ['tomato', '1', 'each'], ['tomato', '1', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['sugar ', '1/2', 'each'], ['grapes', '3', 'g']]], {'potatoes': ['1/4', 'each']}],
   [['grape', '3', 'g'], ['sugar', '1/2', 'each']]],
  ['generated control 1',
   [[[['watercress', '1/3', 'cup'], ['berries', '2', 'cup'], ['sugar ', '1', 'cup']],
     [['tomatoes', '1', 'each'], ['grapes', '1/3', 'each'], ['potatoes', '2', 'tbsp'], ['egg', '1', 'kg']],
     [['sugar ', '3', 'kg'], ['Tomato', '3', 'g']]],
    {'Tomato': ['1/2', 'tsp'], 'berry': ['1/2', 'kg']}],
   [['berry', '2', 'cup'], ['egg', '1', 'kg'], ['grape', '1/3', 'each'], ['potato', '2', 'tbsp'],
    ['sugar', '3', 'kg'], ['sugar', '1', 'cup'], ['tomato', '1', 'each'], ['tomato', '3', 'g'],
    ['watercress', '1/3', 'cup']]],
  ['generated control 2',
   [[[['grape', '1/4', 'tsp'], ['egg', '2', 'each'], ['tomatoes', '3', 'each']], [['eggs', '2', 'tsp']],
     [['berry', '4', 'each'], ['berries', '1', 'g'], ['watercress', '1/3', 'each'],
      ['berries', '3/4', 'tbsp']]],
    {}],
   [['berry', '4', 'each'], ['berry', '1', 'g'], ['berry', '9/4', 'tsp'], ['egg', '2', 'each'],
    ['egg', '2', 'tsp'], ['grape', '1/4', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1/3', 'each']]],
  ['generated control 3',
   [[[['potatoes', '3', 'cup']], [['berry', '1/2', 'tsp'], ['Tomato', '1', 'tsp']]],
    {'potatoes': ['1/3', 'cup']}],
   [['berry', '1/2', 'tsp'], ['potato', '8/3', 'cup'], ['tomato', '1', 'tsp']]]]]
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', '1', 'each'], ['tomatoe', '2', 'each']][['tomato', '3', 'each']]Failed
pantry covers all[][]Passed
regression: -oes plural rule[['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '1/3', 'tsp'], ['tomatoe', '1/2', 'tsp']][['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]Failed
repair check: -oes plural rule[['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']][['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']]Passed
generated control 1[['tomato', '3/4', 'tsp']][['tomato', '3/4', 'tsp']]Passed
generated control 2[['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potatoe', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']][['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]Failed
generated control 3[['berry', '3/4', 'tsp'], ['potatoe', '1/4', 'each'], ['potatoe', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']][['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]Failed

SHA-256 / 224cf928bc4a463fa0aabefa7839e17c623210a4017ad20948197188c23f7f59

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('es'):
            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: -oes plural rule',
   [[[['Tomato', '1/3', 'tsp'], ['flour', '1', 'kg'], ['tomatoes', '1/2', 'tsp'], ['grape', '3', 'each']],
     [['Tomato', '2', 'g'], ['berry', '1/2', 'tsp'], ['flour', '4', 'tsp'], ['berry', '3/4', 'tsp']],
     [['berry', '3/4', 'g'], ['eggs', '1/4', 'tbsp']]],
    {'watercress': ['4', 'g']}],
   [['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'],
    ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '2', 'each'], ['berry', '2', 'kg'], ['Tomato', '1/4', 'g']],
     [['grape', '2', 'cup'], ['watercress', '1/3', 'tbsp'], ['watercress', '1/4', 'tsp']]],
    {'grape': ['3/4', 'tbsp']}],
   [['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'],
    ['watercress', '5/4', 'tsp']]],
  ['generated control 1', [[[['Tomato', '3/4', 'tsp']]], {'berry': ['2', 'g'], 'egg': ['1/3', 'each']}],
   [['tomato', '3/4', 'tsp']]],
  ['generated control 2',
   [[[['peas', '3', 'g'], ['potatoes', '4', 'tsp'], ['flour', '4', 'g'], ['eggs', '1/2', 'g']],
     [['berry', '3/4', 'each'], ['watercress', '1/3', 'tsp'], ['egg', '1/4', 'each'],
      ['grape', '1/2', 'tsp']],
     [['berry', '1/3', 'tsp']]],
    {'egg': ['3', 'tbsp'], 'eggs': ['3/4', 'g']}],
   [['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'],
    ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['generated control 3',
   [[[['watercress', '1/2', 'cup'], ['potatoes', '4', 'tbsp'], ['watercress', '2', 'each']],
     [['berry', '1/4', 'tbsp']], [['potatoes', '1/4', 'each'], ['watercress', '3/4', 'kg']]],
    {}],
   [['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'],
    ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]]],
 [['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: -oes plural rule',
   [[[['grapes', '2', 'g']], [['potatoes', '1/4', 'kg']]], {'Tomato': ['1/2', 'tsp']}],
   [['grape', '2', 'g'], ['potato', '250', 'g']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '1/2', 'kg']], [['Tomato', '2', 'g']],
     [['berry', '3/4', 'g'], ['tomatoes', '3', 'each'], ['grape', '1', 'tsp'], ['tomatoes', '3', 'cup']]],
    {'eggs': ['1/4', 'g']}],
   [['berry', '3/4', 'g'], ['grape', '500', 'g'], ['grape', '1', 'tsp'], ['tomato', '3', 'each'],
    ['tomato', '2', 'g'], ['tomato', '3', 'cup']]],
  ['generated control 1',
   [[[['berries', '3', 'cup'], ['potatoes', '2', 'g'], ['Tomato', '3', 'tbsp'], ['Tomato', '1/4', 'cup']]],
    {}],
   [['berry', '3', 'cup'], ['potato', '2', 'g'], ['tomato', '7/16', 'cup']]],
  ['generated control 2',
   [[[['Tomato', '1/2', 'cup'], ['Tomato', '2', 'each'], ['sugar ', '2', 'tbsp'],
      ['tomatoes', '1/4', 'each']],
     [['peas', '3/4', 'kg'], ['berries', '2', 'each'], ['tomatoes', '3/4', 'kg']]],
    {'flour': ['3', 'tbsp']}],
   [['berry', '2', 'each'], ['pea', '750', 'g'], ['sugar', '2', 'tbsp'], ['tomato', '9/4', 'each'],
    ['tomato', '750', 'g'], ['tomato', '1/2', 'cup']]],
  ['generated control 3', [[[['flour', '3', 'g'], ['berry', '2', 'each']]], {'flour': ['1/2', 'cup']}],
   [['berry', '2', 'each'], ['flour', '3', '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: -oes plural rule',
   [[[['flour', '2', 'tsp'], ['grapes', '3/4', 'kg'], ['watercress', '1/3', 'tsp']],
     [['potatoes', '4', 'tsp'], ['egg', '3/4', 'tbsp'], ['eggs', '3/4', 'each'], ['grape', '1/4', 'tbsp']]],
    {'flour': ['2', 'cup'], 'grape': ['1/4', 'tsp']}],
   [['egg', '3/4', 'each'], ['egg', '9/4', 'tsp'], ['grape', '750', 'g'], ['grape', '1/2', 'tsp'],
    ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['egg', '1/3', 'cup'], ['berries', '1/4', 'cup'], ['Tomato', '2', 'tsp']]],
    {'grapes': ['1', 'tbsp'], 'watercress': ['1/3', 'tsp']}],
   [['berry', '1/4', 'cup'], ['egg', '1/3', 'cup'], ['tomato', '2', 'tsp']]],
  ['generated control 1',
   [[[['potatoes', '1', 'each'], ['grape', '1/3', 'kg'], ['sugar ', '3', 'cup'], ['watercress', '1', 'each']],
     [['flour', '4', 'tbsp']]],
    {'flour': ['1', 'kg']}],
   [['flour', '1/4', 'cup'], ['grape', '1000/3', 'g'], ['potato', '1', 'each'], ['sugar', '3', 'cup'],
    ['watercress', '1', 'each']]],
  ['generated control 2',
   [[[['eggs', '1/4', 'kg'], ['grapes', '1/4', 'tbsp'], ['watercress', '4', 'cup']],
     [['grape', '4', 'g'], ['flour', '3', 'each']]],
    {'berry': ['1/4', 'tsp'], 'watercress': ['3/4', 'g']}],
   [['egg', '250', 'g'], ['flour', '3', 'each'], ['grape', '4', 'g'], ['grape', '3/4', 'tsp'],
    ['watercress', '4', 'cup']]],
  ['generated control 3',
   [[[['grapes', '1/3', 'g']], [['eggs', '1', 'each'], ['berries', '1/4', 'each']]],
    {'egg': ['3/4', 'each'], 'watercress': ['1', 'cup']}],
   [['berry', '1/4', 'each'], ['egg', '1/4', 'each'], ['grape', '1/3', '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: -oes plural rule',
   [[[['grape', '2', 'kg']], [['sugar ', '3/4', 'tsp'], ['tomatoes', '1/2', 'each']]],
    {'berries': ['3', 'tbsp']}],
   [['grape', '2', 'kg'], ['sugar', '3/4', 'tsp'], ['tomato', '1/2', 'each']]],
  ['repair check: -oes plural rule',
   [[[['egg', '3/4', 'cup'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '1/3', 'tsp'], ['grape', '1/2', 'cup'], ['eggs', '1/2', 'tbsp'],
      ['berries', '1/4', 'each']],
     [['grape', '1/4', 'kg'], ['grapes', '1/3', 'tsp'], ['berry', '3', 'kg'], ['flour', '2', 'tbsp']]],
    {'grapes': ['2', 'kg'], 'sugar ': ['2', 'each']}],
   [['berry', '1/4', 'each'], ['berry', '3', 'kg'], ['egg', '25/32', 'cup'], ['flour', '2', 'tbsp'],
    ['grape', '73/144', 'cup'], ['tomato', '1/3', 'tsp'], ['watercress', '3/2', 'tsp']]],
  ['generated control 1',
   [[[['berry', '1/4', 'tbsp'], ['tomatoes', '1/3', 'kg'], ['sugar ', '1', 'tbsp']],
     [['potatoes', '1/2', 'cup'], ['berry', '3', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '3', 'kg'], ['berry', '3/4', 'tsp'], ['potato', '1/2', 'cup'], ['sugar', '1', 'tbsp'],
    ['tomato', '1000/3', 'g']]],
  ['generated control 2',
   [[[['sugar ', '3', 'g'], ['grape', '1/2', 'each'], ['sugar ', '1', 'cup'], ['egg', '3', 'each']],
     [['peas', '4', 'kg'], ['peas', '3', 'kg'], ['berry', '3/4', 'cup']]],
    {}],
   [['berry', '3/4', 'cup'], ['egg', '3', 'each'], ['grape', '1/2', 'each'], ['pea', '7', 'kg'],
    ['sugar', '3', 'g'], ['sugar', '1', 'cup']]],
  ['generated control 3',
   [[[['flour', '4', 'each'], ['berry', '1/2', 'kg'], ['watercress', '2', 'g']]],
    {'berry': ['1', 'tbsp'], 'grapes': ['4', 'tbsp']}],
   [['berry', '500', 'g'], ['flour', '4', 'each'], ['watercress', '2', 'g']]]],
 [['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: -oes plural rule',
   [[[['peas', '1/2', 'each'], ['Tomato', '1', 'tsp'], ['tomatoes', '1', 'each'], ['flour', '1/3', 'tsp']]],
    {'berry': ['3/4', 'tbsp'], 'watercress': ['1/2', 'tbsp']}],
   [['flour', '1/3', 'tsp'], ['pea', '1/2', 'each'], ['tomato', '1', 'each'], ['tomato', '1', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['sugar ', '1/2', 'each'], ['grapes', '3', 'g']]], {'potatoes': ['1/4', 'each']}],
   [['grape', '3', 'g'], ['sugar', '1/2', 'each']]],
  ['generated control 1',
   [[[['watercress', '1/3', 'cup'], ['berries', '2', 'cup'], ['sugar ', '1', 'cup']],
     [['tomatoes', '1', 'each'], ['grapes', '1/3', 'each'], ['potatoes', '2', 'tbsp'], ['egg', '1', 'kg']],
     [['sugar ', '3', 'kg'], ['Tomato', '3', 'g']]],
    {'Tomato': ['1/2', 'tsp'], 'berry': ['1/2', 'kg']}],
   [['berry', '2', 'cup'], ['egg', '1', 'kg'], ['grape', '1/3', 'each'], ['potato', '2', 'tbsp'],
    ['sugar', '3', 'kg'], ['sugar', '1', 'cup'], ['tomato', '1', 'each'], ['tomato', '3', 'g'],
    ['watercress', '1/3', 'cup']]],
  ['generated control 2',
   [[[['grape', '1/4', 'tsp'], ['egg', '2', 'each'], ['tomatoes', '3', 'each']], [['eggs', '2', 'tsp']],
     [['berry', '4', 'each'], ['berries', '1', 'g'], ['watercress', '1/3', 'each'],
      ['berries', '3/4', 'tbsp']]],
    {}],
   [['berry', '4', 'each'], ['berry', '1', 'g'], ['berry', '9/4', 'tsp'], ['egg', '2', 'each'],
    ['egg', '2', 'tsp'], ['grape', '1/4', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1/3', 'each']]],
  ['generated control 3',
   [[[['potatoes', '3', 'cup']], [['berry', '1/2', 'tsp'], ['Tomato', '1', 'tsp']]],
    {'potatoes': ['1/3', 'cup']}],
   [['berry', '1/2', 'tsp'], ['potato', '8/3', 'cup'], ['tomato', '1', 'tsp']]]]]
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: -oes plural rule[['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']][['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]Passed
repair check: -oes plural rule[['berry', '2', 'kg'], ['grap', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']][['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']]Failed
generated control 1[['tomato', '3/4', 'tsp']][['tomato', '3/4', 'tsp']]Passed
generated control 2[['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']][['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]Passed
generated control 3[['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']][['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]Passed

SHA-256 / d1dc278d3a902b23f7f61dd081ac2d988e9ee87f1b0813dd5262d613782ac91c

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: -oes plural rule',
   [[[['Tomato', '1/3', 'tsp'], ['flour', '1', 'kg'], ['tomatoes', '1/2', 'tsp'], ['grape', '3', 'each']],
     [['Tomato', '2', 'g'], ['berry', '1/2', 'tsp'], ['flour', '4', 'tsp'], ['berry', '3/4', 'tsp']],
     [['berry', '3/4', 'g'], ['eggs', '1/4', 'tbsp']]],
    {'watercress': ['4', 'g']}],
   [['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'],
    ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '2', 'each'], ['berry', '2', 'kg'], ['Tomato', '1/4', 'g']],
     [['grape', '2', 'cup'], ['watercress', '1/3', 'tbsp'], ['watercress', '1/4', 'tsp']]],
    {'grape': ['3/4', 'tbsp']}],
   [['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'],
    ['watercress', '5/4', 'tsp']]],
  ['generated control 1', [[[['Tomato', '3/4', 'tsp']]], {'berry': ['2', 'g'], 'egg': ['1/3', 'each']}],
   [['tomato', '3/4', 'tsp']]],
  ['generated control 2',
   [[[['peas', '3', 'g'], ['potatoes', '4', 'tsp'], ['flour', '4', 'g'], ['eggs', '1/2', 'g']],
     [['berry', '3/4', 'each'], ['watercress', '1/3', 'tsp'], ['egg', '1/4', 'each'],
      ['grape', '1/2', 'tsp']],
     [['berry', '1/3', 'tsp']]],
    {'egg': ['3', 'tbsp'], 'eggs': ['3/4', 'g']}],
   [['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'],
    ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['generated control 3',
   [[[['watercress', '1/2', 'cup'], ['potatoes', '4', 'tbsp'], ['watercress', '2', 'each']],
     [['berry', '1/4', 'tbsp']], [['potatoes', '1/4', 'each'], ['watercress', '3/4', 'kg']]],
    {}],
   [['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'],
    ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]]],
 [['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: -oes plural rule',
   [[[['grapes', '2', 'g']], [['potatoes', '1/4', 'kg']]], {'Tomato': ['1/2', 'tsp']}],
   [['grape', '2', 'g'], ['potato', '250', 'g']]],
  ['repair check: -oes plural rule',
   [[[['grapes', '1/2', 'kg']], [['Tomato', '2', 'g']],
     [['berry', '3/4', 'g'], ['tomatoes', '3', 'each'], ['grape', '1', 'tsp'], ['tomatoes', '3', 'cup']]],
    {'eggs': ['1/4', 'g']}],
   [['berry', '3/4', 'g'], ['grape', '500', 'g'], ['grape', '1', 'tsp'], ['tomato', '3', 'each'],
    ['tomato', '2', 'g'], ['tomato', '3', 'cup']]],
  ['generated control 1',
   [[[['berries', '3', 'cup'], ['potatoes', '2', 'g'], ['Tomato', '3', 'tbsp'], ['Tomato', '1/4', 'cup']]],
    {}],
   [['berry', '3', 'cup'], ['potato', '2', 'g'], ['tomato', '7/16', 'cup']]],
  ['generated control 2',
   [[[['Tomato', '1/2', 'cup'], ['Tomato', '2', 'each'], ['sugar ', '2', 'tbsp'],
      ['tomatoes', '1/4', 'each']],
     [['peas', '3/4', 'kg'], ['berries', '2', 'each'], ['tomatoes', '3/4', 'kg']]],
    {'flour': ['3', 'tbsp']}],
   [['berry', '2', 'each'], ['pea', '750', 'g'], ['sugar', '2', 'tbsp'], ['tomato', '9/4', 'each'],
    ['tomato', '750', 'g'], ['tomato', '1/2', 'cup']]],
  ['generated control 3', [[[['flour', '3', 'g'], ['berry', '2', 'each']]], {'flour': ['1/2', 'cup']}],
   [['berry', '2', 'each'], ['flour', '3', '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: -oes plural rule',
   [[[['flour', '2', 'tsp'], ['grapes', '3/4', 'kg'], ['watercress', '1/3', 'tsp']],
     [['potatoes', '4', 'tsp'], ['egg', '3/4', 'tbsp'], ['eggs', '3/4', 'each'], ['grape', '1/4', 'tbsp']]],
    {'flour': ['2', 'cup'], 'grape': ['1/4', 'tsp']}],
   [['egg', '3/4', 'each'], ['egg', '9/4', 'tsp'], ['grape', '750', 'g'], ['grape', '1/2', 'tsp'],
    ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['egg', '1/3', 'cup'], ['berries', '1/4', 'cup'], ['Tomato', '2', 'tsp']]],
    {'grapes': ['1', 'tbsp'], 'watercress': ['1/3', 'tsp']}],
   [['berry', '1/4', 'cup'], ['egg', '1/3', 'cup'], ['tomato', '2', 'tsp']]],
  ['generated control 1',
   [[[['potatoes', '1', 'each'], ['grape', '1/3', 'kg'], ['sugar ', '3', 'cup'], ['watercress', '1', 'each']],
     [['flour', '4', 'tbsp']]],
    {'flour': ['1', 'kg']}],
   [['flour', '1/4', 'cup'], ['grape', '1000/3', 'g'], ['potato', '1', 'each'], ['sugar', '3', 'cup'],
    ['watercress', '1', 'each']]],
  ['generated control 2',
   [[[['eggs', '1/4', 'kg'], ['grapes', '1/4', 'tbsp'], ['watercress', '4', 'cup']],
     [['grape', '4', 'g'], ['flour', '3', 'each']]],
    {'berry': ['1/4', 'tsp'], 'watercress': ['3/4', 'g']}],
   [['egg', '250', 'g'], ['flour', '3', 'each'], ['grape', '4', 'g'], ['grape', '3/4', 'tsp'],
    ['watercress', '4', 'cup']]],
  ['generated control 3',
   [[[['grapes', '1/3', 'g']], [['eggs', '1', 'each'], ['berries', '1/4', 'each']]],
    {'egg': ['3/4', 'each'], 'watercress': ['1', 'cup']}],
   [['berry', '1/4', 'each'], ['egg', '1/4', 'each'], ['grape', '1/3', '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: -oes plural rule',
   [[[['grape', '2', 'kg']], [['sugar ', '3/4', 'tsp'], ['tomatoes', '1/2', 'each']]],
    {'berries': ['3', 'tbsp']}],
   [['grape', '2', 'kg'], ['sugar', '3/4', 'tsp'], ['tomato', '1/2', 'each']]],
  ['repair check: -oes plural rule',
   [[[['egg', '3/4', 'cup'], ['watercress', '1/2', 'tbsp']],
     [['tomatoes', '1/3', 'tsp'], ['grape', '1/2', 'cup'], ['eggs', '1/2', 'tbsp'],
      ['berries', '1/4', 'each']],
     [['grape', '1/4', 'kg'], ['grapes', '1/3', 'tsp'], ['berry', '3', 'kg'], ['flour', '2', 'tbsp']]],
    {'grapes': ['2', 'kg'], 'sugar ': ['2', 'each']}],
   [['berry', '1/4', 'each'], ['berry', '3', 'kg'], ['egg', '25/32', 'cup'], ['flour', '2', 'tbsp'],
    ['grape', '73/144', 'cup'], ['tomato', '1/3', 'tsp'], ['watercress', '3/2', 'tsp']]],
  ['generated control 1',
   [[[['berry', '1/4', 'tbsp'], ['tomatoes', '1/3', 'kg'], ['sugar ', '1', 'tbsp']],
     [['potatoes', '1/2', 'cup'], ['berry', '3', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '3', 'kg'], ['berry', '3/4', 'tsp'], ['potato', '1/2', 'cup'], ['sugar', '1', 'tbsp'],
    ['tomato', '1000/3', 'g']]],
  ['generated control 2',
   [[[['sugar ', '3', 'g'], ['grape', '1/2', 'each'], ['sugar ', '1', 'cup'], ['egg', '3', 'each']],
     [['peas', '4', 'kg'], ['peas', '3', 'kg'], ['berry', '3/4', 'cup']]],
    {}],
   [['berry', '3/4', 'cup'], ['egg', '3', 'each'], ['grape', '1/2', 'each'], ['pea', '7', 'kg'],
    ['sugar', '3', 'g'], ['sugar', '1', 'cup']]],
  ['generated control 3',
   [[[['flour', '4', 'each'], ['berry', '1/2', 'kg'], ['watercress', '2', 'g']]],
    {'berry': ['1', 'tbsp'], 'grapes': ['4', 'tbsp']}],
   [['berry', '500', 'g'], ['flour', '4', 'each'], ['watercress', '2', 'g']]]],
 [['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: -oes plural rule',
   [[[['peas', '1/2', 'each'], ['Tomato', '1', 'tsp'], ['tomatoes', '1', 'each'], ['flour', '1/3', 'tsp']]],
    {'berry': ['3/4', 'tbsp'], 'watercress': ['1/2', 'tbsp']}],
   [['flour', '1/3', 'tsp'], ['pea', '1/2', 'each'], ['tomato', '1', 'each'], ['tomato', '1', 'tsp']]],
  ['repair check: -oes plural rule',
   [[[['sugar ', '1/2', 'each'], ['grapes', '3', 'g']]], {'potatoes': ['1/4', 'each']}],
   [['grape', '3', 'g'], ['sugar', '1/2', 'each']]],
  ['generated control 1',
   [[[['watercress', '1/3', 'cup'], ['berries', '2', 'cup'], ['sugar ', '1', 'cup']],
     [['tomatoes', '1', 'each'], ['grapes', '1/3', 'each'], ['potatoes', '2', 'tbsp'], ['egg', '1', 'kg']],
     [['sugar ', '3', 'kg'], ['Tomato', '3', 'g']]],
    {'Tomato': ['1/2', 'tsp'], 'berry': ['1/2', 'kg']}],
   [['berry', '2', 'cup'], ['egg', '1', 'kg'], ['grape', '1/3', 'each'], ['potato', '2', 'tbsp'],
    ['sugar', '3', 'kg'], ['sugar', '1', 'cup'], ['tomato', '1', 'each'], ['tomato', '3', 'g'],
    ['watercress', '1/3', 'cup']]],
  ['generated control 2',
   [[[['grape', '1/4', 'tsp'], ['egg', '2', 'each'], ['tomatoes', '3', 'each']], [['eggs', '2', 'tsp']],
     [['berry', '4', 'each'], ['berries', '1', 'g'], ['watercress', '1/3', 'each'],
      ['berries', '3/4', 'tbsp']]],
    {}],
   [['berry', '4', 'each'], ['berry', '1', 'g'], ['berry', '9/4', 'tsp'], ['egg', '2', 'each'],
    ['egg', '2', 'tsp'], ['grape', '1/4', 'tsp'], ['tomato', '3', 'each'], ['watercress', '1/3', 'each']]],
  ['generated control 3',
   [[[['potatoes', '3', 'cup']], [['berry', '1/2', 'tsp'], ['Tomato', '1', 'tsp']]],
    {'potatoes': ['1/3', 'cup']}],
   [['berry', '1/2', 'tsp'], ['potato', '8/3', 'cup'], ['tomato', '1', 'tsp']]]]]
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: -oes plural rule[['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']][['berry', '3/4', 'g'], ['berry', '5/4', 'tsp'], ['egg', '3/4', 'tsp'], ['flour', '1', 'kg'], ['flour', '4/3', 'tbsp'], ['grape', '3', 'each'], ['tomato', '2', 'g'], ['tomato', '5/6', 'tsp']]Passed
repair check: -oes plural rule[['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']][['berry', '2', 'kg'], ['grape', '2', 'each'], ['grape', '125/64', 'cup'], ['tomato', '1/4', 'g'], ['watercress', '5/4', 'tsp']]Passed
generated control 1[['tomato', '3/4', 'tsp']][['tomato', '3/4', 'tsp']]Passed
generated control 2[['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']][['berry', '3/4', 'each'], ['berry', '1/3', 'tsp'], ['egg', '1/4', 'each'], ['flour', '4', 'g'], ['grape', '1/2', 'tsp'], ['pea', '3', 'g'], ['potato', '4/3', 'tbsp'], ['watercress', '1/3', 'tsp']]Passed
generated control 3[['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']][['berry', '3/4', 'tsp'], ['potato', '1/4', 'each'], ['potato', '1/4', 'cup'], ['watercress', '2', 'each'], ['watercress', '750', 'g'], ['watercress', '1/2', 'cup']]Passed

SHA-256 / da3cf32ab4e267db5f6fe65bb549e3e466ea5991ed561ac7332aea78e269cc5d

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

Case digest / 48af0eae452e3edfbfbbd4b9ef2f553271e3c987d2853b16f8ff211bddee9c29