FA-79946 / Typography line breaking / Open access
Consecutive hyphen limit: hyphen glyph width · case 01
Hyphenated lines overflow the measure by one unit.
ROOT CAUSE
The fit test for a split head ignores the width of the added hyphen.
VERIFIED REPAIR
Include the hyphen glyph in the width of the head fragment.
Unsuccessful approach: Counting the hyphen but dropping the separating space still misfits lines that already hold words.
Case contract
Input [words as syllable lists, width, limit]. Greedy fill with 1-unit spaces and characters. A word that does not fit may be split at the latest syllable boundary whose head plus "-" fits, only if fewer than limit immediately preceding lines ended in a hyphen and the word is not the paragraph's last word. A line ended without hyphen resets the streak; a word too long for an empty line is set alone. Return the lines.
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):
words, width, limit = x
queue = [list(w) for w in words]
lines = []
cur = ''
streak = 0
k = 0
while k < len(queue):
syl = queue[k]
token = ''.join(syl)
need = len(token) if cur == '' else len(cur) + 1 + len(token)
if need <= width:
cur = token if cur == '' else cur + ' ' + token
k += 1
continue
split = None
if streak < limit and k < len(queue) - 1:
for cut in range(len(syl) - 1, 0, -1):
head = ''.join(syl[:cut]) + '-'
room = len(head) - 1 if cur == '' else len(cur) + len(head)
if room <= width:
split = cut
break
if split is not None:
head = ''.join(syl[:split]) + '-'
lines.append(head if cur == '' else cur + ' ' + head)
queue[k] = syl[split:]
cur = ''
streak += 1
elif cur == '':
lines.append(token)
k += 1
streak = 0
else:
lines.append(cur)
cur, streak = '', 0
if cur:
lines.append(cur)
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['text']], 12, 2], ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text']), ('regression: hyphen glyph width', [[['line'], ['type'], ['of'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['line']], 12, 1], ['line type of', 'paragraph', 'hyphenation', 'kerning line']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['to'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['a'], ['text'], ['a'], ['break', 'ing']], 7, 3], ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']), ('control layout', [[['break', 'ing'], ['to'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['text']], 12, 1], ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text']), ('control layout', [[['jus', 'ti', 'fied'], ['type'], ['type'], ['kern', 'ing'], ['lead', 'ing']], 6, 3], ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'])], [('regression: hyphen glyph width', [[['com', 'po', 'si', 'tion'], ['of'], ['break', 'ing'], ['col', 'umn'], ['to'], ['break', 'ing'], ['pa', 'ra', 'graph'], ['of'], ['kern', 'ing'], ['to']], 11, 3], ['composition', 'of breaking', 'column to', 'breaking', 'paragraph', 'of kerning', 'to']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['line'], ['line'], ['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['of'], ['break', 'ing'], ['break', 'ing'], ['pa', 'ra', 'graph']], 9, 2], ['leading', 'line line', 'composi-', 'tion jus-', 'tified to', 'of break-', 'ing', 'breaking', 'paragraph']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['text'], ['line'], ['break', 'ing'], ['of']], 11, 2], ['interna-', 'tional hy-', 'phenation', 'hyphenation', 'interna-', 'tional', 'breaking', 'hyphenation', 'text line', 'breaking of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['type'], ['kern', 'ing'], ['text'], ['a'], ['a'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied']], 14, 2], ['leading hy-', 'phenation com-', 'position type', 'kerning text a', 'a to interna-', 'tional to', 'justified']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['mar', 'gin'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['type'], ['line'], ['lead', 'ing']], 8, 3], ['margin', 'para-', 'graph', 'justi-', 'fied', 'type', 'line', 'leading']), ('control layout', [[['to'], ['lead', 'ing'], ['com', 'po', 'si', 'tion'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['type']], 13, 3], ['to leading', 'composition', 'column compo-', 'sition type'])], [('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('regression: hyphen glyph width', [[['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['set', 'ting']], 11, 3], ['kerning', 'composition', 'to interna-', 'tional line', 'column hy-', 'phenation', 'setting', 'line', 'setting']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['text'], ['of'], ['of'], ['pa', 'ra', 'graph'], ['to'], ['col', 'umn'], ['kern', 'ing'], ['kern', 'ing']], 6, 1], ['margin', 'justi-', 'fied', 'compo-', 'sition', 'text', 'of of', 'para-', 'graph', 'to', 'column', 'kern-', 'ing', 'kerning']), ('regression: hyphen glyph width', [[['to'], ['lead', 'ing'], ['to'], ['pa', 'ra', 'graph'], ['line'], ['com', 'po', 'si', 'tion'], ['break', 'ing'], ['lead', 'ing'], ['break', 'ing']], 12, 1], ['to leading', 'to paragraph', 'line compo-', 'sition', 'breaking', 'leading', 'breaking']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['mar', 'gin'], ['mar', 'gin'], ['line'], ['text'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['col', 'umn'], ['line']], 8, 2], ['margin', 'margin', 'line', 'text hy-', 'phena-', 'tion', 'setting', 'column', 'line']), ('control layout', [[['text'], ['line'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['set', 'ting']], 14, 2], ['text line hy-', 'phenation in-', 'ternational', 'composition', 'setting'])], [('regression: hyphen glyph width', [[['lead', 'ing'], ['lead', 'ing'], ['col', 'umn'], ['mar', 'gin'], ['col', 'umn'], ['lead', 'ing']], 14, 2], ['leading lead-', 'ing column', 'margin column', 'leading']), ('regression: hyphen glyph width', [[['line'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing'], ['a'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn'], ['lead', 'ing']], 12, 3], ['line column', 'composition', 'setting', 'leading a', 'hyphenation', 'column', 'leading']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['a'], ['text'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['type'], ['mar', 'gin'], ['set', 'ting']], 11, 2], ['paragraph a', 'text hy-', 'phenation', 'hyphenation', 'paragraph', 'hyphenation', 'justified', 'to type', 'margin', 'setting']), ('regression: hyphen glyph width', [[['set', 'ting'], ['type'], ['of'], ['a'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn']], 7, 3], ['setting', 'type of', 'a com-', 'posi-', 'tion', 'compo-', 'sition', 'inter-', 'nation-', 'al', 'column']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['lead', 'ing'], ['text'], ['line'], ['com', 'po', 'si', 'tion']], 13, 3], ['leading lead-', 'ing text line', 'composition']), ('control layout', [[['a'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['type'], ['to']], 13, 3], ['a composition', 'leading mar-', 'gin hyphena-', 'tion margin', 'type to'])], [('regression: hyphen glyph width', [[['col', 'umn'], ['to'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['of']], 7, 1], ['column', 'to com-', 'position', 'compo-', 'sition', 'of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['text'], ['of'], ['jus', 'ti', 'fied'], ['type'], ['kern', 'ing']], 12, 1], ['leading', 'kerning hy-', 'phenation', 'kerning col-', 'umn', 'composition', 'leading text', 'of justified', 'type kerning']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['com', 'po', 'si', 'tion'], ['of'], ['com', 'po', 'si', 'tion'], ['type']], 10, 3], ['margin', 'composi-', 'tion of', 'composi-', 'tion type']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['a'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['text'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph']], 7, 3], ['inter-', 'nation-', 'al a', 'setting', 'margin', 'text', 'text', 'justi-', 'fied', 'break-', 'ing', 'column', 'hyphen-', 'ation', 'paragraph']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['text'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['type'], ['pa', 'ra', 'graph']], 13, 3], ['international', 'margin text', 'column set-', 'ting margin', 'hyphenation', 'type', 'paragraph'])]]
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 |
|---|---|---|---|
| ladder of three hyphenated lines | ['interna-', 'tional', 'composi-', 'tion hy-', 'phenation', 'text'] | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | Failed |
| regression: hyphen glyph width | ['internation-', 'al interna-', 'tional', 'justified hy-', 'phenation', 'type hyphena-', 'tion text'] | ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text'] | Failed |
| regression: hyphen glyph width | ['line type of', 'paragraph hy-', 'phenation', 'kerning line'] | ['line type of', 'paragraph', 'hyphenation', 'kerning line'] | Failed |
| regression: hyphen glyph width | ['paragraph', 'breaking a', 'column set-', 'ting mar-', 'gin text', 'kerning', 'justified', 'interna-', 'tional', 'breaking'] | ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking'] | Failed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | Passed |
| control layout | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | Passed |
| control layout | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | Passed |
SHA-256 / 730cfcc6c79d829291daba90f61823180a30203cd61193a6dfb23b4c183fb288
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
words, width, limit = x
queue = [list(w) for w in words]
lines = []
cur = ''
streak = 0
k = 0
while k < len(queue):
syl = queue[k]
token = ''.join(syl)
need = len(token) if cur == '' else len(cur) + 1 + len(token)
if need <= width:
cur = token if cur == '' else cur + ' ' + token
k += 1
continue
split = None
if streak < limit and k < len(queue) - 1:
for cut in range(len(syl) - 1, 0, -1):
head = ''.join(syl[:cut]) + '-'
room = len(head) if cur == '' else len(cur) + len(head)
if room <= width:
split = cut
break
if split is not None:
head = ''.join(syl[:split]) + '-'
lines.append(head if cur == '' else cur + ' ' + head)
queue[k] = syl[split:]
cur = ''
streak += 1
elif cur == '':
lines.append(token)
k += 1
streak = 0
else:
lines.append(cur)
cur, streak = '', 0
if cur:
lines.append(cur)
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['text']], 12, 2], ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text']), ('regression: hyphen glyph width', [[['line'], ['type'], ['of'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['line']], 12, 1], ['line type of', 'paragraph', 'hyphenation', 'kerning line']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['to'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['a'], ['text'], ['a'], ['break', 'ing']], 7, 3], ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']), ('control layout', [[['break', 'ing'], ['to'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['text']], 12, 1], ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text']), ('control layout', [[['jus', 'ti', 'fied'], ['type'], ['type'], ['kern', 'ing'], ['lead', 'ing']], 6, 3], ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'])], [('regression: hyphen glyph width', [[['com', 'po', 'si', 'tion'], ['of'], ['break', 'ing'], ['col', 'umn'], ['to'], ['break', 'ing'], ['pa', 'ra', 'graph'], ['of'], ['kern', 'ing'], ['to']], 11, 3], ['composition', 'of breaking', 'column to', 'breaking', 'paragraph', 'of kerning', 'to']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['line'], ['line'], ['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['of'], ['break', 'ing'], ['break', 'ing'], ['pa', 'ra', 'graph']], 9, 2], ['leading', 'line line', 'composi-', 'tion jus-', 'tified to', 'of break-', 'ing', 'breaking', 'paragraph']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['text'], ['line'], ['break', 'ing'], ['of']], 11, 2], ['interna-', 'tional hy-', 'phenation', 'hyphenation', 'interna-', 'tional', 'breaking', 'hyphenation', 'text line', 'breaking of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['type'], ['kern', 'ing'], ['text'], ['a'], ['a'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied']], 14, 2], ['leading hy-', 'phenation com-', 'position type', 'kerning text a', 'a to interna-', 'tional to', 'justified']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['mar', 'gin'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['type'], ['line'], ['lead', 'ing']], 8, 3], ['margin', 'para-', 'graph', 'justi-', 'fied', 'type', 'line', 'leading']), ('control layout', [[['to'], ['lead', 'ing'], ['com', 'po', 'si', 'tion'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['type']], 13, 3], ['to leading', 'composition', 'column compo-', 'sition type'])], [('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('regression: hyphen glyph width', [[['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['set', 'ting']], 11, 3], ['kerning', 'composition', 'to interna-', 'tional line', 'column hy-', 'phenation', 'setting', 'line', 'setting']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['text'], ['of'], ['of'], ['pa', 'ra', 'graph'], ['to'], ['col', 'umn'], ['kern', 'ing'], ['kern', 'ing']], 6, 1], ['margin', 'justi-', 'fied', 'compo-', 'sition', 'text', 'of of', 'para-', 'graph', 'to', 'column', 'kern-', 'ing', 'kerning']), ('regression: hyphen glyph width', [[['to'], ['lead', 'ing'], ['to'], ['pa', 'ra', 'graph'], ['line'], ['com', 'po', 'si', 'tion'], ['break', 'ing'], ['lead', 'ing'], ['break', 'ing']], 12, 1], ['to leading', 'to paragraph', 'line compo-', 'sition', 'breaking', 'leading', 'breaking']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['mar', 'gin'], ['mar', 'gin'], ['line'], ['text'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['col', 'umn'], ['line']], 8, 2], ['margin', 'margin', 'line', 'text hy-', 'phena-', 'tion', 'setting', 'column', 'line']), ('control layout', [[['text'], ['line'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['set', 'ting']], 14, 2], ['text line hy-', 'phenation in-', 'ternational', 'composition', 'setting'])], [('regression: hyphen glyph width', [[['lead', 'ing'], ['lead', 'ing'], ['col', 'umn'], ['mar', 'gin'], ['col', 'umn'], ['lead', 'ing']], 14, 2], ['leading lead-', 'ing column', 'margin column', 'leading']), ('regression: hyphen glyph width', [[['line'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing'], ['a'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn'], ['lead', 'ing']], 12, 3], ['line column', 'composition', 'setting', 'leading a', 'hyphenation', 'column', 'leading']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['a'], ['text'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['type'], ['mar', 'gin'], ['set', 'ting']], 11, 2], ['paragraph a', 'text hy-', 'phenation', 'hyphenation', 'paragraph', 'hyphenation', 'justified', 'to type', 'margin', 'setting']), ('regression: hyphen glyph width', [[['set', 'ting'], ['type'], ['of'], ['a'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn']], 7, 3], ['setting', 'type of', 'a com-', 'posi-', 'tion', 'compo-', 'sition', 'inter-', 'nation-', 'al', 'column']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['lead', 'ing'], ['text'], ['line'], ['com', 'po', 'si', 'tion']], 13, 3], ['leading lead-', 'ing text line', 'composition']), ('control layout', [[['a'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['type'], ['to']], 13, 3], ['a composition', 'leading mar-', 'gin hyphena-', 'tion margin', 'type to'])], [('regression: hyphen glyph width', [[['col', 'umn'], ['to'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['of']], 7, 1], ['column', 'to com-', 'position', 'compo-', 'sition', 'of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['text'], ['of'], ['jus', 'ti', 'fied'], ['type'], ['kern', 'ing']], 12, 1], ['leading', 'kerning hy-', 'phenation', 'kerning col-', 'umn', 'composition', 'leading text', 'of justified', 'type kerning']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['com', 'po', 'si', 'tion'], ['of'], ['com', 'po', 'si', 'tion'], ['type']], 10, 3], ['margin', 'composi-', 'tion of', 'composi-', 'tion type']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['a'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['text'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph']], 7, 3], ['inter-', 'nation-', 'al a', 'setting', 'margin', 'text', 'text', 'justi-', 'fied', 'break-', 'ing', 'column', 'hyphen-', 'ation', 'paragraph']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['text'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['type'], ['pa', 'ra', 'graph']], 13, 3], ['international', 'margin text', 'column set-', 'ting margin', 'hyphenation', 'type', 'paragraph'])]]
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 |
|---|---|---|---|
| ladder of three hyphenated lines | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | Passed |
| regression: hyphen glyph width | ['internation-', 'al interna-', 'tional', 'justified hy-', 'phenation', 'type hyphena-', 'tion text'] | ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text'] | Failed |
| regression: hyphen glyph width | ['line type of', 'paragraph hy-', 'phenation', 'kerning line'] | ['line type of', 'paragraph', 'hyphenation', 'kerning line'] | Failed |
| regression: hyphen glyph width | ['paragraph', 'breaking a', 'column set-', 'ting mar-', 'gin text', 'kerning', 'justified', 'interna-', 'tional', 'breaking'] | ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking'] | Failed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | Passed |
| control layout | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | Passed |
| control layout | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | Passed |
SHA-256 / 2245e3b018f4e7f4f8810d4cfef96c8cbc0cfe09200058fd7a8fee989ead9dc3
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
words, width, limit = x
queue = [list(w) for w in words]
lines = []
cur = ''
streak = 0
k = 0
while k < len(queue):
syl = queue[k]
token = ''.join(syl)
need = len(token) if cur == '' else len(cur) + 1 + len(token)
if need <= width:
cur = token if cur == '' else cur + ' ' + token
k += 1
continue
split = None
if streak < limit and k < len(queue) - 1:
for cut in range(len(syl) - 1, 0, -1):
head = ''.join(syl[:cut]) + '-'
room = len(head) if cur == '' else len(cur) + len(head) + 1
if room <= width:
split = cut
break
if split is not None:
head = ''.join(syl[:split]) + '-'
lines.append(head if cur == '' else cur + ' ' + head)
queue[k] = syl[split:]
cur = ''
streak += 1
elif cur == '':
lines.append(token)
k += 1
streak = 0
else:
lines.append(cur)
cur, streak = '', 0
if cur:
lines.append(cur)
return lines
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['type'], ['hy', 'phen', 'a', 'tion'], ['text']], 12, 2], ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text']), ('regression: hyphen glyph width', [[['line'], ['type'], ['of'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['line']], 12, 1], ['line type of', 'paragraph', 'hyphenation', 'kerning line']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['to'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['a'], ['text'], ['a'], ['break', 'ing']], 7, 3], ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']), ('control layout', [[['break', 'ing'], ['to'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['text']], 12, 1], ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text']), ('control layout', [[['jus', 'ti', 'fied'], ['type'], ['type'], ['kern', 'ing'], ['lead', 'ing']], 6, 3], ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'])], [('regression: hyphen glyph width', [[['com', 'po', 'si', 'tion'], ['of'], ['break', 'ing'], ['col', 'umn'], ['to'], ['break', 'ing'], ['pa', 'ra', 'graph'], ['of'], ['kern', 'ing'], ['to']], 11, 3], ['composition', 'of breaking', 'column to', 'breaking', 'paragraph', 'of kerning', 'to']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['line'], ['line'], ['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['of'], ['break', 'ing'], ['break', 'ing'], ['pa', 'ra', 'graph']], 9, 2], ['leading', 'line line', 'composi-', 'tion jus-', 'tified to', 'of break-', 'ing', 'breaking', 'paragraph']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['text'], ['line'], ['break', 'ing'], ['of']], 11, 2], ['interna-', 'tional hy-', 'phenation', 'hyphenation', 'interna-', 'tional', 'breaking', 'hyphenation', 'text line', 'breaking of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['type'], ['kern', 'ing'], ['text'], ['a'], ['a'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied']], 14, 2], ['leading hy-', 'phenation com-', 'position type', 'kerning text a', 'a to interna-', 'tional to', 'justified']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('control layout', [[['mar', 'gin'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['type'], ['line'], ['lead', 'ing']], 8, 3], ['margin', 'para-', 'graph', 'justi-', 'fied', 'type', 'line', 'leading']), ('control layout', [[['to'], ['lead', 'ing'], ['com', 'po', 'si', 'tion'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['type']], 13, 3], ['to leading', 'composition', 'column compo-', 'sition type'])], [('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['a'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing']], 10, 2], ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking']), ('regression: hyphen glyph width', [[['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['set', 'ting']], 11, 3], ['kerning', 'composition', 'to interna-', 'tional line', 'column hy-', 'phenation', 'setting', 'line', 'setting']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['text'], ['of'], ['of'], ['pa', 'ra', 'graph'], ['to'], ['col', 'umn'], ['kern', 'ing'], ['kern', 'ing']], 6, 1], ['margin', 'justi-', 'fied', 'compo-', 'sition', 'text', 'of of', 'para-', 'graph', 'to', 'column', 'kern-', 'ing', 'kerning']), ('regression: hyphen glyph width', [[['to'], ['lead', 'ing'], ['to'], ['pa', 'ra', 'graph'], ['line'], ['com', 'po', 'si', 'tion'], ['break', 'ing'], ['lead', 'ing'], ['break', 'ing']], 12, 1], ['to leading', 'to paragraph', 'line compo-', 'sition', 'breaking', 'leading', 'breaking']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['mar', 'gin'], ['mar', 'gin'], ['line'], ['text'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['col', 'umn'], ['line']], 8, 2], ['margin', 'margin', 'line', 'text hy-', 'phena-', 'tion', 'setting', 'column', 'line']), ('control layout', [[['text'], ['line'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['set', 'ting']], 14, 2], ['text line hy-', 'phenation in-', 'ternational', 'composition', 'setting'])], [('regression: hyphen glyph width', [[['lead', 'ing'], ['lead', 'ing'], ['col', 'umn'], ['mar', 'gin'], ['col', 'umn'], ['lead', 'ing']], 14, 2], ['leading lead-', 'ing column', 'margin column', 'leading']), ('regression: hyphen glyph width', [[['line'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing'], ['a'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn'], ['lead', 'ing']], 12, 3], ['line column', 'composition', 'setting', 'leading a', 'hyphenation', 'column', 'leading']), ('regression: hyphen glyph width', [[['pa', 'ra', 'graph'], ['a'], ['text'], ['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['to'], ['type'], ['mar', 'gin'], ['set', 'ting']], 11, 2], ['paragraph a', 'text hy-', 'phenation', 'hyphenation', 'paragraph', 'hyphenation', 'justified', 'to type', 'margin', 'setting']), ('regression: hyphen glyph width', [[['set', 'ting'], ['type'], ['of'], ['a'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn']], 7, 3], ['setting', 'type of', 'a com-', 'posi-', 'tion', 'compo-', 'sition', 'inter-', 'nation-', 'al', 'column']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['lead', 'ing'], ['text'], ['line'], ['com', 'po', 'si', 'tion']], 13, 3], ['leading lead-', 'ing text line', 'composition']), ('control layout', [[['a'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['type'], ['to']], 13, 3], ['a composition', 'leading mar-', 'gin hyphena-', 'tion margin', 'type to'])], [('regression: hyphen glyph width', [[['col', 'umn'], ['to'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['of']], 7, 1], ['column', 'to com-', 'position', 'compo-', 'sition', 'of']), ('regression: hyphen glyph width', [[['lead', 'ing'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['lead', 'ing'], ['text'], ['of'], ['jus', 'ti', 'fied'], ['type'], ['kern', 'ing']], 12, 1], ['leading', 'kerning hy-', 'phenation', 'kerning col-', 'umn', 'composition', 'leading text', 'of justified', 'type kerning']), ('regression: hyphen glyph width', [[['mar', 'gin'], ['com', 'po', 'si', 'tion'], ['of'], ['com', 'po', 'si', 'tion'], ['type']], 10, 3], ['margin', 'composi-', 'tion of', 'composi-', 'tion type']), ('regression: hyphen glyph width', [[['in', 'ter', 'na', 'tion', 'al'], ['a'], ['set', 'ting'], ['mar', 'gin'], ['text'], ['text'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph']], 7, 3], ['inter-', 'nation-', 'al a', 'setting', 'margin', 'text', 'text', 'justi-', 'fied', 'break-', 'ing', 'column', 'hyphen-', 'ation', 'paragraph']), ('ladder of three hyphenated lines', [[['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['text']], 7, 2], ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['text'], ['col', 'umn'], ['set', 'ting'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['type'], ['pa', 'ra', 'graph']], 13, 3], ['international', 'margin text', 'column set-', 'ting margin', 'hyphenation', 'type', 'paragraph'])]]
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 |
|---|---|---|---|
| ladder of three hyphenated lines | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | Passed |
| regression: hyphen glyph width | ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text'] | ['internation-', 'al interna-', 'tional', 'justified', 'hyphenation', 'type hyphen-', 'ation text'] | Passed |
| regression: hyphen glyph width | ['line type of', 'paragraph', 'hyphenation', 'kerning line'] | ['line type of', 'paragraph', 'hyphenation', 'kerning line'] | Passed |
| regression: hyphen glyph width | ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking'] | ['paragraph', 'breaking a', 'column', 'setting', 'margin', 'text kern-', 'ing justi-', 'fied', 'interna-', 'tional', 'breaking'] | Passed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | ['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking'] | Passed |
| control layout | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | ['breaking to', 'setting in-', 'ternational', 'breaking to', 'internation-', 'al text'] | Passed |
| control layout | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | ['justi-', 'fied', 'type', 'type', 'kern-', 'ing', 'leading'] | Passed |
SHA-256 / 0e81b864cf24659e9282dd987c5276942875e31f5531439dbfc92df8e2e9464e
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:49.226093+00:00.
Case digest / 5c27fc45722e21dd0f7b1b3666ac9af087db0481f0bcf1c9c70fe8e5d8354c37