FA-96856 / Recipe scaling and nutrition / Open access
Servings scaler: countable floor of one · case 01
Scaling one egg for eight down to one serving lists 0 eggs.
ROOT CAUSE
The rounded count is emitted without the minimum of one whole item.
VERIFIED REPAIR
Clamp countable rows to at least 1.
Unsuccessful approach: Clamping only rows that started at one or more still prints 0 for a half lime scaled down.
Case contract
Scale [name, qty, unit, kind] rows from base to target servings. Factor f=target/base (both must be positive, else an error string). Seasoning rows scale by 1+(f-1)*3/4 (damped); other rows by f. Unit "each" rounds half-up to an integer with a floor of 1. Other units round half-up to the nearest 1/8 and print as reduced kitchen fractions ("1 1/2", "3/4", "2"); a zero result prints "pinch".
Why this case matters
Home and commercial recipe scalers must keep countable items whole and print measurable fractions cooks can actually portion.
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, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = math.gcd(rem, 8)
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(n), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: countable floor of one',
[[['pepper', '1', 'tsp', 'seasoning'], ['egg', '4', 'each', 'base'], ['lime', '1', 'each', 'base'],
['milk', '1/2', 'cup', 'base']],
8, 1],
[['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']]],
['repair check: countable floor of one',
[[['cumin', '5/2', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base']], 6, 2],
[['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']]],
['generated control 1',
[[['egg', '5', 'each', 'base'], ['milk', '3/2', 'cup', 'base'], ['cumin', '1/2', 'tsp', 'seasoning']], 6,
3],
[['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']]],
['generated control 2',
[[['pepper', '3', 'tsp', 'seasoning'], ['salt', '3/2', 'tsp', 'seasoning'],
['garlic clove', '3', 'each', 'base'], ['butter', '2/3', 'tbsp', 'base'], ['milk', '3', 'cup', 'base']],
6, 4],
[['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'],
['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']]],
['generated control 3',
[[['lime', '5', 'each', 'base'], ['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '1/2', 'tbsp', 'base'],
['cumin', '1/3', 'tsp', 'seasoning']],
6, 1],
[['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: countable floor of one',
[[['cumin', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['lime', '1/2', 'each', 'base'], ['milk', '2/3', 'cup', 'base'], ['garlic clove', '1', 'each', 'base']],
4, 3],
[['cumin', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['lime', '1', 'each'], ['milk', '1/2', 'cup'],
['garlic clove', '1', 'each']]],
['repair check: countable floor of one',
[[['lime', '1/2', 'each', 'base'], ['egg', '1', 'each', 'base'], ['garlic clove', '4', 'each', 'base']], 6,
5],
[['lime', '1', 'each'], ['egg', '1', 'each'], ['garlic clove', '3', 'each']]],
['generated control 1',
[[['egg', '3', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base']], 8, 4],
[['egg', '2', 'each'], ['flour', '1/8', 'cup'], ['butter', '3/4', 'tbsp']]],
['generated control 2', [[['flour', '9/4', 'cup', 'base'], ['pepper', '9/4', 'tsp', 'seasoning']], 4, 10],
[['flour', '5 5/8', 'cup'], ['pepper', '4 3/4', 'tsp']]],
['generated control 3', [[['egg', '3', 'each', 'base'], ['salt', '1/8', 'tsp', 'seasoning']], 7, 4],
[['egg', '2', 'each'], ['salt', '1/8', 'tsp']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['pepper', '2', 'tsp', 'seasoning'],
['lime', '5', 'each', 'base'], ['egg', '1/2', 'each', 'base']],
6, 1],
[['garlic clove', '1', 'each'], ['pepper', '3/4', 'tsp'], ['lime', '1', 'each'], ['egg', '1', 'each']]],
['repair check: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['salt', '3', 'tsp', 'seasoning'], ['egg', '1', 'each', 'base'],
['lime', '1/2', 'each', 'base'], ['flour', '1/4', 'cup', 'base']],
7, 6],
[['garlic clove', '2', 'each'], ['salt', '2 5/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'],
['flour', '1/4', 'cup']]],
['generated control 1',
[[['pepper', '1', 'tsp', 'seasoning'], ['flour', '3/2', 'cup', 'base'], ['milk', '2/3', 'cup', 'base'],
['salt', '3/4', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']],
6, 6],
[['pepper', '1', 'tsp'], ['flour', '1 1/2', 'cup'], ['milk', '5/8', 'cup'], ['salt', '3/4', 'tsp'],
['garlic clove', '2', 'each']]],
['generated control 2',
[[['salt', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['flour', '1/3', 'cup', 'base']],
5, 2],
[['salt', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['flour', '1/8', 'cup']]],
['generated control 3',
[[['salt', '1/8', 'tsp', 'seasoning'], ['cumin', '1', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
['garlic clove', '1', 'each', 'base']],
3, 9],
[['salt', '3/8', 'tsp'], ['cumin', '2 1/2', 'tsp'], ['milk', '7 1/2', 'cup'],
['garlic clove', '3', 'each']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '1/2', 'each', 'base'], ['butter', '3/2', 'tbsp', 'base'],
['salt', '9/4', 'tsp', 'seasoning'], ['cumin', '2', 'tsp', 'seasoning']],
6, 2],
[['garlic clove', '1', 'each'], ['butter', '1/2', 'tbsp'], ['salt', '1 1/8', 'tsp'],
['cumin', '1', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['salt', '3/2', 'tsp', 'seasoning'],
['pepper', '5/2', 'tsp', 'seasoning']],
4, 3],
[['egg', '1', 'each'], ['salt', '1 1/4', 'tsp'], ['pepper', '2', 'tsp']]],
['generated control 1',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '1', 'each', 'base'], ['milk', '2/3', 'cup', 'base'],
['egg', '4', 'each', 'base'], ['flour', '3/4', 'cup', 'base']],
6, 3],
[['salt', '3/8', 'tsp'], ['lime', '1', 'each'], ['milk', '3/8', 'cup'], ['egg', '2', 'each'],
['flour', '3/8', 'cup']]],
['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['egg', '1/2', 'each', 'base']], 7, 9],
[['butter', '3 1/4', 'tbsp'], ['egg', '1', 'each']]],
['generated control 3', [[['salt', '1', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']], 6, 7],
[['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: countable floor of one',
[[['garlic clove', '1', 'each', 'base'], ['milk', '5/2', 'cup', 'base'], ['flour', '3', 'cup', 'base'],
['cumin', '1', 'tsp', 'seasoning'], ['salt', '3', 'tsp', 'seasoning']],
4, 1],
[['garlic clove', '1', 'each'], ['milk', '5/8', 'cup'], ['flour', '3/4', 'cup'], ['cumin', '1/2', 'tsp'],
['salt', '1 3/8', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '4', 'each', 'base'],
['salt', '1/3', 'tsp', 'seasoning']],
5, 3],
[['egg', '1', 'each'], ['garlic clove', '2', 'each'], ['salt', '1/4', 'tsp']]],
['generated control 1',
[[['butter', '3/4', 'tbsp', 'base'], ['egg', '4', 'each', 'base'], ['pepper', '1/3', 'tsp', 'seasoning']],
8, 11],
[['butter', '1', 'tbsp'], ['egg', '6', 'each'], ['pepper', '3/8', 'tsp']]],
['generated control 2', [[['lime', '5', 'each', 'base'], ['cumin', '1', 'tsp', 'seasoning']], 3, 8],
[['lime', '13', 'each'], ['cumin', '2 1/4', 'tsp']]],
['generated control 3',
[[['pepper', '9/4', 'tsp', 'seasoning'], ['egg', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']],
2, 6],
[['pepper', '5 5/8', 'tsp'], ['egg', '2', 'each'], ['flour', '4 1/2', 'cup']]]]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Passed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Passed |
| regression: countable floor of one | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '0', 'each'], ['milk', '1/8', 'cup']] | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']] | Failed |
| repair check: countable floor of one | [['cumin', '1 1/4', 'tsp'], ['lime', '0', 'each']] | [['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']] | Failed |
| generated control 1 | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | Passed |
| generated control 2 | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | Passed |
| generated control 3 | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | Passed |
SHA-256 / 0cdd1be11c3f05719588f96b5ffcf7a8c721e9512c6d57c983b1e982f99a901b
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, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = math.gcd(rem, 8)
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(max(1, n) if q >= 1 else n), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: countable floor of one',
[[['pepper', '1', 'tsp', 'seasoning'], ['egg', '4', 'each', 'base'], ['lime', '1', 'each', 'base'],
['milk', '1/2', 'cup', 'base']],
8, 1],
[['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']]],
['repair check: countable floor of one',
[[['cumin', '5/2', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base']], 6, 2],
[['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']]],
['generated control 1',
[[['egg', '5', 'each', 'base'], ['milk', '3/2', 'cup', 'base'], ['cumin', '1/2', 'tsp', 'seasoning']], 6,
3],
[['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']]],
['generated control 2',
[[['pepper', '3', 'tsp', 'seasoning'], ['salt', '3/2', 'tsp', 'seasoning'],
['garlic clove', '3', 'each', 'base'], ['butter', '2/3', 'tbsp', 'base'], ['milk', '3', 'cup', 'base']],
6, 4],
[['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'],
['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']]],
['generated control 3',
[[['lime', '5', 'each', 'base'], ['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '1/2', 'tbsp', 'base'],
['cumin', '1/3', 'tsp', 'seasoning']],
6, 1],
[['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: countable floor of one',
[[['cumin', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['lime', '1/2', 'each', 'base'], ['milk', '2/3', 'cup', 'base'], ['garlic clove', '1', 'each', 'base']],
4, 3],
[['cumin', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['lime', '1', 'each'], ['milk', '1/2', 'cup'],
['garlic clove', '1', 'each']]],
['repair check: countable floor of one',
[[['lime', '1/2', 'each', 'base'], ['egg', '1', 'each', 'base'], ['garlic clove', '4', 'each', 'base']], 6,
5],
[['lime', '1', 'each'], ['egg', '1', 'each'], ['garlic clove', '3', 'each']]],
['generated control 1',
[[['egg', '3', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base']], 8, 4],
[['egg', '2', 'each'], ['flour', '1/8', 'cup'], ['butter', '3/4', 'tbsp']]],
['generated control 2', [[['flour', '9/4', 'cup', 'base'], ['pepper', '9/4', 'tsp', 'seasoning']], 4, 10],
[['flour', '5 5/8', 'cup'], ['pepper', '4 3/4', 'tsp']]],
['generated control 3', [[['egg', '3', 'each', 'base'], ['salt', '1/8', 'tsp', 'seasoning']], 7, 4],
[['egg', '2', 'each'], ['salt', '1/8', 'tsp']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['pepper', '2', 'tsp', 'seasoning'],
['lime', '5', 'each', 'base'], ['egg', '1/2', 'each', 'base']],
6, 1],
[['garlic clove', '1', 'each'], ['pepper', '3/4', 'tsp'], ['lime', '1', 'each'], ['egg', '1', 'each']]],
['repair check: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['salt', '3', 'tsp', 'seasoning'], ['egg', '1', 'each', 'base'],
['lime', '1/2', 'each', 'base'], ['flour', '1/4', 'cup', 'base']],
7, 6],
[['garlic clove', '2', 'each'], ['salt', '2 5/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'],
['flour', '1/4', 'cup']]],
['generated control 1',
[[['pepper', '1', 'tsp', 'seasoning'], ['flour', '3/2', 'cup', 'base'], ['milk', '2/3', 'cup', 'base'],
['salt', '3/4', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']],
6, 6],
[['pepper', '1', 'tsp'], ['flour', '1 1/2', 'cup'], ['milk', '5/8', 'cup'], ['salt', '3/4', 'tsp'],
['garlic clove', '2', 'each']]],
['generated control 2',
[[['salt', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['flour', '1/3', 'cup', 'base']],
5, 2],
[['salt', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['flour', '1/8', 'cup']]],
['generated control 3',
[[['salt', '1/8', 'tsp', 'seasoning'], ['cumin', '1', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
['garlic clove', '1', 'each', 'base']],
3, 9],
[['salt', '3/8', 'tsp'], ['cumin', '2 1/2', 'tsp'], ['milk', '7 1/2', 'cup'],
['garlic clove', '3', 'each']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '1/2', 'each', 'base'], ['butter', '3/2', 'tbsp', 'base'],
['salt', '9/4', 'tsp', 'seasoning'], ['cumin', '2', 'tsp', 'seasoning']],
6, 2],
[['garlic clove', '1', 'each'], ['butter', '1/2', 'tbsp'], ['salt', '1 1/8', 'tsp'],
['cumin', '1', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['salt', '3/2', 'tsp', 'seasoning'],
['pepper', '5/2', 'tsp', 'seasoning']],
4, 3],
[['egg', '1', 'each'], ['salt', '1 1/4', 'tsp'], ['pepper', '2', 'tsp']]],
['generated control 1',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '1', 'each', 'base'], ['milk', '2/3', 'cup', 'base'],
['egg', '4', 'each', 'base'], ['flour', '3/4', 'cup', 'base']],
6, 3],
[['salt', '3/8', 'tsp'], ['lime', '1', 'each'], ['milk', '3/8', 'cup'], ['egg', '2', 'each'],
['flour', '3/8', 'cup']]],
['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['egg', '1/2', 'each', 'base']], 7, 9],
[['butter', '3 1/4', 'tbsp'], ['egg', '1', 'each']]],
['generated control 3', [[['salt', '1', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']], 6, 7],
[['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: countable floor of one',
[[['garlic clove', '1', 'each', 'base'], ['milk', '5/2', 'cup', 'base'], ['flour', '3', 'cup', 'base'],
['cumin', '1', 'tsp', 'seasoning'], ['salt', '3', 'tsp', 'seasoning']],
4, 1],
[['garlic clove', '1', 'each'], ['milk', '5/8', 'cup'], ['flour', '3/4', 'cup'], ['cumin', '1/2', 'tsp'],
['salt', '1 3/8', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '4', 'each', 'base'],
['salt', '1/3', 'tsp', 'seasoning']],
5, 3],
[['egg', '1', 'each'], ['garlic clove', '2', 'each'], ['salt', '1/4', 'tsp']]],
['generated control 1',
[[['butter', '3/4', 'tbsp', 'base'], ['egg', '4', 'each', 'base'], ['pepper', '1/3', 'tsp', 'seasoning']],
8, 11],
[['butter', '1', 'tbsp'], ['egg', '6', 'each'], ['pepper', '3/8', 'tsp']]],
['generated control 2', [[['lime', '5', 'each', 'base'], ['cumin', '1', 'tsp', 'seasoning']], 3, 8],
[['lime', '13', 'each'], ['cumin', '2 1/4', 'tsp']]],
['generated control 3',
[[['pepper', '9/4', 'tsp', 'seasoning'], ['egg', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']],
2, 6],
[['pepper', '5 5/8', 'tsp'], ['egg', '2', 'each'], ['flour', '4 1/2', 'cup']]]]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Passed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Passed |
| regression: countable floor of one | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']] | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']] | Passed |
| repair check: countable floor of one | [['cumin', '1 1/4', 'tsp'], ['lime', '0', 'each']] | [['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']] | Failed |
| generated control 1 | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | Passed |
| generated control 2 | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | Passed |
| generated control 3 | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | Passed |
SHA-256 / 1949c8e4be9c7db792281cfe7bcabdd8cbd42ba57227618e4ac1eadc57634ae7
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, base, target):
if base <= 0 or target <= 0:
return 'error: servings must be positive'
f = Fraction(target, base)
def fmt(e):
if e == 0:
return 'pinch'
whole, rem = divmod(e, 8)
if rem == 0:
return str(whole)
g = math.gcd(rem, 8)
frac = '%d/%d' % (rem // g, 8 // g)
return frac if whole == 0 else '%d %s' % (whole, frac)
out = []
for name, qty, unit, kind in items:
q = Fraction(qty)
if kind == 'seasoning':
s = q * (1 + (f - 1) * Fraction(3, 4))
else:
s = q * f
if unit == 'each':
n = int(s) + (1 if s - int(s) >= Fraction(1, 2) else 0)
out.append([name, str(max(1, n)), unit])
else:
e = int(s * 8 + Fraction(1, 2))
out.append([name, fmt(e), unit])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['regression: countable floor of one',
[[['pepper', '1', 'tsp', 'seasoning'], ['egg', '4', 'each', 'base'], ['lime', '1', 'each', 'base'],
['milk', '1/2', 'cup', 'base']],
8, 1],
[['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']]],
['repair check: countable floor of one',
[[['cumin', '5/2', 'tsp', 'seasoning'], ['lime', '1/2', 'each', 'base']], 6, 2],
[['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']]],
['generated control 1',
[[['egg', '5', 'each', 'base'], ['milk', '3/2', 'cup', 'base'], ['cumin', '1/2', 'tsp', 'seasoning']], 6,
3],
[['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']]],
['generated control 2',
[[['pepper', '3', 'tsp', 'seasoning'], ['salt', '3/2', 'tsp', 'seasoning'],
['garlic clove', '3', 'each', 'base'], ['butter', '2/3', 'tbsp', 'base'], ['milk', '3', 'cup', 'base']],
6, 4],
[['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'],
['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']]],
['generated control 3',
[[['lime', '5', 'each', 'base'], ['pepper', '1/8', 'tsp', 'seasoning'], ['butter', '1/2', 'tbsp', 'base'],
['cumin', '1/3', 'tsp', 'seasoning']],
6, 1],
[['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']]]],
[['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['regression: countable floor of one',
[[['cumin', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['lime', '1/2', 'each', 'base'], ['milk', '2/3', 'cup', 'base'], ['garlic clove', '1', 'each', 'base']],
4, 3],
[['cumin', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['lime', '1', 'each'], ['milk', '1/2', 'cup'],
['garlic clove', '1', 'each']]],
['repair check: countable floor of one',
[[['lime', '1/2', 'each', 'base'], ['egg', '1', 'each', 'base'], ['garlic clove', '4', 'each', 'base']], 6,
5],
[['lime', '1', 'each'], ['egg', '1', 'each'], ['garlic clove', '3', 'each']]],
['generated control 1',
[[['egg', '3', 'each', 'base'], ['flour', '1/3', 'cup', 'base'], ['butter', '3/2', 'tbsp', 'base']], 8, 4],
[['egg', '2', 'each'], ['flour', '1/8', 'cup'], ['butter', '3/4', 'tbsp']]],
['generated control 2', [[['flour', '9/4', 'cup', 'base'], ['pepper', '9/4', 'tsp', 'seasoning']], 4, 10],
[['flour', '5 5/8', 'cup'], ['pepper', '4 3/4', 'tsp']]],
['generated control 3', [[['egg', '3', 'each', 'base'], ['salt', '1/8', 'tsp', 'seasoning']], 7, 4],
[['egg', '2', 'each'], ['salt', '1/8', 'tsp']]]],
[['double batch with seasoning', [[['salt', '1', 'tsp', 'seasoning'], ['egg', '3', 'each', 'base']], 4, 8],
[['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']]],
['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['pepper', '2', 'tsp', 'seasoning'],
['lime', '5', 'each', 'base'], ['egg', '1/2', 'each', 'base']],
6, 1],
[['garlic clove', '1', 'each'], ['pepper', '3/4', 'tsp'], ['lime', '1', 'each'], ['egg', '1', 'each']]],
['repair check: countable floor of one',
[[['garlic clove', '2', 'each', 'base'], ['salt', '3', 'tsp', 'seasoning'], ['egg', '1', 'each', 'base'],
['lime', '1/2', 'each', 'base'], ['flour', '1/4', 'cup', 'base']],
7, 6],
[['garlic clove', '2', 'each'], ['salt', '2 5/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'],
['flour', '1/4', 'cup']]],
['generated control 1',
[[['pepper', '1', 'tsp', 'seasoning'], ['flour', '3/2', 'cup', 'base'], ['milk', '2/3', 'cup', 'base'],
['salt', '3/4', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']],
6, 6],
[['pepper', '1', 'tsp'], ['flour', '1 1/2', 'cup'], ['milk', '5/8', 'cup'], ['salt', '3/4', 'tsp'],
['garlic clove', '2', 'each']]],
['generated control 2',
[[['salt', '1/8', 'tsp', 'seasoning'], ['pepper', '1/8', 'tsp', 'seasoning'],
['flour', '1/3', 'cup', 'base']],
5, 2],
[['salt', '1/8', 'tsp'], ['pepper', '1/8', 'tsp'], ['flour', '1/8', 'cup']]],
['generated control 3',
[[['salt', '1/8', 'tsp', 'seasoning'], ['cumin', '1', 'tsp', 'seasoning'], ['milk', '5/2', 'cup', 'base'],
['garlic clove', '1', 'each', 'base']],
3, 9],
[['salt', '3/8', 'tsp'], ['cumin', '2 1/2', 'tsp'], ['milk', '7 1/2', 'cup'],
['garlic clove', '3', 'each']]]],
[['tiny scale-down to pinch', [[['cumin', '1/8', 'tsp', 'base'], ['egg', '1', 'each', 'base']], 8, 1],
[['cumin', 'pinch', 'tsp'], ['egg', '1', 'each']]],
['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['regression: countable floor of one',
[[['garlic clove', '1/2', 'each', 'base'], ['butter', '3/2', 'tbsp', 'base'],
['salt', '9/4', 'tsp', 'seasoning'], ['cumin', '2', 'tsp', 'seasoning']],
6, 2],
[['garlic clove', '1', 'each'], ['butter', '1/2', 'tbsp'], ['salt', '1 1/8', 'tsp'],
['cumin', '1', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['salt', '3/2', 'tsp', 'seasoning'],
['pepper', '5/2', 'tsp', 'seasoning']],
4, 3],
[['egg', '1', 'each'], ['salt', '1 1/4', 'tsp'], ['pepper', '2', 'tsp']]],
['generated control 1',
[[['salt', '2/3', 'tsp', 'seasoning'], ['lime', '1', 'each', 'base'], ['milk', '2/3', 'cup', 'base'],
['egg', '4', 'each', 'base'], ['flour', '3/4', 'cup', 'base']],
6, 3],
[['salt', '3/8', 'tsp'], ['lime', '1', 'each'], ['milk', '3/8', 'cup'], ['egg', '2', 'each'],
['flour', '3/8', 'cup']]],
['generated control 2', [[['butter', '5/2', 'tbsp', 'base'], ['egg', '1/2', 'each', 'base']], 7, 9],
[['butter', '3 1/4', 'tbsp'], ['egg', '1', 'each']]],
['generated control 3', [[['salt', '1', 'tsp', 'seasoning'], ['garlic clove', '2', 'each', 'base']], 6, 7],
[['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each']]]],
[['half egg rounds up', [[['egg', '3', 'each', 'base'], ['milk', '1/2', 'cup', 'base']], 4, 6],
[['egg', '5', 'each'], ['milk', '3/4', 'cup']]],
['identity scaling control', [[['egg', '2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']], 4, 4],
[['egg', '2', 'each'], ['flour', '1 1/2', 'cup']]],
['zero servings rejected', [[['egg', '2', 'each', 'base']], 0, 4], 'error: servings must be positive'],
['regression: countable floor of one',
[[['garlic clove', '1', 'each', 'base'], ['milk', '5/2', 'cup', 'base'], ['flour', '3', 'cup', 'base'],
['cumin', '1', 'tsp', 'seasoning'], ['salt', '3', 'tsp', 'seasoning']],
4, 1],
[['garlic clove', '1', 'each'], ['milk', '5/8', 'cup'], ['flour', '3/4', 'cup'], ['cumin', '1/2', 'tsp'],
['salt', '1 3/8', 'tsp']]],
['repair check: countable floor of one',
[[['egg', '1/2', 'each', 'base'], ['garlic clove', '4', 'each', 'base'],
['salt', '1/3', 'tsp', 'seasoning']],
5, 3],
[['egg', '1', 'each'], ['garlic clove', '2', 'each'], ['salt', '1/4', 'tsp']]],
['generated control 1',
[[['butter', '3/4', 'tbsp', 'base'], ['egg', '4', 'each', 'base'], ['pepper', '1/3', 'tsp', 'seasoning']],
8, 11],
[['butter', '1', 'tbsp'], ['egg', '6', 'each'], ['pepper', '3/8', 'tsp']]],
['generated control 2', [[['lime', '5', 'each', 'base'], ['cumin', '1', 'tsp', 'seasoning']], 3, 8],
[['lime', '13', 'each'], ['cumin', '2 1/4', 'tsp']]],
['generated control 3',
[[['pepper', '9/4', 'tsp', 'seasoning'], ['egg', '1/2', 'each', 'base'], ['flour', '3/2', 'cup', 'base']],
2, 6],
[['pepper', '5 5/8', 'tsp'], ['egg', '2', 'each'], ['flour', '4 1/2', 'cup']]]]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| identity scaling control | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | [['egg', '2', 'each'], ['flour', '1 1/2', 'cup']] | Passed |
| zero servings rejected | error: servings must be positive | error: servings must be positive | Passed |
| double batch with seasoning | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | [['salt', '1 3/4', 'tsp'], ['egg', '6', 'each']] | Passed |
| regression: countable floor of one | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']] | [['pepper', '3/8', 'tsp'], ['egg', '1', 'each'], ['lime', '1', 'each'], ['milk', '1/8', 'cup']] | Passed |
| repair check: countable floor of one | [['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']] | [['cumin', '1 1/4', 'tsp'], ['lime', '1', 'each']] | Passed |
| generated control 1 | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | [['egg', '3', 'each'], ['milk', '3/4', 'cup'], ['cumin', '3/8', 'tsp']] | Passed |
| generated control 2 | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | [['pepper', '2 1/4', 'tsp'], ['salt', '1 1/8', 'tsp'], ['garlic clove', '2', 'each'], ['butter', '1/2', 'tbsp'], ['milk', '2', 'cup']] | Passed |
| generated control 3 | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | [['lime', '1', 'each'], ['pepper', 'pinch', 'tsp'], ['butter', '1/8', 'tbsp'], ['cumin', '1/8', 'tsp']] | Passed |
SHA-256 / c541becbf92c001396167be4754515bbc94fbba336ddf5165c08884ba1e209be
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:26.504963+00:00.
Case digest / a80f5831538c83d911dfd2ceecce901a3336e67e3cf254ebff778aaf306b0125