FA-80051 / Typography line breaking / Open access
Box-glue-penalty breakpoints: penalty width accounting · case 01
Hyphenated lines are reported one hyphen narrower.
ROOT CAUSE
The break width at a penalty omits the penalty width.
VERIFIED REPAIR
Add the penalty width only when the break is taken there.
Unsuccessful approach: Adding the width to the running total also charges unused hyphens.
Case contract
Input [items, width]; items are ["b",w], ["g",w] or ["p",w,cost,flag]. Legal breaks: glue immediately after a box; penalty with cost < 10000 (width counted only if broken there); cost <= -10000 forces a break. Discardable glue/penalties at a line start are dropped. First-fit: when the running width exceeds the measure, break at the last legal breakpoint. Return [[line width, break kind]] with kinds glue/penalty/forced/end.
Why this case matters
Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
items, width = x
lines = []
start = 0
n = len(items)
while start < n:
while start < n and items[start][0] != 'b':
start += 1
if start >= n:
break
total = 0
last = None
result = None
i = start
while i < n:
it = items[i]
if it[0] == 'p':
if it[2] <= -10000:
result = (i, total + it[1], 'forced')
break
if it[2] < 10000:
last = (i, total, 'penalty')
elif it[0] == 'g':
if items[i - 1][0] == 'b':
last = (i, total, 'glue')
total += it[1]
else:
total += it[1]
if total > width and last is not None:
result = last
break
i += 1
if result is None:
lines.append([total, 'end'])
break
lines.append([result[1], result[2]])
start = result[0] + 1
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2]], 18], [[12, 'glue'], [18, 'penalty']]), ('regression: penalty width accounting', [[['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 5], ['g', 2]], 11], [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 2], ['b', 7], ['p', 0, -5000, False], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 1]], 11], [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 1], ['g', 2], ['b', 3], ['g', 2], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 1]], 15], [[15, 'glue'], [15, 'glue'], [15, 'glue']])], [('regression: penalty width accounting', [[['b', 1], ['g', 2], ['b', 4], ['g', 1], ['b', 5], ['p', 0, -5000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['g', 1]], 7], [[7, 'glue'], [5, 'penalty'], [6, 'penalty'], [6, 'end']]), ('regression: penalty width accounting', [[['b', 5], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 9], [[9, 'penalty'], [5, 'forced'], [8, 'glue'], [8, 'glue']]), ('regression: penalty width accounting', [[['b', 7], ['g', 2], ['b', 4], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 6], ['g', 1]], 17], [[18, 'penalty'], [15, 'forced'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 3], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1]], 7], [[4, 'glue'], [8, 'penalty'], [6, 'glue'], [7, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['p', 0, -10000, False], ['g', 2]], 15], [[12, 'glue'], [13, 'glue'], [6, 'forced']]), ('control layout', [[['b', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['g', 1], ['b', 5], ['g', 1], ['b', 3], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2]], 11], [[6, 'glue'], [7, 'glue'], [9, 'glue'], [6, 'forced']])], [('regression: penalty width accounting', [[['b', 2], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 6], [[2, 'glue'], [6, 'glue'], [7, 'penalty'], [4, 'penalty'], [8, 'penalty'], [2, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1]], 12], [[12, 'penalty'], [12, 'glue'], [8, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 8], [[3, 'penalty'], [8, 'glue'], [8, 'glue'], [7, 'penalty'], [9, 'penalty'], [6, 'forced'], [2, 'end']]), ('partial-repair probe', [[['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 2]], 18], [[2, 'forced'], [16, 'forced'], [11, 'forced'], [18, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 3], ['g', 1], ['g', 1]], 8], [[3, 'glue'], [6, 'glue'], [6, 'glue'], [5, 'end']]), ('control layout', [[['b', 1], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['p', 0, 10000, False], ['g', 1]], 13], [[10, 'forced'], [11, 'penalty'], [13, 'glue'], [7, 'glue'], [6, 'end']])], [('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 3], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 0, 9999, False], ['g', 2], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 2]], 10], [[6, 'glue'], [4, 'glue'], [7, 'penalty'], [8, 'penalty'], [8, 'penalty'], [7, 'glue'], [6, 'glue'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 7], [[1, 'glue'], [7, 'glue'], [6, 'penalty'], [3, 'penalty'], [8, 'penalty'], [5, 'end']]), ('partial-repair probe', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 6], ['g', 2], ['b', 2], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 16], [[13, 'glue'], [15, 'glue'], [12, 'forced'], [6, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 6], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 2], ['g', 1]], 7], [[6, 'forced'], [1, 'forced'], [6, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 6], ['g', 1], ['b', 2], ['p', 0, 10000, False], ['g', 1]], 14], [[12, 'glue'], [10, 'end']])], [('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2]], 9], [[10, 'penalty'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, 9999, False], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1]], 11], [[7, 'penalty'], [10, 'penalty'], [6, 'glue'], [9, 'glue'], [8, 'penalty'], [6, 'penalty'], [6, 'end']]), ('partial-repair probe', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 1], ['g', 1], ['g', 1]], 16], [[14, 'forced'], [15, 'glue']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 15], [[9, 'penalty'], [7, 'forced'], [1, 'forced'], [5, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 5], ['g', 1], ['b', 6], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['p', 0, 900, False], ['g', 1], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 4], ['g', 2]], 14], [[12, 'glue'], [14, 'glue'], [14, 'glue'], [6, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 1], ['g', 1], ['b', 3], ['g', 2], ['b', 3], ['g', 1]], 16], [[16, 'glue'], [11, 'end']])]]
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 |
|---|---|---|---|
| hyphen penalty taken | [[5, 'penalty'], [4, 'glue'], [3, 'end']] | [[6, 'penalty'], [4, 'glue'], [3, 'end']] | Failed |
| regression: penalty width accounting | [[12, 'glue'], [17, 'penalty']] | [[12, 'glue'], [18, 'penalty']] | Failed |
| regression: penalty width accounting | [[11, 'penalty'], [1, 'forced'], [8, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | Failed |
| regression: penalty width accounting | [[4, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']] | [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']] | Failed |
| forced break | [[5, 'forced'], [3, 'end']] | [[5, 'forced'], [3, 'end']] | Passed |
| inhibited penalty | [[9, 'glue'], [3, 'end']] | [[9, 'glue'], [3, 'end']] | Passed |
| control layout | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | Passed |
| control layout | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | Passed |
SHA-256 / d3a48e4d8cd18a5bc77c8130fccb0d6560d0022353ea448312a414fc8fdab644
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
items, width = x
lines = []
start = 0
n = len(items)
while start < n:
while start < n and items[start][0] != 'b':
start += 1
if start >= n:
break
total = 0
last = None
result = None
i = start
while i < n:
it = items[i]
if it[0] == 'p':
if it[2] <= -10000:
result = (i, total + it[1], 'forced')
break
if it[2] < 10000:
last = (i, total + it[1], 'penalty')
total += it[1]
elif it[0] == 'g':
if items[i - 1][0] == 'b':
last = (i, total, 'glue')
total += it[1]
else:
total += it[1]
if total > width and last is not None:
result = last
break
i += 1
if result is None:
lines.append([total, 'end'])
break
lines.append([result[1], result[2]])
start = result[0] + 1
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2]], 18], [[12, 'glue'], [18, 'penalty']]), ('regression: penalty width accounting', [[['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 5], ['g', 2]], 11], [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 2], ['b', 7], ['p', 0, -5000, False], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 1]], 11], [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 1], ['g', 2], ['b', 3], ['g', 2], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 1]], 15], [[15, 'glue'], [15, 'glue'], [15, 'glue']])], [('regression: penalty width accounting', [[['b', 1], ['g', 2], ['b', 4], ['g', 1], ['b', 5], ['p', 0, -5000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['g', 1]], 7], [[7, 'glue'], [5, 'penalty'], [6, 'penalty'], [6, 'end']]), ('regression: penalty width accounting', [[['b', 5], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 9], [[9, 'penalty'], [5, 'forced'], [8, 'glue'], [8, 'glue']]), ('regression: penalty width accounting', [[['b', 7], ['g', 2], ['b', 4], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 6], ['g', 1]], 17], [[18, 'penalty'], [15, 'forced'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 3], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1]], 7], [[4, 'glue'], [8, 'penalty'], [6, 'glue'], [7, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['p', 0, -10000, False], ['g', 2]], 15], [[12, 'glue'], [13, 'glue'], [6, 'forced']]), ('control layout', [[['b', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['g', 1], ['b', 5], ['g', 1], ['b', 3], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2]], 11], [[6, 'glue'], [7, 'glue'], [9, 'glue'], [6, 'forced']])], [('regression: penalty width accounting', [[['b', 2], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 6], [[2, 'glue'], [6, 'glue'], [7, 'penalty'], [4, 'penalty'], [8, 'penalty'], [2, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1]], 12], [[12, 'penalty'], [12, 'glue'], [8, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 8], [[3, 'penalty'], [8, 'glue'], [8, 'glue'], [7, 'penalty'], [9, 'penalty'], [6, 'forced'], [2, 'end']]), ('partial-repair probe', [[['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 2]], 18], [[2, 'forced'], [16, 'forced'], [11, 'forced'], [18, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 3], ['g', 1], ['g', 1]], 8], [[3, 'glue'], [6, 'glue'], [6, 'glue'], [5, 'end']]), ('control layout', [[['b', 1], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['p', 0, 10000, False], ['g', 1]], 13], [[10, 'forced'], [11, 'penalty'], [13, 'glue'], [7, 'glue'], [6, 'end']])], [('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 3], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 0, 9999, False], ['g', 2], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 2]], 10], [[6, 'glue'], [4, 'glue'], [7, 'penalty'], [8, 'penalty'], [8, 'penalty'], [7, 'glue'], [6, 'glue'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 7], [[1, 'glue'], [7, 'glue'], [6, 'penalty'], [3, 'penalty'], [8, 'penalty'], [5, 'end']]), ('partial-repair probe', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 6], ['g', 2], ['b', 2], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 16], [[13, 'glue'], [15, 'glue'], [12, 'forced'], [6, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 6], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 2], ['g', 1]], 7], [[6, 'forced'], [1, 'forced'], [6, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 6], ['g', 1], ['b', 2], ['p', 0, 10000, False], ['g', 1]], 14], [[12, 'glue'], [10, 'end']])], [('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2]], 9], [[10, 'penalty'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, 9999, False], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1]], 11], [[7, 'penalty'], [10, 'penalty'], [6, 'glue'], [9, 'glue'], [8, 'penalty'], [6, 'penalty'], [6, 'end']]), ('partial-repair probe', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 1], ['g', 1], ['g', 1]], 16], [[14, 'forced'], [15, 'glue']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 15], [[9, 'penalty'], [7, 'forced'], [1, 'forced'], [5, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 5], ['g', 1], ['b', 6], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['p', 0, 900, False], ['g', 1], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 4], ['g', 2]], 14], [[12, 'glue'], [14, 'glue'], [14, 'glue'], [6, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 1], ['g', 1], ['b', 3], ['g', 2], ['b', 3], ['g', 1]], 16], [[16, 'glue'], [11, 'end']])]]
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 |
|---|---|---|---|
| hyphen penalty taken | [[6, 'penalty'], [4, 'glue'], [3, 'end']] | [[6, 'penalty'], [4, 'glue'], [3, 'end']] | Passed |
| regression: penalty width accounting | [[13, 'glue'], [19, 'penalty']] | [[12, 'glue'], [18, 'penalty']] | Failed |
| regression: penalty width accounting | [[8, 'penalty'], [8, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | Failed |
| regression: penalty width accounting | [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [7, 'end']] | [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']] | Failed |
| forced break | [[5, 'forced'], [3, 'end']] | [[5, 'forced'], [3, 'end']] | Passed |
| inhibited penalty | [[9, 'glue'], [3, 'end']] | [[9, 'glue'], [3, 'end']] | Passed |
| control layout | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | Passed |
| control layout | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | Passed |
SHA-256 / ecd3dfc9b6b5e625c9b990832a434f38c5d0641892b24ed10e0e524bc28bdfbc
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
items, width = x
lines = []
start = 0
n = len(items)
while start < n:
while start < n and items[start][0] != 'b':
start += 1
if start >= n:
break
total = 0
last = None
result = None
i = start
while i < n:
it = items[i]
if it[0] == 'p':
if it[2] <= -10000:
result = (i, total + it[1], 'forced')
break
if it[2] < 10000:
last = (i, total + it[1], 'penalty')
elif it[0] == 'g':
if items[i - 1][0] == 'b':
last = (i, total, 'glue')
total += it[1]
else:
total += it[1]
if total > width and last is not None:
result = last
break
i += 1
if result is None:
lines.append([total, 'end'])
break
lines.append([result[1], result[2]])
start = result[0] + 1
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2]], 18], [[12, 'glue'], [18, 'penalty']]), ('regression: penalty width accounting', [[['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 5], ['g', 2]], 11], [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 3], ['g', 2], ['b', 7], ['p', 0, -5000, False], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1]], 7], [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 1]], 11], [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 1], ['g', 2], ['b', 3], ['g', 2], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 1]], 15], [[15, 'glue'], [15, 'glue'], [15, 'glue']])], [('regression: penalty width accounting', [[['b', 1], ['g', 2], ['b', 4], ['g', 1], ['b', 5], ['p', 0, -5000, False], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['g', 1]], 7], [[7, 'glue'], [5, 'penalty'], [6, 'penalty'], [6, 'end']]), ('regression: penalty width accounting', [[['b', 5], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 9], [[9, 'penalty'], [5, 'forced'], [8, 'glue'], [8, 'glue']]), ('regression: penalty width accounting', [[['b', 7], ['g', 2], ['b', 4], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['b', 6], ['g', 1]], 17], [[18, 'penalty'], [15, 'forced'], [7, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 3], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 1], ['g', 1]], 7], [[4, 'glue'], [8, 'penalty'], [6, 'glue'], [7, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['b', 2], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['p', 0, -10000, False], ['g', 2]], 15], [[12, 'glue'], [13, 'glue'], [6, 'forced']]), ('control layout', [[['b', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['g', 1], ['b', 5], ['g', 1], ['b', 3], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 2]], 11], [[6, 'glue'], [7, 'glue'], [9, 'glue'], [6, 'forced']])], [('regression: penalty width accounting', [[['b', 2], ['g', 2], ['b', 6], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 6], [[2, 'glue'], [6, 'glue'], [7, 'penalty'], [4, 'penalty'], [8, 'penalty'], [2, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1]], 12], [[12, 'penalty'], [12, 'glue'], [8, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 8], [[3, 'penalty'], [8, 'glue'], [8, 'glue'], [7, 'penalty'], [9, 'penalty'], [6, 'forced'], [2, 'end']]), ('partial-repair probe', [[['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 2]], 18], [[2, 'forced'], [16, 'forced'], [11, 'forced'], [18, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 3], ['g', 1], ['g', 1]], 8], [[3, 'glue'], [6, 'glue'], [6, 'glue'], [5, 'end']]), ('control layout', [[['b', 1], ['g', 2], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['p', 0, 10000, False], ['g', 1]], 13], [[10, 'forced'], [11, 'penalty'], [13, 'glue'], [7, 'glue'], [6, 'end']])], [('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('regression: penalty width accounting', [[['b', 2], ['g', 1], ['b', 3], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 0, 9999, False], ['g', 2], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 2]], 10], [[6, 'glue'], [4, 'glue'], [7, 'penalty'], [8, 'penalty'], [8, 'penalty'], [7, 'glue'], [6, 'glue'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 7], [[1, 'glue'], [7, 'glue'], [6, 'penalty'], [3, 'penalty'], [8, 'penalty'], [5, 'end']]), ('partial-repair probe', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['g', 1], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 6], ['g', 2], ['b', 2], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2]], 16], [[13, 'glue'], [15, 'glue'], [12, 'forced'], [6, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 6], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['g', 1], ['b', 2], ['g', 1]], 7], [[6, 'forced'], [1, 'forced'], [6, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 6], ['g', 1], ['b', 2], ['p', 0, 10000, False], ['g', 1]], 14], [[12, 'glue'], [10, 'end']])], [('regression: penalty width accounting', [[['b', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2]], 9], [[10, 'penalty'], [9, 'end']]), ('regression: penalty width accounting', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['p', 0, 10000, False], ['g', 1], ['b', 4], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, 9999, False], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1]], 11], [[7, 'penalty'], [10, 'penalty'], [6, 'glue'], [9, 'glue'], [8, 'penalty'], [6, 'penalty'], [6, 'end']]), ('partial-repair probe', [[['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 7], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 1], ['g', 1], ['g', 1]], 16], [[14, 'forced'], [15, 'glue']]), ('regression: penalty width accounting', [[['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 3], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1]], 15], [[9, 'penalty'], [7, 'forced'], [1, 'forced'], [5, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 5], ['g', 1], ['b', 6], ['g', 2], ['b', 2], ['g', 2], ['b', 7], ['p', 0, 900, False], ['g', 1], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 6], ['g', 1], ['b', 4], ['g', 2]], 14], [[12, 'glue'], [14, 'glue'], [14, 'glue'], [6, 'end']]), ('control layout', [[['b', 2], ['g', 1], ['g', 1], ['b', 2], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 1], ['g', 1], ['b', 3], ['g', 2], ['b', 3], ['g', 1]], 16], [[16, 'glue'], [11, 'end']])]]
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 |
|---|---|---|---|
| hyphen penalty taken | [[6, 'penalty'], [4, 'glue'], [3, 'end']] | [[6, 'penalty'], [4, 'glue'], [3, 'end']] | Passed |
| regression: penalty width accounting | [[12, 'glue'], [18, 'penalty']] | [[12, 'glue'], [18, 'penalty']] | Passed |
| regression: penalty width accounting | [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | [[12, 'penalty'], [1, 'forced'], [9, 'penalty'], [6, 'glue'], [5, 'glue'], [7, 'end']] | Passed |
| regression: penalty width accounting | [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']] | [[5, 'penalty'], [7, 'glue'], [3, 'glue'], [7, 'penalty'], [3, 'forced'], [6, 'end']] | Passed |
| forced break | [[5, 'forced'], [3, 'end']] | [[5, 'forced'], [3, 'end']] | Passed |
| inhibited penalty | [[9, 'glue'], [3, 'end']] | [[9, 'glue'], [3, 'end']] | Passed |
| control layout | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | [[7, 'forced'], [5, 'glue'], [7, 'glue'], [4, 'end']] | Passed |
| control layout | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | [[15, 'glue'], [15, 'glue'], [15, 'glue']] | Passed |
SHA-256 / b58085419ed25d198c034d8c98123dd3b12f77040be1481f8a8c72d1e26057b0
Verification & scope
A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. 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:49:50.297118+00:00.
Case digest / bf52313ba01a1c7a473546e16ddd264b9ff09aac521c3fee1bf5a9346d07c3f1