FA-97661 / Knitting and sewing pattern grading / Open access
Stranded colorwork float checker: round wrap merge · case 01
In the round, a float crossing the beginning of round is reported as two short floats.
ROOT CAUSE
Wrap-around merging is applied to flat rows instead of rounds.
VERIFIED REPAIR
Merge wrapping floats only in the round.
Unsuccessful approach: Merging without checking the last run reaches the end joins unrelated floats.
Case contract
row is a string of color letters. For each color, a float is a maximal run of other colors [start, length]. In the round, a float touching both the end and the start (with at least two runs) wraps and merges into the last run (its start is kept). Report [color, start, length] for floats longer than max_float, sorted by (start, color).
Why this case matters
Stranded knitting charts are checked for long floats that need catching.
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(row, max_float, in_round):
n = len(row)
out = []
for color in sorted(set(row)):
runs = []
i = 0
while i < n:
if row[i] != color:
j = i
while j < n and row[j] != color:
j += 1
runs.append([i, j - i])
i = j
else:
i += 1
if not in_round and len(runs) >= 2 and runs[0][0] == 0 and runs[-1][0] + runs[-1][1] == n:
first = runs.pop(0)
runs[-1][1] += first[1]
for start, length in runs:
if length > max_float:
out.append([color, start, length])
return sorted(out, key=lambda x: (x[1], x[0]))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAACAAAACAA', 4, True], [['C', 9, 5]]],
['repair check: round wrap merge', ['BAAAAAABBBAAAAA', 3, True], [['B', 1, 6], ['B', 10, 5]]],
['generated control 1', ['ABAAABBAAABAA', 4, True], []],
['generated control 2', ['BAAAABBBAAA', 4, False], []],
['generated control 3', ['BAAABBAA', 5, False], []]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAAAAAABBAAAA', 5, True], [['B', 9, 11]]],
['repair check: round wrap merge', ['ABAAAAAAAB', 3, True], [['B', 2, 7]]],
['generated control 1', ['BAAAAAABBAAA', 4, True], [['B', 1, 6]]],
['generated control 2', ['BAAAAAABBBAAA', 5, True], [['B', 1, 6]]],
['generated control 3', ['BAAAAABBAAA', 5, False], []]],
[['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['regression: round wrap merge', ['AAAAABAAABAAAAA', 3, True], [['B', 10, 10]]],
['repair check: round wrap merge', ['BAAAABBBAAAAA', 3, True], [['B', 1, 4], ['B', 8, 5]]],
['generated control 1', ['BAAAAAAABAAAAA', 3, False], [['B', 1, 7], ['B', 9, 5]]],
['generated control 2', ['BAAAAABAA', 4, True], [['B', 1, 5]]],
['generated control 3', ['BAAAABBAA', 5, True], []]],
[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAABABBAAAABAA', 4, True], [['B', 12, 5]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['ABAAAABABBAAB', 3, False], [['B', 2, 4]]],
['generated control 2', ['AABABAAAAAAAAB', 4, False], [['B', 5, 8]]],
['generated control 3', ['BAAAABBAAA', 3, True], [['B', 1, 4]]]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAABAAAAAA', 5, True], [['B', 4, 9]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['BAAABBAA', 4, False], []],
['generated control 2', ['AAAABABAAAAABAA', 5, True], [['B', 13, 6]]],
['generated control 3', ['AAAAAAAAAABA', 5, True], [['B', 11, 11]]]]]
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 |
|---|---|---|---|
| flat long float | [['B', 1, 6]] | [['B', 1, 6]] | Passed |
| wrap in round | [['B', 2, 5]] | [['B', 2, 5], ['A', 7, 5]] | Failed |
| exact limit | [] | [] | Passed |
| regression: round wrap merge | [] | [['C', 9, 5]] | Failed |
| repair check: round wrap merge | [['B', 1, 6], ['B', 10, 5]] | [['B', 1, 6], ['B', 10, 5]] | Passed |
| generated control 1 | [] | [] | Passed |
| generated control 2 | [] | [] | Passed |
| generated control 3 | [] | [] | Passed |
SHA-256 / b788ef1103122653c61a8816ecd3d3850a142f9c21a7bd9a8a60893973f1e9be
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(row, max_float, in_round):
n = len(row)
out = []
for color in sorted(set(row)):
runs = []
i = 0
while i < n:
if row[i] != color:
j = i
while j < n and row[j] != color:
j += 1
runs.append([i, j - i])
i = j
else:
i += 1
if in_round and len(runs) >= 2 and runs[0][0] == 0:
first = runs.pop(0)
runs[-1][1] += first[1]
for start, length in runs:
if length > max_float:
out.append([color, start, length])
return sorted(out, key=lambda x: (x[1], x[0]))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAACAAAACAA', 4, True], [['C', 9, 5]]],
['repair check: round wrap merge', ['BAAAAAABBBAAAAA', 3, True], [['B', 1, 6], ['B', 10, 5]]],
['generated control 1', ['ABAAABBAAABAA', 4, True], []],
['generated control 2', ['BAAAABBBAAA', 4, False], []],
['generated control 3', ['BAAABBAA', 5, False], []]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAAAAAABBAAAA', 5, True], [['B', 9, 11]]],
['repair check: round wrap merge', ['ABAAAAAAAB', 3, True], [['B', 2, 7]]],
['generated control 1', ['BAAAAAABBAAA', 4, True], [['B', 1, 6]]],
['generated control 2', ['BAAAAAABBBAAA', 5, True], [['B', 1, 6]]],
['generated control 3', ['BAAAAABBAAA', 5, False], []]],
[['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['regression: round wrap merge', ['AAAAABAAABAAAAA', 3, True], [['B', 10, 10]]],
['repair check: round wrap merge', ['BAAAABBBAAAAA', 3, True], [['B', 1, 4], ['B', 8, 5]]],
['generated control 1', ['BAAAAAAABAAAAA', 3, False], [['B', 1, 7], ['B', 9, 5]]],
['generated control 2', ['BAAAAABAA', 4, True], [['B', 1, 5]]],
['generated control 3', ['BAAAABBAA', 5, True], []]],
[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAABABBAAAABAA', 4, True], [['B', 12, 5]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['ABAAAABABBAAB', 3, False], [['B', 2, 4]]],
['generated control 2', ['AABABAAAAAAAAB', 4, False], [['B', 5, 8]]],
['generated control 3', ['BAAAABBAAA', 3, True], [['B', 1, 4]]]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAABAAAAAA', 5, True], [['B', 4, 9]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['BAAABBAA', 4, False], []],
['generated control 2', ['AAAABABAAAAABAA', 5, True], [['B', 13, 6]]],
['generated control 3', ['AAAAAAAAAABA', 5, True], [['B', 11, 11]]]]]
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 |
|---|---|---|---|
| flat long float | [['B', 1, 6]] | [['B', 1, 6]] | Passed |
| wrap in round | [['B', 2, 5], ['A', 7, 5]] | [['B', 2, 5], ['A', 7, 5]] | Passed |
| exact limit | [] | [] | Passed |
| regression: round wrap merge | [['C', 9, 5]] | [['C', 9, 5]] | Passed |
| repair check: round wrap merge | [['B', 1, 6], ['A', 7, 4], ['B', 10, 5]] | [['B', 1, 6], ['B', 10, 5]] | Failed |
| generated control 1 | [] | [] | Passed |
| generated control 2 | [] | [] | Passed |
| generated control 3 | [] | [] | Passed |
SHA-256 / b2b0ccbb5b1d7d94ae4da880f25ff8f4d713b8c8c724d1134fe2081e960ac490
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(row, max_float, in_round):
n = len(row)
out = []
for color in sorted(set(row)):
runs = []
i = 0
while i < n:
if row[i] != color:
j = i
while j < n and row[j] != color:
j += 1
runs.append([i, j - i])
i = j
else:
i += 1
if in_round and len(runs) >= 2 and runs[0][0] == 0 and runs[-1][0] + runs[-1][1] == n:
first = runs.pop(0)
runs[-1][1] += first[1]
for start, length in runs:
if length > max_float:
out.append([color, start, length])
return sorted(out, key=lambda x: (x[1], x[0]))
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAACAAAACAA', 4, True], [['C', 9, 5]]],
['repair check: round wrap merge', ['BAAAAAABBBAAAAA', 3, True], [['B', 1, 6], ['B', 10, 5]]],
['generated control 1', ['ABAAABBAAABAA', 4, True], []],
['generated control 2', ['BAAAABBBAAA', 4, False], []],
['generated control 3', ['BAAABBAA', 5, False], []]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAAAAAABBAAAA', 5, True], [['B', 9, 11]]],
['repair check: round wrap merge', ['ABAAAAAAAB', 3, True], [['B', 2, 7]]],
['generated control 1', ['BAAAAAABBAAA', 4, True], [['B', 1, 6]]],
['generated control 2', ['BAAAAAABBBAAA', 5, True], [['B', 1, 6]]],
['generated control 3', ['BAAAAABBAAA', 5, False], []]],
[['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['regression: round wrap merge', ['AAAAABAAABAAAAA', 3, True], [['B', 10, 10]]],
['repair check: round wrap merge', ['BAAAABBBAAAAA', 3, True], [['B', 1, 4], ['B', 8, 5]]],
['generated control 1', ['BAAAAAAABAAAAA', 3, False], [['B', 1, 7], ['B', 9, 5]]],
['generated control 2', ['BAAAAABAA', 4, True], [['B', 1, 5]]],
['generated control 3', ['BAAAABBAA', 5, True], []]],
[['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []],
['regression: round wrap merge', ['AAABABBAAAABAA', 4, True], [['B', 12, 5]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['ABAAAABABBAAB', 3, False], [['B', 2, 4]]],
['generated control 2', ['AABABAAAAAAAAB', 4, False], [['B', 5, 8]]],
['generated control 3', ['BAAAABBAAA', 3, True], [['B', 1, 4]]]],
[['wrap in round', ['BBAAAAABBB', 4, True], [['B', 2, 5], ['A', 7, 5]]],
['exact limit', ['BAAAAB', 4, False], []], ['flat long float', ['BAAAAAABBA', 5, False], [['B', 1, 6]]],
['regression: round wrap merge', ['AAABAAAAAA', 5, True], [['B', 4, 9]]],
['repair check: round wrap merge', ['BAAAABBBAAAA', 3, True], [['B', 1, 4], ['B', 8, 4]]],
['generated control 1', ['BAAABBAA', 4, False], []],
['generated control 2', ['AAAABABAAAAABAA', 5, True], [['B', 13, 6]]],
['generated control 3', ['AAAAAAAAAABA', 5, True], [['B', 11, 11]]]]]
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 |
|---|---|---|---|
| flat long float | [['B', 1, 6]] | [['B', 1, 6]] | Passed |
| wrap in round | [['B', 2, 5], ['A', 7, 5]] | [['B', 2, 5], ['A', 7, 5]] | Passed |
| exact limit | [] | [] | Passed |
| regression: round wrap merge | [['C', 9, 5]] | [['C', 9, 5]] | Passed |
| repair check: round wrap merge | [['B', 1, 6], ['B', 10, 5]] | [['B', 1, 6], ['B', 10, 5]] | Passed |
| generated control 1 | [] | [] | Passed |
| generated control 2 | [] | [] | Passed |
| generated control 3 | [] | [] | Passed |
SHA-256 / ebd72caf1708592db6f8f6c2f051299a917facff84d889bae8ed84ec31aa74ac
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:34.372739+00:00.
Case digest / ff4102573f7bcedd2744d11dda68df904ecc1a76c72d3d77cae0af0edfabdf82