FAILURE MAP
← Case archive

FA-79961 / Typography line breaking / Open access

Consecutive hyphen limit: final word protection · case 01

The paragraph's last word is split across lines.

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

ROOT CAUSE

The last-word guard compares against len(queue) so the final word is also eligible.

VERIFIED REPAIR

Never hyphenate the final word of the paragraph.

Unsuccessful approach: Guarding the last two words protects a word that may legally split.

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):
            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 = [[('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['text'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['line'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion']], 11, 1], ['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']), ('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('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', [[['kern', 'ing'], ['line'], ['type'], ['jus', 'ti', 'fied'], ['set', 'ting']], 11, 2], ['kerning', 'line type', 'justified', 'setting']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['set', 'ting'], ['a']], 10, 2], ['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']), ('control layout', [[['col', 'umn'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['type'], ['of'], ['of'], ['line'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['line']], 7, 3], ['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line'])], [('regression: final word protection', [[['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['breaking', 'margin hy-', 'phenation', 'justified', 'a hyphena-', 'tion com-', 'position', 'hyphenation']), ('regression: final word protection', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion']], 12, 1], ['paragraph', 'breaking', 'margin hy-', 'phenation', 'kerning jus-', 'tified to', 'kerning', 'hyphenation']), ('partial-repair probe', [[['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['of'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting']], 9, 3], ['breaking', 'interna-', 'tional', 'text of', 'setting', 'interna-', 'tional', 'line a', 'interna-', 'tional', 'setting']), ('regression: final word protection', [[['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['break', 'ing'], ['mar', 'gin'], ['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al']], 6, 1], ['compo-', 'sition', 'inter-', 'national', 'margin', 'break-', 'ing', 'margin', 'line', 'set-', 'ting', 'international']), ('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', [[['set', 'ting'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['type'], ['type'], ['text'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['a'], ['set', 'ting']], 11, 2], ['setting', 'justified', 'breaking', 'type type', 'text break-', 'ing hyphen-', 'ation a', 'setting']), ('control layout', [[['a'], ['line'], ['lead', 'ing'], ['break', 'ing'], ['text'], ['of'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['to'], ['type']], 6, 2], ['a line', 'lead-', 'ing', 'break-', 'ing', 'text', 'of', 'compo-', 'sition', 'to hy-', 'phena-', 'tion', 'to', 'type'])], [('regression: final word protection', [[['set', 'ting'], ['of'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['line'], ['set', 'ting'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin']], 11, 2], ['setting of', 'margin', 'kerning', 'setting', 'column line', 'setting a', 'interna-', 'tional', 'margin']), ('regression: final word protection', [[['a'], ['type'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['to'], ['to'], ['break', 'ing'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['type'], ['text'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['a type in-', 'ternation-', 'al leading', 'to to', 'breaking', 'composi-', 'tion hy-', 'phenation', 'type text', 'hyphenation']), ('regression: final word protection', [[['text'], ['line'], ['to'], ['text'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['of'], ['break', 'ing'], ['com', 'po', 'si', 'tion']], 10, 3], ['text line', 'to text', 'leading', 'justified', 'setting', 'justified', 'of break-', 'ing', 'composition']), ('regression: final word protection', [[['break', 'ing'], ['of'], ['set', 'ting'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 9, 3], ['breaking', 'of set-', 'ting mar-', 'gin', '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', [[['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['of'], ['text']], 7, 3], ['kerning', 'setting', 'column', 'of text']), ('control layout', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['to'], ['set', 'ting'], ['text'], ['mar', 'gin'], ['kern', 'ing'], ['jus', 'ti', 'fied']], 14, 1], ['line interna-', 'tional', 'paragraph in-', 'ternational', 'composition', 'margin to set-', 'ting text', 'margin kerning', 'justified'])], [('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('regression: final word protection', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['break', 'ing'], ['to'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn']], 9, 3], ['justified', 'breaking', 'to hy-', 'phenation', 'column']), ('regression: final word protection', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['text'], ['set', 'ting'], ['lead', 'ing']], 11, 3], ['breaking', 'composition', 'interna-', 'tional', 'breaking', 'text set-', 'ting', 'leading']), ('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'], ['text'], ['lead', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['to'], ['jus', 'ti', 'fied'], ['lead', 'ing']], 13, 1], ['margin text', 'leading col-', 'umn', 'hyphenation', 'margin inter-', 'national', 'margin set-', 'ting to', 'justified', 'leading']), ('control layout', [[['to'], ['set', 'ting'], ['of'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing']], 12, 2], ['to setting', 'of leading', 'leading of', 'composition', 'setting', 'leading'])], [('regression: final word protection', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['break', 'ing'], ['of'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['hyphena-', 'tion hy-', 'phenation', 'leading', 'breaking', 'of text a', 'justified', 'justified', 'to', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['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']), ('partial-repair probe', [[['to'], ['hy', 'phen', 'a', 'tion'], ['line'], ['com', 'po', 'si', 'tion'], ['of']], 6, 3], ['to hy-', 'phena-', 'tion', 'line', 'compo-', 'sition', 'of']), ('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', [[['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['type'], ['to'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['type'], ['a']], 13, 3], ['of composi-', 'tion interna-', 'tional kern-', 'ing type to', 'justified to', 'kerning type', 'a']), ('control layout', [[['of'], ['break', 'ing'], ['type'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['break', 'ing']], 12, 3], ['of breaking', 'type compo-', 'sition in-', 'ternational', 'hyphenation', 'breaking'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
last word never hyphenated['a compo-', 'sition']['a', 'composition']Failed
regression: final word protection['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'break-', 'ing']['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']Failed
partial-repair probe['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']Passed
regression: final word protection['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kern-', 'ing']['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']Failed
ladder of three hyphenated lines['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']Passed
control layout['kerning', 'line type', 'justified', 'setting']['kerning', 'line type', 'justified', 'setting']Passed
control layout['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']Passed
control layout['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']Passed

SHA-256 / b59d6784e3cacf7ce7cd3c5a8a31f59e4f1e7c68258b88c6e820d5942991e2b8

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) - 2:
            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 = [[('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['text'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['line'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion']], 11, 1], ['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']), ('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('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', [[['kern', 'ing'], ['line'], ['type'], ['jus', 'ti', 'fied'], ['set', 'ting']], 11, 2], ['kerning', 'line type', 'justified', 'setting']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['set', 'ting'], ['a']], 10, 2], ['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']), ('control layout', [[['col', 'umn'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['type'], ['of'], ['of'], ['line'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['line']], 7, 3], ['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line'])], [('regression: final word protection', [[['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['breaking', 'margin hy-', 'phenation', 'justified', 'a hyphena-', 'tion com-', 'position', 'hyphenation']), ('regression: final word protection', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion']], 12, 1], ['paragraph', 'breaking', 'margin hy-', 'phenation', 'kerning jus-', 'tified to', 'kerning', 'hyphenation']), ('partial-repair probe', [[['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['of'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting']], 9, 3], ['breaking', 'interna-', 'tional', 'text of', 'setting', 'interna-', 'tional', 'line a', 'interna-', 'tional', 'setting']), ('regression: final word protection', [[['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['break', 'ing'], ['mar', 'gin'], ['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al']], 6, 1], ['compo-', 'sition', 'inter-', 'national', 'margin', 'break-', 'ing', 'margin', 'line', 'set-', 'ting', 'international']), ('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', [[['set', 'ting'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['type'], ['type'], ['text'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['a'], ['set', 'ting']], 11, 2], ['setting', 'justified', 'breaking', 'type type', 'text break-', 'ing hyphen-', 'ation a', 'setting']), ('control layout', [[['a'], ['line'], ['lead', 'ing'], ['break', 'ing'], ['text'], ['of'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['to'], ['type']], 6, 2], ['a line', 'lead-', 'ing', 'break-', 'ing', 'text', 'of', 'compo-', 'sition', 'to hy-', 'phena-', 'tion', 'to', 'type'])], [('regression: final word protection', [[['set', 'ting'], ['of'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['line'], ['set', 'ting'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin']], 11, 2], ['setting of', 'margin', 'kerning', 'setting', 'column line', 'setting a', 'interna-', 'tional', 'margin']), ('regression: final word protection', [[['a'], ['type'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['to'], ['to'], ['break', 'ing'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['type'], ['text'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['a type in-', 'ternation-', 'al leading', 'to to', 'breaking', 'composi-', 'tion hy-', 'phenation', 'type text', 'hyphenation']), ('regression: final word protection', [[['text'], ['line'], ['to'], ['text'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['of'], ['break', 'ing'], ['com', 'po', 'si', 'tion']], 10, 3], ['text line', 'to text', 'leading', 'justified', 'setting', 'justified', 'of break-', 'ing', 'composition']), ('regression: final word protection', [[['break', 'ing'], ['of'], ['set', 'ting'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 9, 3], ['breaking', 'of set-', 'ting mar-', 'gin', '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', [[['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['of'], ['text']], 7, 3], ['kerning', 'setting', 'column', 'of text']), ('control layout', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['to'], ['set', 'ting'], ['text'], ['mar', 'gin'], ['kern', 'ing'], ['jus', 'ti', 'fied']], 14, 1], ['line interna-', 'tional', 'paragraph in-', 'ternational', 'composition', 'margin to set-', 'ting text', 'margin kerning', 'justified'])], [('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('regression: final word protection', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['break', 'ing'], ['to'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn']], 9, 3], ['justified', 'breaking', 'to hy-', 'phenation', 'column']), ('regression: final word protection', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['text'], ['set', 'ting'], ['lead', 'ing']], 11, 3], ['breaking', 'composition', 'interna-', 'tional', 'breaking', 'text set-', 'ting', 'leading']), ('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'], ['text'], ['lead', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['to'], ['jus', 'ti', 'fied'], ['lead', 'ing']], 13, 1], ['margin text', 'leading col-', 'umn', 'hyphenation', 'margin inter-', 'national', 'margin set-', 'ting to', 'justified', 'leading']), ('control layout', [[['to'], ['set', 'ting'], ['of'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing']], 12, 2], ['to setting', 'of leading', 'leading of', 'composition', 'setting', 'leading'])], [('regression: final word protection', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['break', 'ing'], ['of'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['hyphena-', 'tion hy-', 'phenation', 'leading', 'breaking', 'of text a', 'justified', 'justified', 'to', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['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']), ('partial-repair probe', [[['to'], ['hy', 'phen', 'a', 'tion'], ['line'], ['com', 'po', 'si', 'tion'], ['of']], 6, 3], ['to hy-', 'phena-', 'tion', 'line', 'compo-', 'sition', 'of']), ('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', [[['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['type'], ['to'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['type'], ['a']], 13, 3], ['of composi-', 'tion interna-', 'tional kern-', 'ing type to', 'justified to', 'kerning type', 'a']), ('control layout', [[['of'], ['break', 'ing'], ['type'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['break', 'ing']], 12, 3], ['of breaking', 'type compo-', 'sition in-', 'ternational', 'hyphenation', 'breaking'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
last word never hyphenated['a', 'composition']['a', 'composition']Passed
regression: final word protection['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']Passed
partial-repair probe['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column', 'justified', 'composition']['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']Failed
regression: final word protection['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'international', 'kerning']['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']Failed
ladder of three hyphenated lines['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphenation', 'text']['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']Failed
control layout['kerning', 'line type', 'justified', 'setting']['kerning', 'line type', 'justified', 'setting']Passed
control layout['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']Passed
control layout['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']Passed

SHA-256 / 5e4f84323e933ceeac7ef8e682cbe803166c09c9dec46a63f0ff72ac99908f67

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 = [[('last word never hyphenated', [[['a'], ['com', 'po', 'si', 'tion']], 8, 2], ['a', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['text'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['set', 'ting'], ['line'], ['line'], ['jus', 'ti', 'fied'], ['col', 'umn'], ['jus', 'ti', 'fied'], ['com', 'po', 'si', 'tion']], 11, 1], ['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']), ('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('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', [[['kern', 'ing'], ['line'], ['type'], ['jus', 'ti', 'fied'], ['set', 'ting']], 11, 2], ['kerning', 'line type', 'justified', 'setting']), ('control layout', [[['hy', 'phen', 'a', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting'], ['set', 'ting'], ['a']], 10, 2], ['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']), ('control layout', [[['col', 'umn'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['type'], ['of'], ['of'], ['line'], ['set', 'ting'], ['pa', 'ra', 'graph'], ['kern', 'ing'], ['line']], 7, 3], ['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line'])], [('regression: final word protection', [[['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['jus', 'ti', 'fied'], ['a'], ['hy', 'phen', 'a', 'tion'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['breaking', 'margin hy-', 'phenation', 'justified', 'a hyphena-', 'tion com-', 'position', 'hyphenation']), ('regression: final word protection', [[['pa', 'ra', 'graph'], ['break', 'ing'], ['mar', 'gin'], ['hy', 'phen', 'a', 'tion'], ['kern', 'ing'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['hy', 'phen', 'a', 'tion']], 12, 1], ['paragraph', 'breaking', 'margin hy-', 'phenation', 'kerning jus-', 'tified to', 'kerning', 'hyphenation']), ('partial-repair probe', [[['break', 'ing'], ['in', 'ter', 'na', 'tion', 'al'], ['text'], ['of'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['line'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['set', 'ting']], 9, 3], ['breaking', 'interna-', 'tional', 'text of', 'setting', 'interna-', 'tional', 'line a', 'interna-', 'tional', 'setting']), ('regression: final word protection', [[['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['break', 'ing'], ['mar', 'gin'], ['line'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al']], 6, 1], ['compo-', 'sition', 'inter-', 'national', 'margin', 'break-', 'ing', 'margin', 'line', 'set-', 'ting', 'international']), ('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', [[['set', 'ting'], ['jus', 'ti', 'fied'], ['break', 'ing'], ['type'], ['type'], ['text'], ['break', 'ing'], ['hy', 'phen', 'a', 'tion'], ['a'], ['set', 'ting']], 11, 2], ['setting', 'justified', 'breaking', 'type type', 'text break-', 'ing hyphen-', 'ation a', 'setting']), ('control layout', [[['a'], ['line'], ['lead', 'ing'], ['break', 'ing'], ['text'], ['of'], ['com', 'po', 'si', 'tion'], ['to'], ['hy', 'phen', 'a', 'tion'], ['to'], ['type']], 6, 2], ['a line', 'lead-', 'ing', 'break-', 'ing', 'text', 'of', 'compo-', 'sition', 'to hy-', 'phena-', 'tion', 'to', 'type'])], [('regression: final word protection', [[['set', 'ting'], ['of'], ['mar', 'gin'], ['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['line'], ['set', 'ting'], ['a'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin']], 11, 2], ['setting of', 'margin', 'kerning', 'setting', 'column line', 'setting a', 'interna-', 'tional', 'margin']), ('regression: final word protection', [[['a'], ['type'], ['in', 'ter', 'na', 'tion', 'al'], ['lead', 'ing'], ['to'], ['to'], ['break', 'ing'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['type'], ['text'], ['hy', 'phen', 'a', 'tion']], 10, 3], ['a type in-', 'ternation-', 'al leading', 'to to', 'breaking', 'composi-', 'tion hy-', 'phenation', 'type text', 'hyphenation']), ('regression: final word protection', [[['text'], ['line'], ['to'], ['text'], ['lead', 'ing'], ['jus', 'ti', 'fied'], ['set', 'ting'], ['jus', 'ti', 'fied'], ['of'], ['break', 'ing'], ['com', 'po', 'si', 'tion']], 10, 3], ['text line', 'to text', 'leading', 'justified', 'setting', 'justified', 'of break-', 'ing', 'composition']), ('regression: final word protection', [[['break', 'ing'], ['of'], ['set', 'ting'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al']], 9, 3], ['breaking', 'of set-', 'ting mar-', 'gin', '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', [[['kern', 'ing'], ['set', 'ting'], ['col', 'umn'], ['of'], ['text']], 7, 3], ['kerning', 'setting', 'column', 'of text']), ('control layout', [[['line'], ['in', 'ter', 'na', 'tion', 'al'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['com', 'po', 'si', 'tion'], ['mar', 'gin'], ['to'], ['set', 'ting'], ['text'], ['mar', 'gin'], ['kern', 'ing'], ['jus', 'ti', 'fied']], 14, 1], ['line interna-', 'tional', 'paragraph in-', 'ternational', 'composition', 'margin to set-', 'ting text', 'margin kerning', 'justified'])], [('regression: final word protection', [[['line'], ['pa', 'ra', 'graph'], ['com', 'po', 'si', 'tion'], ['hy', 'phen', 'a', 'tion'], ['pa', 'ra', 'graph'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing']], 6, 1], ['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']), ('regression: final word protection', [[['a'], ['break', 'ing'], ['text'], ['to'], ['mar', 'gin'], ['set', 'ting'], ['in', 'ter', 'na', 'tion', 'al'], ['in', 'ter', 'na', 'tion', 'al']], 6, 3], ['a', 'break-', 'ing', 'text', 'to', 'margin', 'set-', 'ting', 'inter-', 'na-', 'tional', 'international']), ('partial-repair probe', [[['jus', 'ti', 'fied'], ['break', 'ing'], ['to'], ['hy', 'phen', 'a', 'tion'], ['col', 'umn']], 9, 3], ['justified', 'breaking', 'to hy-', 'phenation', 'column']), ('regression: final word protection', [[['break', 'ing'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['break', 'ing'], ['text'], ['set', 'ting'], ['lead', 'ing']], 11, 3], ['breaking', 'composition', 'interna-', 'tional', 'breaking', 'text set-', 'ting', 'leading']), ('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'], ['text'], ['lead', 'ing'], ['col', 'umn'], ['hy', 'phen', 'a', 'tion'], ['mar', 'gin'], ['in', 'ter', 'na', 'tion', 'al'], ['mar', 'gin'], ['set', 'ting'], ['to'], ['jus', 'ti', 'fied'], ['lead', 'ing']], 13, 1], ['margin text', 'leading col-', 'umn', 'hyphenation', 'margin inter-', 'national', 'margin set-', 'ting to', 'justified', 'leading']), ('control layout', [[['to'], ['set', 'ting'], ['of'], ['lead', 'ing'], ['lead', 'ing'], ['of'], ['com', 'po', 'si', 'tion'], ['set', 'ting'], ['lead', 'ing']], 12, 2], ['to setting', 'of leading', 'leading of', 'composition', 'setting', 'leading'])], [('regression: final word protection', [[['hy', 'phen', 'a', 'tion'], ['hy', 'phen', 'a', 'tion'], ['lead', 'ing'], ['break', 'ing'], ['of'], ['text'], ['a'], ['jus', 'ti', 'fied'], ['jus', 'ti', 'fied'], ['to'], ['com', 'po', 'si', 'tion']], 10, 3], ['hyphena-', 'tion hy-', 'phenation', 'leading', 'breaking', 'of text a', 'justified', 'justified', 'to', 'composition']), ('regression: final word protection', [[['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']), ('partial-repair probe', [[['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']), ('partial-repair probe', [[['to'], ['hy', 'phen', 'a', 'tion'], ['line'], ['com', 'po', 'si', 'tion'], ['of']], 6, 3], ['to hy-', 'phena-', 'tion', 'line', 'compo-', 'sition', 'of']), ('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', [[['of'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['kern', 'ing'], ['type'], ['to'], ['jus', 'ti', 'fied'], ['to'], ['kern', 'ing'], ['type'], ['a']], 13, 3], ['of composi-', 'tion interna-', 'tional kern-', 'ing type to', 'justified to', 'kerning type', 'a']), ('control layout', [[['of'], ['break', 'ing'], ['type'], ['com', 'po', 'si', 'tion'], ['in', 'ter', 'na', 'tion', 'al'], ['hy', 'phen', 'a', 'tion'], ['break', 'ing']], 12, 3], ['of breaking', 'type compo-', 'sition in-', 'ternational', 'hyphenation', 'breaking'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
last word never hyphenated['a', 'composition']['a', 'composition']Passed
regression: final word protection['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']['to in-', 'terna-', 'tional', 'a mar-', 'gin a', 'text a', 'breaking']Passed
partial-repair probe['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']['text justi-', 'fied a', 'hyphenation', 'setting', 'line line', 'justified', 'column jus-', 'tified', 'composition']Passed
regression: final word protection['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']['line', 'para-', 'graph', 'compo-', 'sition', 'hy-', 'phenation', 'para-', 'graph', 'inter-', 'national', 'kerning']Passed
ladder of three hyphenated lines['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']['inter-', 'nation-', 'al', 'compo-', 'sition', 'hyphen-', 'ation', 'text']Passed
control layout['kerning', 'line type', 'justified', 'setting']['kerning', 'line type', 'justified', 'setting']Passed
control layout['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']['hyphena-', 'tion in-', 'ternational', 'setting', 'setting a']Passed
control layout['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']['column', 'compo-', 'sition', 'hyphen-', 'ation', 'leading', 'type of', 'of line', 'setting', 'para-', 'graph', 'kerning', 'line']Passed

SHA-256 / 137a6d22c1db92597d76e8ea1880f4f2d841ced63f18de2c11883688f14d8587

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

Case digest / 07f47d0131745ca24907b9f6b02e7387550400115a3e7832821beabd8a23213c