FA-97576 / Knitting and sewing pattern grading / Open access
Cutting layout fabric length: layout sort order · case 01
Short pieces open rows that tall pieces then extend, wasting fabric.
ROOT CAUSE
Pieces are packed shortest first.
VERIFIED REPAIR
Sort tallest first, then widest.
Unsuccessful approach: Sorting by width ignores row height.
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()
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: layout sort order', [[[20, 80, 2], [20, 60, 1], [40, 30, 2]], 110, True], [110, 10]],
['repair check: layout sort order', [[[150, 45, 1], [35, 30, 1], [40, 60, 2], [35, 100, 3]], 140, False],
[280, 25]],
['generated control 1', [[[70, 100, 3], [150, 45, 1], [40, 100, 1]], 110, False], [450, 40]],
['generated control 2', [[[35, 45, 2], [55, 45, 1]], 150, True], [45, 4]],
['generated control 3', [[[70, 45, 1]], 110, True], [45, 4]]],
[['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: layout sort order', [[[150, 45, 2], [55, 45, 1]], 140, False], [195, 18]],
['repair check: layout sort order', [[[20, 100, 2], [70, 30, 1], [110, 80, 3]], 110, True], [370, 33]],
['generated control 1', [[[70, 100, 2], [40, 60, 2], [150, 60, 2]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 30, 2], [40, 30, 2], [110, 45, 1], [110, 45, 3]], 150, True], [240, 21]],
['generated control 3', [[[110, 30, 1], [150, 100, 1]], 140, True], 'error: piece too wide']],
[['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: layout sort order', [[[20, 60, 1], [150, 30, 2], [40, 45, 1]], 110, False], [195, 18]],
['repair check: layout sort order', [[[55, 45, 3], [110, 45, 2], [40, 80, 2]], 150, False], [260, 23]],
['generated control 1', [[[70, 30, 1], [150, 30, 1]], 140, False], [150, 14]],
['generated control 2', [[[20, 45, 1]], 150, False], [45, 4]],
['generated control 3', [[[20, 80, 1]], 110, True], [80, 7]]],
[['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: layout sort order', [[[110, 30, 1], [150, 60, 1], [20, 45, 1]], 140, False], [180, 16]],
['repair check: layout sort order', [[[110, 45, 3], [70, 80, 2], [20, 60, 1], [35, 100, 3]], 140, False],
[330, 29]],
['generated control 1', [[[35, 30, 3], [55, 80, 3]], 150, True], [190, 17]],
['generated control 2', [[[55, 100, 2]], 110, False], [100, 9]],
['generated control 3', [[[40, 45, 1], [110, 45, 1], [40, 30, 1], [40, 100, 1]], 150, True], [145, 13]]],
[['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: layout sort order', [[[40, 60, 1], [40, 45, 3], [70, 80, 2]], 110, False], [250, 22]],
['repair check: layout sort order', [[[55, 30, 3], [110, 30, 3], [70, 45, 1]], 150, False], [195, 18]],
['generated control 1', [[[150, 30, 3], [70, 45, 1], [40, 45, 1], [150, 100, 3]], 110, True],
'error: piece too wide'],
['generated control 2', [[[55, 80, 2], [110, 45, 2], [20, 80, 2], [40, 45, 1]], 140, True], [250, 22]],
['generated control 3', [[[35, 60, 3], [150, 100, 2], [110, 60, 1], [150, 30, 2]], 150, False], [380, 34]]]]
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: layout sort order | [140, 13] | [110, 10] | Failed |
| repair check: layout sort order | [310, 28] | [280, 25] | Failed |
| generated control 1 | [450, 40] | [450, 40] | Passed |
| generated control 2 | [45, 4] | [45, 4] | Passed |
| generated control 3 | [45, 4] | [45, 4] | Passed |
SHA-256 / 67389b7b48715c7ba82cf2a9f9f3706d4e3fe25b52856e97a296c44807c2fa16
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(key=lambda t: -t[1])
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: layout sort order', [[[20, 80, 2], [20, 60, 1], [40, 30, 2]], 110, True], [110, 10]],
['repair check: layout sort order', [[[150, 45, 1], [35, 30, 1], [40, 60, 2], [35, 100, 3]], 140, False],
[280, 25]],
['generated control 1', [[[70, 100, 3], [150, 45, 1], [40, 100, 1]], 110, False], [450, 40]],
['generated control 2', [[[35, 45, 2], [55, 45, 1]], 150, True], [45, 4]],
['generated control 3', [[[70, 45, 1]], 110, True], [45, 4]]],
[['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: layout sort order', [[[150, 45, 2], [55, 45, 1]], 140, False], [195, 18]],
['repair check: layout sort order', [[[20, 100, 2], [70, 30, 1], [110, 80, 3]], 110, True], [370, 33]],
['generated control 1', [[[70, 100, 2], [40, 60, 2], [150, 60, 2]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 30, 2], [40, 30, 2], [110, 45, 1], [110, 45, 3]], 150, True], [240, 21]],
['generated control 3', [[[110, 30, 1], [150, 100, 1]], 140, True], 'error: piece too wide']],
[['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: layout sort order', [[[20, 60, 1], [150, 30, 2], [40, 45, 1]], 110, False], [195, 18]],
['repair check: layout sort order', [[[55, 45, 3], [110, 45, 2], [40, 80, 2]], 150, False], [260, 23]],
['generated control 1', [[[70, 30, 1], [150, 30, 1]], 140, False], [150, 14]],
['generated control 2', [[[20, 45, 1]], 150, False], [45, 4]],
['generated control 3', [[[20, 80, 1]], 110, True], [80, 7]]],
[['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: layout sort order', [[[110, 30, 1], [150, 60, 1], [20, 45, 1]], 140, False], [180, 16]],
['repair check: layout sort order', [[[110, 45, 3], [70, 80, 2], [20, 60, 1], [35, 100, 3]], 140, False],
[330, 29]],
['generated control 1', [[[35, 30, 3], [55, 80, 3]], 150, True], [190, 17]],
['generated control 2', [[[55, 100, 2]], 110, False], [100, 9]],
['generated control 3', [[[40, 45, 1], [110, 45, 1], [40, 30, 1], [40, 100, 1]], 150, True], [145, 13]]],
[['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: layout sort order', [[[40, 60, 1], [40, 45, 3], [70, 80, 2]], 110, False], [250, 22]],
['repair check: layout sort order', [[[55, 30, 3], [110, 30, 3], [70, 45, 1]], 150, False], [195, 18]],
['generated control 1', [[[150, 30, 3], [70, 45, 1], [40, 45, 1], [150, 100, 3]], 110, True],
'error: piece too wide'],
['generated control 2', [[[55, 80, 2], [110, 45, 2], [20, 80, 2], [40, 45, 1]], 140, True], [250, 22]],
['generated control 3', [[[35, 60, 3], [150, 100, 2], [110, 60, 1], [150, 30, 2]], 150, False], [380, 34]]]]
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: layout sort order | [160, 14] | [110, 10] | Failed |
| repair check: layout sort order | [250, 22] | [280, 25] | Failed |
| generated control 1 | [450, 40] | [450, 40] | Passed |
| generated control 2 | [45, 4] | [45, 4] | Passed |
| generated control 3 | [45, 4] | [45, 4] | Passed |
SHA-256 / 8ea0ad3c2d2c8fe1e6f6974ab6d69eae2c6c569d47ffc344a5dc409ec42209bf
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: layout sort order', [[[20, 80, 2], [20, 60, 1], [40, 30, 2]], 110, True], [110, 10]],
['repair check: layout sort order', [[[150, 45, 1], [35, 30, 1], [40, 60, 2], [35, 100, 3]], 140, False],
[280, 25]],
['generated control 1', [[[70, 100, 3], [150, 45, 1], [40, 100, 1]], 110, False], [450, 40]],
['generated control 2', [[[35, 45, 2], [55, 45, 1]], 150, True], [45, 4]],
['generated control 3', [[[70, 45, 1]], 110, True], [45, 4]]],
[['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: layout sort order', [[[150, 45, 2], [55, 45, 1]], 140, False], [195, 18]],
['repair check: layout sort order', [[[20, 100, 2], [70, 30, 1], [110, 80, 3]], 110, True], [370, 33]],
['generated control 1', [[[70, 100, 2], [40, 60, 2], [150, 60, 2]], 140, True], 'error: piece too wide'],
['generated control 2', [[[70, 30, 2], [40, 30, 2], [110, 45, 1], [110, 45, 3]], 150, True], [240, 21]],
['generated control 3', [[[110, 30, 1], [150, 100, 1]], 140, True], 'error: piece too wide']],
[['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: layout sort order', [[[20, 60, 1], [150, 30, 2], [40, 45, 1]], 110, False], [195, 18]],
['repair check: layout sort order', [[[55, 45, 3], [110, 45, 2], [40, 80, 2]], 150, False], [260, 23]],
['generated control 1', [[[70, 30, 1], [150, 30, 1]], 140, False], [150, 14]],
['generated control 2', [[[20, 45, 1]], 150, False], [45, 4]],
['generated control 3', [[[20, 80, 1]], 110, True], [80, 7]]],
[['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: layout sort order', [[[110, 30, 1], [150, 60, 1], [20, 45, 1]], 140, False], [180, 16]],
['repair check: layout sort order', [[[110, 45, 3], [70, 80, 2], [20, 60, 1], [35, 100, 3]], 140, False],
[330, 29]],
['generated control 1', [[[35, 30, 3], [55, 80, 3]], 150, True], [190, 17]],
['generated control 2', [[[55, 100, 2]], 110, False], [100, 9]],
['generated control 3', [[[40, 45, 1], [110, 45, 1], [40, 30, 1], [40, 100, 1]], 150, True], [145, 13]]],
[['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: layout sort order', [[[40, 60, 1], [40, 45, 3], [70, 80, 2]], 110, False], [250, 22]],
['repair check: layout sort order', [[[55, 30, 3], [110, 30, 3], [70, 45, 1]], 150, False], [195, 18]],
['generated control 1', [[[150, 30, 3], [70, 45, 1], [40, 45, 1], [150, 100, 3]], 110, True],
'error: piece too wide'],
['generated control 2', [[[55, 80, 2], [110, 45, 2], [20, 80, 2], [40, 45, 1]], 140, True], [250, 22]],
['generated control 3', [[[35, 60, 3], [150, 100, 2], [110, 60, 1], [150, 30, 2]], 150, False], [380, 34]]]]
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: layout sort order | [110, 10] | [110, 10] | Passed |
| repair check: layout sort order | [280, 25] | [280, 25] | Passed |
| generated control 1 | [450, 40] | [450, 40] | Passed |
| generated control 2 | [45, 4] | [45, 4] | Passed |
| generated control 3 | [45, 4] | [45, 4] | Passed |
SHA-256 / 0a38e6884d44ce27b1fa815d634791d93a10b61800c177daafa35eec1df340b4
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.505976+00:00.
Case digest / aee223e2dbf2cdc1db7fe91c4b8e18f733bfb7707914205d2c9e8e19cb74990b