FA-97591 / Knitting and sewing pattern grading / Open access
Cutting layout fabric length: yardage rounding · case 01
Buying the rounded yardage leaves the layout a few cm short.
ROOT CAUSE
Eighths of a yard are rounded to nearest instead of up.
VERIFIED REPAIR
Round eighths up.
Unsuccessful approach: A 90 cm "yard" overstates yardage.
Case contract
Pieces [w, h, qty] (cm; w across the fabric). A piece wider than the fabric is rotated if the fabric is not directional and its height fits, else "error: piece too wide". Expand qty, sort by (height, width) descending, then shelf-pack: start a new row when the row width plus the piece would exceed the fabric width; each row is as tall as its tallest piece. Return [length_cm, eighths_of_a_yard] with eighths = ceiling(length/91.44*8).
Why this case matters
Pattern envelopes and cutting planners estimate yardage from piece layouts and nap direction.
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(pieces, width, directional):
items = []
for w, h, qty in pieces:
for _ in range(qty):
if w > width:
if directional or h > width:
return 'error: piece too wide'
w, h = h, w
items.append((h, w))
items.sort(reverse=True)
length = 0
row_w = 0
row_h = 0
for h, w in items:
if row_w + w > width:
length += row_h
row_w, row_h = 0, 0
row_w += w
row_h = max(row_h, h)
length += row_h
return [length, math.floor(Fraction(length) / Fraction(9144, 100) * 8 + Fraction(1, 2))]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[35, 45, 3], [70, 45, 3], [40, 100, 3], [70, 100, 2]], 150, False],
[335, 30]],
['repair check: yardage rounding', [[[55, 80, 1], [20, 30, 2]], 140, False], [80, 7]],
['generated control 1', [[[150, 45, 1], [20, 60, 3]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 60, 3], [110, 60, 1], [70, 45, 3], [40, 100, 1]], 150, False], [265, 24]],
['generated control 3', [[[35, 100, 1], [55, 80, 1]], 140, True], [100, 9]]],
[['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['regression: yardage rounding', [[[110, 60, 1], [35, 100, 2], [110, 80, 2], [55, 60, 2]], 140, False],
[380, 34]],
['repair check: yardage rounding', [[[40, 60, 1], [70, 45, 3], [40, 45, 3], [40, 80, 1]], 140, False],
[215, 19]],
['generated control 1', [[[35, 60, 2], [20, 60, 3], [150, 45, 1], [55, 45, 2]], 140, False], [255, 23]],
['generated control 2', [[[55, 30, 2], [110, 80, 2]], 150, False], [190, 17]],
['generated control 3', [[[150, 30, 1], [55, 45, 1]], 140, False], [150, 14]]],
[['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['regression: yardage rounding', [[[40, 60, 1], [70, 100, 1], [35, 100, 1], [150, 60, 2]], 150, False],
[280, 25]],
['repair check: yardage rounding', [[[150, 45, 1], [20, 80, 1], [110, 100, 2], [110, 80, 2]], 140, False],
[510, 45]],
['generated control 1', [[[150, 30, 1], [20, 100, 1]], 110, False], [150, 14]],
['generated control 2', [[[35, 100, 1], [150, 100, 1]], 150, True], [200, 18]],
['generated control 3', [[[40, 100, 1]], 140, False], [100, 9]]],
[['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['regression: yardage rounding', [[[40, 60, 2]], 150, False], [60, 6]],
['repair check: yardage rounding', [[[40, 80, 3]], 110, False], [160, 14]],
['generated control 1', [[[55, 45, 1]], 110, True], [45, 4]],
['generated control 2', [[[35, 45, 3]], 150, False], [45, 4]],
['generated control 3', [[[70, 100, 2], [110, 45, 1], [150, 80, 1]], 110, True], 'error: piece too wide']],
[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[150, 100, 1], [110, 60, 1], [55, 80, 1], [55, 100, 3]], 150, False],
[360, 32]],
['repair check: yardage rounding', [[[110, 80, 1]], 110, False], [80, 7]],
['generated control 1', [[[110, 100, 3], [40, 60, 1], [40, 60, 3], [110, 100, 1]], 150, False], [460, 41]],
['generated control 2', [[[70, 30, 2], [20, 80, 1], [150, 100, 1], [20, 80, 1]], 150, False], [210, 19]],
['generated control 3', [[[35, 45, 1]], 110, False], [45, 4]]]]
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 |
|---|---|---|---|
| two pieces one row | [60, 5] | [60, 6] | Failed |
| rotate wide piece | [150, 13] | [150, 14] | Failed |
| directional wide piece | error: piece too wide | error: piece too wide | Passed |
| regression: yardage rounding | [335, 29] | [335, 30] | Failed |
| repair check: yardage rounding | [80, 7] | [80, 7] | Passed |
| generated control 1 | error: piece too wide | error: piece too wide | Passed |
| generated control 2 | [265, 23] | [265, 24] | Failed |
| generated control 3 | [100, 9] | [100, 9] | Passed |
SHA-256 / cfec83d5997d1038fbe7cdb81b508005ec09d584fbe01be62f8c9e5582b4f88e
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(pieces, width, directional):
items = []
for w, h, qty in pieces:
for _ in range(qty):
if w > width:
if directional or h > width:
return 'error: piece too wide'
w, h = h, w
items.append((h, w))
items.sort(reverse=True)
length = 0
row_w = 0
row_h = 0
for h, w in items:
if row_w + w > width:
length += row_h
row_w, row_h = 0, 0
row_w += w
row_h = max(row_h, h)
length += row_h
return [length, math.ceil(Fraction(length) / 90 * 8)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[35, 45, 3], [70, 45, 3], [40, 100, 3], [70, 100, 2]], 150, False],
[335, 30]],
['repair check: yardage rounding', [[[55, 80, 1], [20, 30, 2]], 140, False], [80, 7]],
['generated control 1', [[[150, 45, 1], [20, 60, 3]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 60, 3], [110, 60, 1], [70, 45, 3], [40, 100, 1]], 150, False], [265, 24]],
['generated control 3', [[[35, 100, 1], [55, 80, 1]], 140, True], [100, 9]]],
[['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['regression: yardage rounding', [[[110, 60, 1], [35, 100, 2], [110, 80, 2], [55, 60, 2]], 140, False],
[380, 34]],
['repair check: yardage rounding', [[[40, 60, 1], [70, 45, 3], [40, 45, 3], [40, 80, 1]], 140, False],
[215, 19]],
['generated control 1', [[[35, 60, 2], [20, 60, 3], [150, 45, 1], [55, 45, 2]], 140, False], [255, 23]],
['generated control 2', [[[55, 30, 2], [110, 80, 2]], 150, False], [190, 17]],
['generated control 3', [[[150, 30, 1], [55, 45, 1]], 140, False], [150, 14]]],
[['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['regression: yardage rounding', [[[40, 60, 1], [70, 100, 1], [35, 100, 1], [150, 60, 2]], 150, False],
[280, 25]],
['repair check: yardage rounding', [[[150, 45, 1], [20, 80, 1], [110, 100, 2], [110, 80, 2]], 140, False],
[510, 45]],
['generated control 1', [[[150, 30, 1], [20, 100, 1]], 110, False], [150, 14]],
['generated control 2', [[[35, 100, 1], [150, 100, 1]], 150, True], [200, 18]],
['generated control 3', [[[40, 100, 1]], 140, False], [100, 9]]],
[['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['regression: yardage rounding', [[[40, 60, 2]], 150, False], [60, 6]],
['repair check: yardage rounding', [[[40, 80, 3]], 110, False], [160, 14]],
['generated control 1', [[[55, 45, 1]], 110, True], [45, 4]],
['generated control 2', [[[35, 45, 3]], 150, False], [45, 4]],
['generated control 3', [[[70, 100, 2], [110, 45, 1], [150, 80, 1]], 110, True], 'error: piece too wide']],
[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[150, 100, 1], [110, 60, 1], [55, 80, 1], [55, 100, 3]], 150, False],
[360, 32]],
['repair check: yardage rounding', [[[110, 80, 1]], 110, False], [80, 7]],
['generated control 1', [[[110, 100, 3], [40, 60, 1], [40, 60, 3], [110, 100, 1]], 150, False], [460, 41]],
['generated control 2', [[[70, 30, 2], [20, 80, 1], [150, 100, 1], [20, 80, 1]], 150, False], [210, 19]],
['generated control 3', [[[35, 45, 1]], 110, False], [45, 4]]]]
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 |
|---|---|---|---|
| two pieces one row | [60, 6] | [60, 6] | Passed |
| rotate wide piece | [150, 14] | [150, 14] | Passed |
| directional wide piece | error: piece too wide | error: piece too wide | Passed |
| regression: yardage rounding | [335, 30] | [335, 30] | Passed |
| repair check: yardage rounding | [80, 8] | [80, 7] | Failed |
| generated control 1 | error: piece too wide | error: piece too wide | Passed |
| generated control 2 | [265, 24] | [265, 24] | Passed |
| generated control 3 | [100, 9] | [100, 9] | Passed |
SHA-256 / c1d12be9dcf997998952eab0a0400aec8e07d5c244ef7944c51e4b9002ba17c5
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(pieces, width, directional):
items = []
for w, h, qty in pieces:
for _ in range(qty):
if w > width:
if directional or h > width:
return 'error: piece too wide'
w, h = h, w
items.append((h, w))
items.sort(reverse=True)
length = 0
row_w = 0
row_h = 0
for h, w in items:
if row_w + w > width:
length += row_h
row_w, row_h = 0, 0
row_w += w
row_h = max(row_h, h)
length += row_h
return [length, math.ceil(Fraction(length) / Fraction(9144, 100) * 8)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[35, 45, 3], [70, 45, 3], [40, 100, 3], [70, 100, 2]], 150, False],
[335, 30]],
['repair check: yardage rounding', [[[55, 80, 1], [20, 30, 2]], 140, False], [80, 7]],
['generated control 1', [[[150, 45, 1], [20, 60, 3]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 60, 3], [110, 60, 1], [70, 45, 3], [40, 100, 1]], 150, False], [265, 24]],
['generated control 3', [[[35, 100, 1], [55, 80, 1]], 140, True], [100, 9]]],
[['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['regression: yardage rounding', [[[110, 60, 1], [35, 100, 2], [110, 80, 2], [55, 60, 2]], 140, False],
[380, 34]],
['repair check: yardage rounding', [[[40, 60, 1], [70, 45, 3], [40, 45, 3], [40, 80, 1]], 140, False],
[215, 19]],
['generated control 1', [[[35, 60, 2], [20, 60, 3], [150, 45, 1], [55, 45, 2]], 140, False], [255, 23]],
['generated control 2', [[[55, 30, 2], [110, 80, 2]], 150, False], [190, 17]],
['generated control 3', [[[150, 30, 1], [55, 45, 1]], 140, False], [150, 14]]],
[['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['regression: yardage rounding', [[[40, 60, 1], [70, 100, 1], [35, 100, 1], [150, 60, 2]], 150, False],
[280, 25]],
['repair check: yardage rounding', [[[150, 45, 1], [20, 80, 1], [110, 100, 2], [110, 80, 2]], 140, False],
[510, 45]],
['generated control 1', [[[150, 30, 1], [20, 100, 1]], 110, False], [150, 14]],
['generated control 2', [[[35, 100, 1], [150, 100, 1]], 150, True], [200, 18]],
['generated control 3', [[[40, 100, 1]], 140, False], [100, 9]]],
[['exact fit row', [[[55, 80, 2], [40, 45, 1]], 150, False], [80, 7]],
['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['regression: yardage rounding', [[[40, 60, 2]], 150, False], [60, 6]],
['repair check: yardage rounding', [[[40, 80, 3]], 110, False], [160, 14]],
['generated control 1', [[[55, 45, 1]], 110, True], [45, 4]],
['generated control 2', [[[35, 45, 3]], 150, False], [45, 4]],
['generated control 3', [[[70, 100, 2], [110, 45, 1], [150, 80, 1]], 110, True], 'error: piece too wide']],
[['two pieces one row', [[[70, 60, 2]], 140, False], [60, 6]],
['rotate wide piece', [[[150, 60, 1]], 140, False], [150, 14]],
['directional wide piece', [[[150, 60, 1]], 140, True], 'error: piece too wide'],
['regression: yardage rounding', [[[150, 100, 1], [110, 60, 1], [55, 80, 1], [55, 100, 3]], 150, False],
[360, 32]],
['repair check: yardage rounding', [[[110, 80, 1]], 110, False], [80, 7]],
['generated control 1', [[[110, 100, 3], [40, 60, 1], [40, 60, 3], [110, 100, 1]], 150, False], [460, 41]],
['generated control 2', [[[70, 30, 2], [20, 80, 1], [150, 100, 1], [20, 80, 1]], 150, False], [210, 19]],
['generated control 3', [[[35, 45, 1]], 110, False], [45, 4]]]]
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 |
|---|---|---|---|
| two pieces one row | [60, 6] | [60, 6] | Passed |
| rotate wide piece | [150, 14] | [150, 14] | Passed |
| directional wide piece | error: piece too wide | error: piece too wide | Passed |
| regression: yardage rounding | [335, 30] | [335, 30] | Passed |
| repair check: yardage rounding | [80, 7] | [80, 7] | Passed |
| generated control 1 | error: piece too wide | error: piece too wide | Passed |
| generated control 2 | [265, 24] | [265, 24] | Passed |
| generated control 3 | [100, 9] | [100, 9] | Passed |
SHA-256 / 52b13465390d20d61c10cb57bedfe8bb28a662ee1178db7f096a2785ecb487a4
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:33.688776+00:00.
Case digest / 5693ab1d1cd090cf8abb28f35ca0c4feeebe24c4a59a469d3f773bf32aad2496