FA-79956 / Typography line breaking / Open access
Consecutive hyphen limit: ladder limit comparison · case 01
One more consecutive hyphen than allowed is produced.
ROOT CAUSE
The limit check uses <= so the streak may reach limit+1.
VERIFIED REPAIR
Permit a split only while the streak is below the limit.
Unsuccessful approach: Using limit - 1 forbids the last allowed hyphen.
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) 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: ladder limit comparison', [[['to'], ['line'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['mar', 'gin'], ['type'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn'], ['line'], ['com', 'po', 'si', 'tion'], ['to']], 14, 1], ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['to'], ['lead', 'ing'], ['a']], 7, 1], ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a']), ('partial-repair probe', [[['lead', 'ing'], ['a'], ['col', 'umn'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['a']], 11, 2], ['leading a', 'column col-', 'umn compo-', 'sition a']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['col', 'umn'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['line'], ['line'], ['a']], 12, 2], ['column kern-', 'ing text', 'column line', 'line a']), ('control layout', [[['line'], ['of'], ['mar', 'gin'], ['a'], ['text'], ['line'], ['a'], ['pa', 'ra', 'graph'], ['of'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['break', 'ing']], 7, 3], ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking']), ('control layout', [[['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['type'], ['col', 'umn'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting']], 8, 2], ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'])], [('regression: ladder limit comparison', [[['mar', 'gin'], ['mar', 'gin'], ['break', 'ing'], ['text'], ['of'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['line']], 8, 2], ['margin', 'margin', 'breaking', 'text of', 'leading', 'hyphena-', 'tion in-', 'ternational', 'line']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['kern', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['a'], ['col', 'umn'], ['pa', 'ra', 'graph']], 6, 1], ['margin', 'kern-', 'ing', 'column', 'hy-', 'phenation', 'a col-', 'umn', 'paragraph']), ('regression: ladder limit comparison', [[['kern', 'ing'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['to'], ['pa', 'ra', 'graph']], 10, 1], ['kerning to', 'kerning', 'hyphena-', 'tion to', 'hyphena-', 'tion', 'margin to', 'paragraph']), ('partial-repair probe', [[['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['to'], ['text'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['of'], ['kern', 'ing']], 12, 2], ['composition', 'to breaking', 'to text jus-', 'tified set-', 'ting of', 'kerning']), ('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', [[['lead', 'ing'], ['break', 'ing'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['text'], ['pa', 'ra', 'graph'], ['line']], 12, 3], ['leading', 'breaking a', 'internation-', 'al a margin', 'text para-', 'graph line']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['jus', 'ti', 'fied'], ['to'], ['type'], ['of'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['type'], ['hy', 'phen', 'a', 'tion']], 14, 3], ['justified to', 'type of kern-', 'ing composi-', 'tion to kern-', 'ing', 'international', 'leading type', 'hyphenation']), ('regression: ladder limit comparison', [[['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['mar', 'gin'], ['com', 'po', 'si', 'tion']], 6, 1], ['compo-', 'sition', 'justi-', 'fied', 'hy-', 'phenation', 'set-', 'ting', 'margin', 'composition']), ('partial-repair probe', [[['text'], ['col', 'umn'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['to'], ['text'], ['a']], 7, 1], ['text', 'column', 'text a', 'justi-', 'fied', 'compo-', 'sition', 'hyphen-', 'ation', 'to text', 'a']), ('regression: ladder limit comparison', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1], ['breaking com-', 'position', 'international', 'setting com-', 'position', 'composition', 'to breaking', 'international']), ('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', [[['line'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['of'], ['col', 'umn'], ['pa', 'ra', 'graph'], ['a']], 13, 3], ['line leading', 'international', 'margin set-', 'ting column', 'justified of', 'column para-', 'graph a']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['type'], ['break', 'ing'], ['set', 'ting'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['text']], 9, 1], ['paragraph', 'interna-', 'tional', 'type', 'breaking', 'setting', 'hyphena-', 'tion', 'setting', 'justified', 'text']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['type'], ['col', 'umn'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph']], 9, 1], ['leading', 'type col-', 'umn', 'column', 'hyphena-', 'tion line', 'interna-', 'tional', 'paragraph']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['of'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph']], 8, 2], ['margin', 'of col-', 'umn in-', 'ternational', 'interna-', 'tional', 'kerning', 'margin', 'paragraph']), ('partial-repair probe', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', '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', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['of'], ['type'], ['type'], ['com', 'po', 'si', 'tion'], ['text'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion']], 9, 3], ['of type', 'type com-', 'position', 'text jus-', 'tified', 'hyphenation'])], [('regression: ladder limit comparison', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['text'], ['hy', 'phen', 'a', 'tion']], 13, 1], ['line interna-', 'tional', 'international', 'text composi-', 'tion to', 'hyphenation', 'international', 'kerning com-', 'position text', 'hyphenation']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['lead', 'ing'], ['set', 'ting'], ['kern', 'ing'], ['break', 'ing'], ['type'], ['mar', 'gin'], ['type'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied']], 8, 2], ['leading', 'leading', 'setting', 'kerning', 'breaking', 'type', 'margin', 'type', 'setting', 'composi-', 'tion in-', 'ternational', 'justified']), ('regression: ladder limit comparison', [[['a'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['pa', 'ra', 'graph']], 11, 1], ['a kerning', 'interna-', 'tional', 'setting', 'paragraph']), ('partial-repair probe', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('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', [[['type'], ['set', 'ting'], ['a'], ['a'], ['break', 'ing'], ['kern', 'ing'], ['mar', 'gin'], ['type'], ['of'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['type set-', 'ting a a', 'breaking', 'kerning', 'margin', 'type of', 'hyphenation']), ('control layout', [[['break', 'ing'], ['mar', 'gin'], ['mar', 'gin'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['lead', 'ing']], 12, 2], ['breaking', 'margin mar-', 'gin leading', 'internation-', 'al line', 'leading'])]]
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 com-', 'position', 'hyphen-', 'ation', 'text'] | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | Failed |
| regression: ladder limit comparison | ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national col-', 'umn line', 'composition to'] | ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to'] | Failed |
| partial-repair probe | ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a'] | ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a'] | Passed |
| partial-repair probe | ['leading a', 'column col-', 'umn compo-', 'sition a'] | ['leading a', 'column col-', 'umn compo-', 'sition a'] | Passed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['column kern-', 'ing text', 'column line', 'line a'] | ['column kern-', 'ing text', 'column line', 'line a'] | Passed |
| control layout | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | Passed |
| control layout | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | Passed |
SHA-256 / e69b21f169fa05987a402c3c539773408660f95057f52bb76e3e0f9f7916da13
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 - 1 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: ladder limit comparison', [[['to'], ['line'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['mar', 'gin'], ['type'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn'], ['line'], ['com', 'po', 'si', 'tion'], ['to']], 14, 1], ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['to'], ['lead', 'ing'], ['a']], 7, 1], ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a']), ('partial-repair probe', [[['lead', 'ing'], ['a'], ['col', 'umn'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['a']], 11, 2], ['leading a', 'column col-', 'umn compo-', 'sition a']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['col', 'umn'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['line'], ['line'], ['a']], 12, 2], ['column kern-', 'ing text', 'column line', 'line a']), ('control layout', [[['line'], ['of'], ['mar', 'gin'], ['a'], ['text'], ['line'], ['a'], ['pa', 'ra', 'graph'], ['of'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['break', 'ing']], 7, 3], ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking']), ('control layout', [[['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['type'], ['col', 'umn'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting']], 8, 2], ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'])], [('regression: ladder limit comparison', [[['mar', 'gin'], ['mar', 'gin'], ['break', 'ing'], ['text'], ['of'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['line']], 8, 2], ['margin', 'margin', 'breaking', 'text of', 'leading', 'hyphena-', 'tion in-', 'ternational', 'line']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['kern', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['a'], ['col', 'umn'], ['pa', 'ra', 'graph']], 6, 1], ['margin', 'kern-', 'ing', 'column', 'hy-', 'phenation', 'a col-', 'umn', 'paragraph']), ('regression: ladder limit comparison', [[['kern', 'ing'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['to'], ['pa', 'ra', 'graph']], 10, 1], ['kerning to', 'kerning', 'hyphena-', 'tion to', 'hyphena-', 'tion', 'margin to', 'paragraph']), ('partial-repair probe', [[['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['to'], ['text'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['of'], ['kern', 'ing']], 12, 2], ['composition', 'to breaking', 'to text jus-', 'tified set-', 'ting of', 'kerning']), ('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', [[['lead', 'ing'], ['break', 'ing'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['text'], ['pa', 'ra', 'graph'], ['line']], 12, 3], ['leading', 'breaking a', 'internation-', 'al a margin', 'text para-', 'graph line']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['jus', 'ti', 'fied'], ['to'], ['type'], ['of'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['type'], ['hy', 'phen', 'a', 'tion']], 14, 3], ['justified to', 'type of kern-', 'ing composi-', 'tion to kern-', 'ing', 'international', 'leading type', 'hyphenation']), ('regression: ladder limit comparison', [[['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['mar', 'gin'], ['com', 'po', 'si', 'tion']], 6, 1], ['compo-', 'sition', 'justi-', 'fied', 'hy-', 'phenation', 'set-', 'ting', 'margin', 'composition']), ('partial-repair probe', [[['text'], ['col', 'umn'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['to'], ['text'], ['a']], 7, 1], ['text', 'column', 'text a', 'justi-', 'fied', 'compo-', 'sition', 'hyphen-', 'ation', 'to text', 'a']), ('regression: ladder limit comparison', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1], ['breaking com-', 'position', 'international', 'setting com-', 'position', 'composition', 'to breaking', 'international']), ('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', [[['line'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['of'], ['col', 'umn'], ['pa', 'ra', 'graph'], ['a']], 13, 3], ['line leading', 'international', 'margin set-', 'ting column', 'justified of', 'column para-', 'graph a']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['type'], ['break', 'ing'], ['set', 'ting'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['text']], 9, 1], ['paragraph', 'interna-', 'tional', 'type', 'breaking', 'setting', 'hyphena-', 'tion', 'setting', 'justified', 'text']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['type'], ['col', 'umn'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph']], 9, 1], ['leading', 'type col-', 'umn', 'column', 'hyphena-', 'tion line', 'interna-', 'tional', 'paragraph']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['of'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph']], 8, 2], ['margin', 'of col-', 'umn in-', 'ternational', 'interna-', 'tional', 'kerning', 'margin', 'paragraph']), ('partial-repair probe', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', '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', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['of'], ['type'], ['type'], ['com', 'po', 'si', 'tion'], ['text'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion']], 9, 3], ['of type', 'type com-', 'position', 'text jus-', 'tified', 'hyphenation'])], [('regression: ladder limit comparison', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['text'], ['hy', 'phen', 'a', 'tion']], 13, 1], ['line interna-', 'tional', 'international', 'text composi-', 'tion to', 'hyphenation', 'international', 'kerning com-', 'position text', 'hyphenation']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['lead', 'ing'], ['set', 'ting'], ['kern', 'ing'], ['break', 'ing'], ['type'], ['mar', 'gin'], ['type'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied']], 8, 2], ['leading', 'leading', 'setting', 'kerning', 'breaking', 'type', 'margin', 'type', 'setting', 'composi-', 'tion in-', 'ternational', 'justified']), ('regression: ladder limit comparison', [[['a'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['pa', 'ra', 'graph']], 11, 1], ['a kerning', 'interna-', 'tional', 'setting', 'paragraph']), ('partial-repair probe', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('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', [[['type'], ['set', 'ting'], ['a'], ['a'], ['break', 'ing'], ['kern', 'ing'], ['mar', 'gin'], ['type'], ['of'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['type set-', 'ting a a', 'breaking', 'kerning', 'margin', 'type of', 'hyphenation']), ('control layout', [[['break', 'ing'], ['mar', 'gin'], ['mar', 'gin'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['lead', 'ing']], 12, 2], ['breaking', 'margin mar-', 'gin leading', 'internation-', 'al line', 'leading'])]]
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-', 'national', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | ['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text'] | Failed |
| regression: ladder limit comparison | ['to line', 'composition', 'margin margin', 'type kerning', 'international', 'column line', 'composition to'] | ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to'] | Failed |
| partial-repair probe | ['justified', 'paragraph', 'justified', 'paragraph', 'kerning', 'to', 'leading', 'a'] | ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a'] | Failed |
| partial-repair probe | ['leading a', 'column col-', 'umn', 'composition', 'a'] | ['leading a', 'column col-', 'umn compo-', 'sition a'] | Failed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['column kern-', 'ing text', 'column line', 'line a'] | ['column kern-', 'ing text', 'column line', 'line a'] | Passed |
| control layout | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | Passed |
| control layout | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | Passed |
SHA-256 / 836a26dd38a20b3ae9b9398d8d63b169b8961703d0e621d812cf305009cc145c
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: ladder limit comparison', [[['to'], ['line'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['mar', 'gin'], ['type'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['col', 'umn'], ['line'], ['com', 'po', 'si', 'tion'], ['to']], 14, 1], ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['jus', 'ti', 'fied'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['to'], ['lead', 'ing'], ['a']], 7, 1], ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a']), ('partial-repair probe', [[['lead', 'ing'], ['a'], ['col', 'umn'], ['col', 'umn'], ['com', 'po', 'si', 'tion'], ['a']], 11, 2], ['leading a', 'column col-', 'umn compo-', 'sition a']), ('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('control layout', [[['col', 'umn'], ['kern', 'ing'], ['text'], ['col', 'umn'], ['line'], ['line'], ['a']], 12, 2], ['column kern-', 'ing text', 'column line', 'line a']), ('control layout', [[['line'], ['of'], ['mar', 'gin'], ['a'], ['text'], ['line'], ['a'], ['pa', 'ra', 'graph'], ['of'], ['com', 'po', 'si', 'tion'], ['kern', 'ing'], ['break', 'ing']], 7, 3], ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking']), ('control layout', [[['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['type'], ['col', 'umn'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting']], 8, 2], ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'])], [('regression: ladder limit comparison', [[['mar', 'gin'], ['mar', 'gin'], ['break', 'ing'], ['text'], ['of'], ['lead', 'ing'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['line']], 8, 2], ['margin', 'margin', 'breaking', 'text of', 'leading', 'hyphena-', 'tion in-', 'ternational', 'line']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['kern', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['a'], ['col', 'umn'], ['pa', 'ra', 'graph']], 6, 1], ['margin', 'kern-', 'ing', 'column', 'hy-', 'phenation', 'a col-', 'umn', 'paragraph']), ('regression: ladder limit comparison', [[['kern', 'ing'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['to'], ['pa', 'ra', 'graph']], 10, 1], ['kerning to', 'kerning', 'hyphena-', 'tion to', 'hyphena-', 'tion', 'margin to', 'paragraph']), ('partial-repair probe', [[['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['to'], ['text'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['of'], ['kern', 'ing']], 12, 2], ['composition', 'to breaking', 'to text jus-', 'tified set-', 'ting of', 'kerning']), ('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', [[['lead', 'ing'], ['break', 'ing'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['a'], ['mar', 'gin'], ['text'], ['pa', 'ra', 'graph'], ['line']], 12, 3], ['leading', 'breaking a', 'internation-', 'al a margin', 'text para-', 'graph line']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['jus', 'ti', 'fied'], ['to'], ['type'], ['of'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['to'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['type'], ['hy', 'phen', 'a', 'tion']], 14, 3], ['justified to', 'type of kern-', 'ing composi-', 'tion to kern-', 'ing', 'international', 'leading type', 'hyphenation']), ('regression: ladder limit comparison', [[['com', 'po', 'si', 'tion'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['mar', 'gin'], ['com', 'po', 'si', 'tion']], 6, 1], ['compo-', 'sition', 'justi-', 'fied', 'hy-', 'phenation', 'set-', 'ting', 'margin', 'composition']), ('partial-repair probe', [[['text'], ['col', 'umn'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['to'], ['text'], ['a']], 7, 1], ['text', 'column', 'text a', 'justi-', 'fied', 'compo-', 'sition', 'hyphen-', 'ation', 'to text', 'a']), ('regression: ladder limit comparison', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['com', 'po', 'si', 'tion'], ['to'], ['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1], ['breaking com-', 'position', 'international', 'setting com-', 'position', 'composition', 'to breaking', 'international']), ('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', [[['line'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['of'], ['col', 'umn'], ['pa', 'ra', 'graph'], ['a']], 13, 3], ['line leading', 'international', 'margin set-', 'ting column', 'justified of', 'column para-', 'graph a']), ('control layout', [[['col', 'umn'], ['pa', 'ra', 'graph'], ['text'], ['pa', 'ra', 'graph'], ['break', 'ing'], ['of'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['of'], ['jus', 'ti', 'fied'], ['in', 'ter', 'na', 'tion', 'al']], 11, 2], ['column pa-', 'ragraph', 'text para-', 'graph', 'breaking of', 'hyphenation', 'kerning of', 'justified', 'international'])], [('regression: ladder limit comparison', [[['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['type'], ['break', 'ing'], ['set', 'ting'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['text']], 9, 1], ['paragraph', 'interna-', 'tional', 'type', 'breaking', 'setting', 'hyphena-', 'tion', 'setting', 'justified', 'text']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['type'], ['col', 'umn'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph']], 9, 1], ['leading', 'type col-', 'umn', 'column', 'hyphena-', 'tion line', 'interna-', 'tional', 'paragraph']), ('regression: ladder limit comparison', [[['mar', 'gin'], ['of'], ['col', 'umn'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['mar', 'gin'], ['pa', 'ra', 'graph']], 8, 2], ['margin', 'of col-', 'umn in-', 'ternational', 'interna-', 'tional', 'kerning', 'margin', 'paragraph']), ('partial-repair probe', [[['of'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['break', 'ing']], 8, 3], ['of jus-', 'tified', 'setting', 'composi-', 'tion in-', 'terna-', 'tional', 'composi-', 'tion in-', 'terna-', 'tional', 'para-', 'graph', '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', [[['lead', 'ing'], ['pa', 'ra', 'graph'], ['to'], ['mar', 'gin'], ['line'], ['jus', 'ti', 'fied']], 14, 3], ['leading para-', 'graph to mar-', 'gin line', 'justified']), ('control layout', [[['of'], ['type'], ['type'], ['com', 'po', 'si', 'tion'], ['text'], ['jus', 'ti', 'fied'], ['hy', 'phen', 'a', 'tion']], 9, 3], ['of type', 'type com-', 'position', 'text jus-', 'tified', 'hyphenation'])], [('regression: ladder limit comparison', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['com', 'po', 'si', 'tion'], ['text'], ['hy', 'phen', 'a', 'tion']], 13, 1], ['line interna-', 'tional', 'international', 'text composi-', 'tion to', 'hyphenation', 'international', 'kerning com-', 'position text', 'hyphenation']), ('regression: ladder limit comparison', [[['lead', 'ing'], ['lead', 'ing'], ['set', 'ting'], ['kern', 'ing'], ['break', 'ing'], ['type'], ['mar', 'gin'], ['type'], ['set', 'ting'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['jus', 'ti', 'fied']], 8, 2], ['leading', 'leading', 'setting', 'kerning', 'breaking', 'type', 'margin', 'type', 'setting', 'composi-', 'tion in-', 'ternational', 'justified']), ('regression: ladder limit comparison', [[['a'], ['kern', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['pa', 'ra', 'graph']], 11, 1], ['a kerning', 'interna-', 'tional', 'setting', 'paragraph']), ('partial-repair probe', [[['set', 'ting'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['of'], ['in', 'ter', 'na', 'tion', 'al'], ['to'], ['jus', 'ti', 'fied'], ['mar', 'gin'], ['line']], 8, 1], ['setting', 'leading', 'justi-', 'fied of', 'interna-', 'tional', 'to jus-', 'tified', 'margin', 'line']), ('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', [[['type'], ['set', 'ting'], ['a'], ['a'], ['break', 'ing'], ['kern', 'ing'], ['mar', 'gin'], ['type'], ['of'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['type set-', 'ting a a', 'breaking', 'kerning', 'margin', 'type of', 'hyphenation']), ('control layout', [[['break', 'ing'], ['mar', 'gin'], ['mar', 'gin'], ['lead', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['lead', 'ing']], 12, 2], ['breaking', 'margin mar-', 'gin leading', 'internation-', 'al line', 'leading'])]]
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: ladder limit comparison | ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to'] | ['to line compo-', 'sition margin', 'margin type', 'kerning inter-', 'national', 'column line', 'composition to'] | Passed |
| partial-repair probe | ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a'] | ['justi-', 'fied', 'para-', 'graph', 'justi-', 'fied', 'para-', 'graph', 'kerning', 'to', 'leading', 'a'] | Passed |
| partial-repair probe | ['leading a', 'column col-', 'umn compo-', 'sition a'] | ['leading a', 'column col-', 'umn compo-', 'sition a'] | Passed |
| last word never hyphenated | ['a', 'composition'] | ['a', 'composition'] | Passed |
| control layout | ['column kern-', 'ing text', 'column line', 'line a'] | ['column kern-', 'ing text', 'column line', 'line a'] | Passed |
| control layout | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | ['line of', 'margin', 'a text', 'line a', 'para-', 'graph', 'of com-', 'posi-', 'tion', 'kerning', 'breaking'] | Passed |
| control layout | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | ['kerning', 'hyphena-', 'tion', 'type', 'column', 'margin', 'kerning', 'setting'] | Passed |
SHA-256 / 6ad601e0d80479d3024b2b0b69abadf85480373397e9e334daee706220134aed
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.569668+00:00.
Case digest / 94f7146e92b51b200f7eb0014fc521454a652c0c3f5a60beaa979a77bc8f988a