FAILURE MAP
← Case archive

FA-97426 / Knitting and sewing pattern grading / Open access

Yarn yardage estimator: skein count · case 01

A need of 2.3 skeins buys 2 and the project runs out.

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

ROOT CAUSE

Skeins are rounded to the nearest instead of up.

THE FAILURE

Skeins are rounded to the nearest instead of up.

Unsuccessful approach: floor+1 buys a spare skein when the need is an exact multiple.

Case contract

grams = garment_area / swatch_area * swatch_g; meters = grams * skein_m/skein_g; add margin_pct as a multiplier (meters*(1+margin/100)). skeins = ceiling(meters/skein_m); leftover = skeins*skein_m - meters. Return [meters, skeins, leftover] with meters and leftover half-up integers. Non-positive swatch area or skein weight -> "error: swatch".

Why this case matters

Designers and knitters estimate how many skeins to buy from a weighed swatch.

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(swatch_g, swatch_w_cm, swatch_h_cm, garment_area_cm2, skein_g, skein_m, margin_pct):
    sw_area = Fraction(str(swatch_w_cm)) * Fraction(str(swatch_h_cm))
    if sw_area <= 0 or skein_g <= 0:
        return 'error: swatch'
    grams = Fraction(str(garment_area_cm2)) / sw_area * Fraction(str(swatch_g))
    meters = grams * Fraction(skein_m, skein_g)
    meters = meters * (1 + Fraction(margin_pct, 100))
    skeins = math.floor(meters / skein_m + Fraction(1, 2))
    leftover = skeins * skein_m - meters
    return [math.floor(meters + Fraction(1, 2)), skeins, math.floor(leftover + Fraction(1, 2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['regression: skein count', [20, 12, 15, 2000, 100, 125, 0], [278, 3, 97]],
  ['repair check: skein count', [15, 12, 15, 2400, 100, 100, 0], [200, 2, 0]],
  ['generated control 1', [12, 10, 15, 6000, 100, 400, 15], [2208, 6, 192]],
  ['generated control 2', [8, 15, 10, 6000, 50, 100, 0], [640, 7, 60]],
  ['generated control 3', [8, 10, 10, 2400, 50, 125, 15], [552, 5, 73]]],
 [['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['regression: skein count', [12, 15, 12, 2000, 100, 200, 0], [267, 2, 133]],
  ['repair check: skein count', [20, 15, 10, 9000, 100, 125, 0], [1500, 12, 0]],
  ['generated control 1', [10, 10, 12, 6000, 100, 200, 15], [1150, 6, 50]],
  ['generated control 2', [12, 10, 10, 9000, 50, 100, 15], [2484, 25, 16]],
  ['generated control 3', [15, 10, 15, 2400, 50, 200, 10], [1056, 6, 144]]],
 [['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['regression: skein count', [12, 15, 12, 1500, 100, 150, 15], [173, 2, 128]],
  ['repair check: skein count', [20, 10, 10, 3000, 100, 125, 0], [750, 6, 0]],
  ['generated control 1', [15, 12, 15, 2400, 100, 100, 10], [220, 3, 80]],
  ['generated control 2', [8, 15, 12, 6000, 50, 125, 0], [667, 6, 83]],
  ['generated control 3', [8, 10, 10, 9000, 100, 125, 15], [1035, 9, 90]]],
 [['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['regression: skein count', [8, 15, 12, 6000, 50, 400, 20], [2560, 7, 240]],
  ['repair check: skein count', [20, 10, 10, 6000, 100, 150, 0], [1800, 12, 0]],
  ['generated control 1', [8, 15, 12, 3000, 50, 400, 10], [1173, 3, 27]],
  ['generated control 2', [12, 15, 15, 9000, 50, 200, 0], [1920, 10, 80]],
  ['generated control 3', [15, 10, 10, 2000, 50, 125, 10], [825, 7, 50]]],
 [['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['regression: skein count', [10, 15, 15, 4800, 50, 150, 0], [640, 5, 110]],
  ['repair check: skein count', [20, 12, 12, 9000, 50, 400, 20], [12000, 30, 0]],
  ['generated control 1', [15, 15, 15, 4800, 50, 125, 20], [960, 8, 40]],
  ['generated control 2', [8, 12, 15, 1500, 50, 400, 10], [587, 2, 213]],
  ['generated control 3', [10, 12, 12, 2400, 50, 200, 10], [733, 4, 67]]]]
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
exact two skeins[400, 2, 0][400, 2, 0]Passed
with margin[1320, 11, 55][1320, 11, 55]Passed
zero swatcherror: swatcherror: swatchPassed
regression: skein count[278, 2, -28][278, 3, 97]Failed
repair check: skein count[200, 2, 0][200, 2, 0]Passed
generated control 1[2208, 6, 192][2208, 6, 192]Passed
generated control 2[640, 6, -40][640, 7, 60]Failed
generated control 3[552, 4, -52][552, 5, 73]Failed

SHA-256 / 25a216e5685e0a0cca6f540c897d11692c3666e16745205eb464ad1f006a2587

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(swatch_g, swatch_w_cm, swatch_h_cm, garment_area_cm2, skein_g, skein_m, margin_pct):
    sw_area = Fraction(str(swatch_w_cm)) * Fraction(str(swatch_h_cm))
    if sw_area <= 0 or skein_g <= 0:
        return 'error: swatch'
    grams = Fraction(str(garment_area_cm2)) / sw_area * Fraction(str(swatch_g))
    meters = grams * Fraction(skein_m, skein_g)
    meters = meters * (1 + Fraction(margin_pct, 100))
    skeins = math.floor(meters / skein_m) + 1
    leftover = skeins * skein_m - meters
    return [math.floor(meters + Fraction(1, 2)), skeins, math.floor(leftover + Fraction(1, 2))]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['regression: skein count', [20, 12, 15, 2000, 100, 125, 0], [278, 3, 97]],
  ['repair check: skein count', [15, 12, 15, 2400, 100, 100, 0], [200, 2, 0]],
  ['generated control 1', [12, 10, 15, 6000, 100, 400, 15], [2208, 6, 192]],
  ['generated control 2', [8, 15, 10, 6000, 50, 100, 0], [640, 7, 60]],
  ['generated control 3', [8, 10, 10, 2400, 50, 125, 15], [552, 5, 73]]],
 [['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['regression: skein count', [12, 15, 12, 2000, 100, 200, 0], [267, 2, 133]],
  ['repair check: skein count', [20, 15, 10, 9000, 100, 125, 0], [1500, 12, 0]],
  ['generated control 1', [10, 10, 12, 6000, 100, 200, 15], [1150, 6, 50]],
  ['generated control 2', [12, 10, 10, 9000, 50, 100, 15], [2484, 25, 16]],
  ['generated control 3', [15, 10, 15, 2400, 50, 200, 10], [1056, 6, 144]]],
 [['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['regression: skein count', [12, 15, 12, 1500, 100, 150, 15], [173, 2, 128]],
  ['repair check: skein count', [20, 10, 10, 3000, 100, 125, 0], [750, 6, 0]],
  ['generated control 1', [15, 12, 15, 2400, 100, 100, 10], [220, 3, 80]],
  ['generated control 2', [8, 15, 12, 6000, 50, 125, 0], [667, 6, 83]],
  ['generated control 3', [8, 10, 10, 9000, 100, 125, 15], [1035, 9, 90]]],
 [['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['regression: skein count', [8, 15, 12, 6000, 50, 400, 20], [2560, 7, 240]],
  ['repair check: skein count', [20, 10, 10, 6000, 100, 150, 0], [1800, 12, 0]],
  ['generated control 1', [8, 15, 12, 3000, 50, 400, 10], [1173, 3, 27]],
  ['generated control 2', [12, 15, 15, 9000, 50, 200, 0], [1920, 10, 80]],
  ['generated control 3', [15, 10, 10, 2000, 50, 125, 10], [825, 7, 50]]],
 [['with margin', [12, 10, 12, 4800, 50, 125, 10], [1320, 11, 55]],
  ['zero swatch', [10, 0, 10, 2000, 100, 200, 0], 'error: swatch'],
  ['exact two skeins', [10, 10, 10, 2000, 100, 200, 0], [400, 2, 0]],
  ['regression: skein count', [10, 15, 15, 4800, 50, 150, 0], [640, 5, 110]],
  ['repair check: skein count', [20, 12, 12, 9000, 50, 400, 20], [12000, 30, 0]],
  ['generated control 1', [15, 15, 15, 4800, 50, 125, 20], [960, 8, 40]],
  ['generated control 2', [8, 12, 15, 1500, 50, 400, 10], [587, 2, 213]],
  ['generated control 3', [10, 12, 12, 2400, 50, 200, 10], [733, 4, 67]]]]
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
exact two skeins[400, 3, 200][400, 2, 0]Failed
with margin[1320, 11, 55][1320, 11, 55]Passed
zero swatcherror: swatcherror: swatchPassed
regression: skein count[278, 3, 97][278, 3, 97]Passed
repair check: skein count[200, 3, 100][200, 2, 0]Failed
generated control 1[2208, 6, 192][2208, 6, 192]Passed
generated control 2[640, 7, 60][640, 7, 60]Passed
generated control 3[552, 5, 73][552, 5, 73]Passed

SHA-256 / e4e18c1125808ff00f0d0d1b99b565906fb5dfca2c37d9273acbfe5b49d3ca2c

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / 28aee9cfc6a7a9e592bed677ee9639a453194e41f6a360c0df746f01877a71c3