FAILURE MAP
← Case archive

FA-80231 / Typography line breaking / Open access

Ragged-right hyphenation zone: before/after minimums · case 01

Hyphens leave too-short heads or tails.

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

ROOT CAUSE

The head is checked against the after minimum and the tail against the before minimum.

VERIFIED REPAIR

Check the head against min before and the tail against min after.

Unsuccessful approach: Making the head check strict rejects legal heads.

Case contract

Input [words as syllables, width, zone, min word length, min chars before, min chars after, hyphenate capitals]. Greedy fill. A word that does not fit may be hyphenated only if the slack left on the line (width minus current text minus the separating space) is at least the zone, the word has at least min-word characters, and (capitals allowed or its first letter is not uppercase). Pick the latest syllable boundary with head >= min before and tail >= min after chars whose head plus "-" fits. Return 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, zone, min_word, min_before, min_after, caps = x
    lines = []
    cur = ''
    k = 0
    queue = [list(w) for w in words]
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        cand = token if not cur else cur + ' ' + token
        if len(cand) <= width:
            cur = cand
            k += 1
            continue
        slack = width - len(cur) - (1 if cur else 0)
        eligible = slack >= zone and len(token) >= min_word and (caps or not token[0].isupper())
        cut = None
        if eligible:
            for c in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:c])
                tail = ''.join(syl[c:])
                if len(head) < min_after or len(tail) < min_before:
                    continue
                fit = len(head) + 1 if not cur else len(cur) + len(head) + 2
                if fit <= width:
                    cut = c
                    break
        if cut is not None:
            head = ''.join(syl[:cut]) + '-'
            lines.append(head if not cur else cur + ' ' + head)
            queue[k] = syl[cut:]
            cur = ''
        elif cur:
            lines.append(cur)
            cur = ''
        else:
            cur = token
            k += 1
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['rag', 'ged'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['ty', 'po', 'gra', 'phy'], ['a'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 11, 3, 6, 1, 2, False], ['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']), ('regression: before/after minimums', [[['of'], ['im', 'por', 'tant'], ['of'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['the'], ['hy', 'phen', 'at', 'ed'], ['a']], 12, 4, 7, 3, 2, True], ['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['a'], ['e', 'Book', 'ing'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald']], 13, 2, 5, 1, 3, True], ['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['a'], ['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['the'], ['set']], 15, 5, 5, 2, 3, True], ['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']), ('control layout', [[['Mc', 'Don', 'ald'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['Ber', 'lin'], ['Ber', 'lin'], ['e', 'Book', 'ing']], 14, 2, 4, 2, 2, False], ['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking'])], [('regression: before/after minimums', [[['im', 'por', 'tant'], ['im', 'por', 'tant'], ['a'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy'], ['of'], ['rag', 'ged']], 13, 1, 4, 2, 3, False], ['important im-', 'portant a ty-', 'pography ty-', 'pography set', 'ragged typo-', 'graphy of', 'ragged']), ('regression: before/after minimums', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['hy', 'phen', 'at', 'ed'], ['the'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant']], 9, 1, 4, 1, 3, True], ['eBooking', 'McDonald', 'Berlin', 'hyphen-', 'ated the', 'typogra-', 'phy im-', 'portant']), ('partial-repair probe', [[['a'], ['Ber', 'lin'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['e', 'Book', 'ing'], ['Ber', 'lin'], ['a'], ['im', 'por', 'tant']], 14, 5, 7, 2, 2, False], ['a Berlin im-', 'portant typo-', 'graphy eBook-', 'ing Berlin a', 'important']), ('partial-repair probe', [[['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['set'], ['the']], 9, 4, 4, 3, 2, False], ['important', 'only rag-', 'ged set', 'the']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['a'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['set']], 14, 3, 4, 3, 2, True], ['a only typo-', 'graphy set']), ('control layout', [[['a'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['set'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['a']], 14, 2, 5, 2, 2, True], ['a McDonald', 'eBooking set', 'typography', 'ragged a'])], [('regression: before/after minimums', [[['rag', 'ged'], ['the'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['e', 'Book', 'ing'], ['set'], ['of'], ['the'], ['im', 'por', 'tant']], 12, 5, 7, 2, 3, True], ['ragged the', 'hyphenated', 'Berlin', 'eBooking set', 'of the im-', 'portant']), ('regression: before/after minimums', [[['a'], ['of'], ['ty', 'po', 'gra', 'phy'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['ty', 'po', 'gra', 'phy']], 13, 3, 4, 3, 2, False], ['a of typogra-', 'phy only', 'hyphenated', 'typography']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['the'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['set'], ['Mc', 'Don', 'ald'], ['rag', 'ged']], 8, 5, 4, 1, 2, True], ['the', 'typogra-', 'phy', 'typogra-', 'phy set', 'ragged', 'set', 'McDonald', 'ragged']), ('control layout', [[['set'], ['the'], ['the'], ['set'], ['e', 'Book', 'ing'], ['on', 'ly'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1, 5, 3, 3, True], ['set the the', 'set eBooking', 'only interna-', 'tional'])], [('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['set'], ['Mc', 'Don', 'ald'], ['the'], ['hy', 'phen', 'at', 'ed'], ['e', 'Book', 'ing'], ['im', 'por', 'tant']], 11, 2, 5, 2, 3, True], ['McDonald', 'important', 'McDonald', 'set McDon-', 'ald the hy-', 'phenated', 'eBooking', 'important']), ('regression: before/after minimums', [[['rag', 'ged'], ['e', 'Book', 'ing'], ['of'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant'], ['of'], ['e', 'Book', 'ing'], ['rag', 'ged'], ['Ber', 'lin'], ['Mc', 'Don', 'ald']], 13, 5, 6, 1, 2, True], ['ragged eBook-', 'ing of typo-', 'graphy impor-', 'tant of e-', 'Booking rag-', 'ged Berlin', 'McDonald']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['rag', 'ged'], ['rag', 'ged'], ['set'], ['im', 'por', 'tant'], ['set'], ['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['hy', 'phen', 'at', 'ed']], 16, 4, 5, 3, 3, True], ['ragged ragged', 'set important', 'set eBooking', 'McDonald hyphen-', 'ated']), ('control layout', [[['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald'], ['of'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 12, 4, 6, 2, 2, False], ['hyphenated', 'McDonald of', 'set interna-', 'tional'])], [('regression: before/after minimums', [[['Ber', 'lin'], ['the'], ['hy', 'phen', 'at', 'ed'], ['the'], ['Mc', 'Don', 'ald'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 8, 1, 7, 2, 3, False], ['Berlin', 'the hy-', 'phenated', 'the', 'McDonald', 'set in-', 'terna-', 'tional']), ('regression: before/after minimums', [[['the'], ['hy', 'phen', 'at', 'ed'], ['rag', 'ged'], ['the'], ['the'], ['set']], 8, 3, 5, 3, 2, False], ['the', 'hyphen-', 'ated', 'ragged', 'the the', 'set']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('regression: before/after minimums', [[['im', 'por', 'tant'], ['e', 'Book', 'ing'], ['e', 'Book', 'ing'], ['rag', 'ged']], 15, 1, 4, 1, 2, True], ['important e-', 'Booking eBook-', 'ing ragged']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['rag', 'ged'], ['Mc', 'Don', 'ald'], ['Mc', 'Don', 'ald']], 10, 5, 6, 3, 3, True], ['McDonald', 'important', 'Berlin', 'McDonald', 'ragged', 'McDonald', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['the'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy']], 11, 3, 4, 2, 3, True], ['eBooking', 'McDonald', 'eBooking', 'the only', 'typography'])]]
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
regression: before/after minimums['McDonald', 'ragged', 'eBooking', 'typography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']Failed
regression: before/after minimums['of important', 'of only hy-', 'phenated the', 'hyphenated a']['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']Failed
partial-repair probe['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']Passed
regression: before/after minimums['McDonald', 'important', 'typography a', 'eBooking', 'important', 'McDonald', 'international', 'McDonald']['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']Failed
zone exactly met['the typo-', 'graphy']['the typo-', 'graphy']Passed
capitalised word protected['the', 'McDonald']['the', 'McDonald']Passed
control layout['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']Passed
control layout['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']Passed

SHA-256 / f167648459d603cb4710412c8b9258099305e1d9a5b181894a7f40d5dbc9fd62

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width, zone, min_word, min_before, min_after, caps = x
    lines = []
    cur = ''
    k = 0
    queue = [list(w) for w in words]
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        cand = token if not cur else cur + ' ' + token
        if len(cand) <= width:
            cur = cand
            k += 1
            continue
        slack = width - len(cur) - (1 if cur else 0)
        eligible = slack >= zone and len(token) >= min_word and (caps or not token[0].isupper())
        cut = None
        if eligible:
            for c in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:c])
                tail = ''.join(syl[c:])
                if len(head) <= min_before or len(tail) < min_after:
                    continue
                fit = len(head) + 1 if not cur else len(cur) + len(head) + 2
                if fit <= width:
                    cut = c
                    break
        if cut is not None:
            head = ''.join(syl[:cut]) + '-'
            lines.append(head if not cur else cur + ' ' + head)
            queue[k] = syl[cut:]
            cur = ''
        elif cur:
            lines.append(cur)
            cur = ''
        else:
            cur = token
            k += 1
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['rag', 'ged'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['ty', 'po', 'gra', 'phy'], ['a'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 11, 3, 6, 1, 2, False], ['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']), ('regression: before/after minimums', [[['of'], ['im', 'por', 'tant'], ['of'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['the'], ['hy', 'phen', 'at', 'ed'], ['a']], 12, 4, 7, 3, 2, True], ['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['a'], ['e', 'Book', 'ing'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald']], 13, 2, 5, 1, 3, True], ['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['a'], ['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['the'], ['set']], 15, 5, 5, 2, 3, True], ['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']), ('control layout', [[['Mc', 'Don', 'ald'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['Ber', 'lin'], ['Ber', 'lin'], ['e', 'Book', 'ing']], 14, 2, 4, 2, 2, False], ['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking'])], [('regression: before/after minimums', [[['im', 'por', 'tant'], ['im', 'por', 'tant'], ['a'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy'], ['of'], ['rag', 'ged']], 13, 1, 4, 2, 3, False], ['important im-', 'portant a ty-', 'pography ty-', 'pography set', 'ragged typo-', 'graphy of', 'ragged']), ('regression: before/after minimums', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['hy', 'phen', 'at', 'ed'], ['the'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant']], 9, 1, 4, 1, 3, True], ['eBooking', 'McDonald', 'Berlin', 'hyphen-', 'ated the', 'typogra-', 'phy im-', 'portant']), ('partial-repair probe', [[['a'], ['Ber', 'lin'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['e', 'Book', 'ing'], ['Ber', 'lin'], ['a'], ['im', 'por', 'tant']], 14, 5, 7, 2, 2, False], ['a Berlin im-', 'portant typo-', 'graphy eBook-', 'ing Berlin a', 'important']), ('partial-repair probe', [[['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['set'], ['the']], 9, 4, 4, 3, 2, False], ['important', 'only rag-', 'ged set', 'the']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['a'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['set']], 14, 3, 4, 3, 2, True], ['a only typo-', 'graphy set']), ('control layout', [[['a'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['set'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['a']], 14, 2, 5, 2, 2, True], ['a McDonald', 'eBooking set', 'typography', 'ragged a'])], [('regression: before/after minimums', [[['rag', 'ged'], ['the'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['e', 'Book', 'ing'], ['set'], ['of'], ['the'], ['im', 'por', 'tant']], 12, 5, 7, 2, 3, True], ['ragged the', 'hyphenated', 'Berlin', 'eBooking set', 'of the im-', 'portant']), ('regression: before/after minimums', [[['a'], ['of'], ['ty', 'po', 'gra', 'phy'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['ty', 'po', 'gra', 'phy']], 13, 3, 4, 3, 2, False], ['a of typogra-', 'phy only', 'hyphenated', 'typography']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['the'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['set'], ['Mc', 'Don', 'ald'], ['rag', 'ged']], 8, 5, 4, 1, 2, True], ['the', 'typogra-', 'phy', 'typogra-', 'phy set', 'ragged', 'set', 'McDonald', 'ragged']), ('control layout', [[['set'], ['the'], ['the'], ['set'], ['e', 'Book', 'ing'], ['on', 'ly'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1, 5, 3, 3, True], ['set the the', 'set eBooking', 'only interna-', 'tional'])], [('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['set'], ['Mc', 'Don', 'ald'], ['the'], ['hy', 'phen', 'at', 'ed'], ['e', 'Book', 'ing'], ['im', 'por', 'tant']], 11, 2, 5, 2, 3, True], ['McDonald', 'important', 'McDonald', 'set McDon-', 'ald the hy-', 'phenated', 'eBooking', 'important']), ('regression: before/after minimums', [[['rag', 'ged'], ['e', 'Book', 'ing'], ['of'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant'], ['of'], ['e', 'Book', 'ing'], ['rag', 'ged'], ['Ber', 'lin'], ['Mc', 'Don', 'ald']], 13, 5, 6, 1, 2, True], ['ragged eBook-', 'ing of typo-', 'graphy impor-', 'tant of e-', 'Booking rag-', 'ged Berlin', 'McDonald']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['rag', 'ged'], ['rag', 'ged'], ['set'], ['im', 'por', 'tant'], ['set'], ['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['hy', 'phen', 'at', 'ed']], 16, 4, 5, 3, 3, True], ['ragged ragged', 'set important', 'set eBooking', 'McDonald hyphen-', 'ated']), ('control layout', [[['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald'], ['of'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 12, 4, 6, 2, 2, False], ['hyphenated', 'McDonald of', 'set interna-', 'tional'])], [('regression: before/after minimums', [[['Ber', 'lin'], ['the'], ['hy', 'phen', 'at', 'ed'], ['the'], ['Mc', 'Don', 'ald'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 8, 1, 7, 2, 3, False], ['Berlin', 'the hy-', 'phenated', 'the', 'McDonald', 'set in-', 'terna-', 'tional']), ('regression: before/after minimums', [[['the'], ['hy', 'phen', 'at', 'ed'], ['rag', 'ged'], ['the'], ['the'], ['set']], 8, 3, 5, 3, 2, False], ['the', 'hyphen-', 'ated', 'ragged', 'the the', 'set']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('regression: before/after minimums', [[['im', 'por', 'tant'], ['e', 'Book', 'ing'], ['e', 'Book', 'ing'], ['rag', 'ged']], 15, 1, 4, 1, 2, True], ['important e-', 'Booking eBook-', 'ing ragged']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['rag', 'ged'], ['Mc', 'Don', 'ald'], ['Mc', 'Don', 'ald']], 10, 5, 6, 3, 3, True], ['McDonald', 'important', 'Berlin', 'McDonald', 'ragged', 'McDonald', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['the'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy']], 11, 3, 4, 2, 3, True], ['eBooking', 'McDonald', 'eBooking', 'the only', 'typography'])]]
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
regression: before/after minimums['McDonald', 'ragged', 'eBooking', 'typography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']Failed
regression: before/after minimums['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']Passed
partial-repair probe['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged', 'ragged only', 'hyphenated']['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']Failed
regression: before/after minimums['McDonald im-', 'portant typo-', 'graphy a', 'eBooking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']Failed
zone exactly met['the typo-', 'graphy']['the typo-', 'graphy']Passed
capitalised word protected['the', 'McDonald']['the', 'McDonald']Passed
control layout['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']Passed
control layout['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']Passed

SHA-256 / 326a9064f3913c589224c514a39ab0c4e2c73382685548920993160d20cdcd70

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width, zone, min_word, min_before, min_after, caps = x
    lines = []
    cur = ''
    k = 0
    queue = [list(w) for w in words]
    while k < len(queue):
        syl = queue[k]
        token = ''.join(syl)
        cand = token if not cur else cur + ' ' + token
        if len(cand) <= width:
            cur = cand
            k += 1
            continue
        slack = width - len(cur) - (1 if cur else 0)
        eligible = slack >= zone and len(token) >= min_word and (caps or not token[0].isupper())
        cut = None
        if eligible:
            for c in range(len(syl) - 1, 0, -1):
                head = ''.join(syl[:c])
                tail = ''.join(syl[c:])
                if len(head) < min_before or len(tail) < min_after:
                    continue
                fit = len(head) + 1 if not cur else len(cur) + len(head) + 2
                if fit <= width:
                    cut = c
                    break
        if cut is not None:
            head = ''.join(syl[:cut]) + '-'
            lines.append(head if not cur else cur + ' ' + head)
            queue[k] = syl[cut:]
            cur = ''
        elif cur:
            lines.append(cur)
            cur = ''
        else:
            cur = token
            k += 1
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['rag', 'ged'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['ty', 'po', 'gra', 'phy'], ['a'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 11, 3, 6, 1, 2, False], ['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']), ('regression: before/after minimums', [[['of'], ['im', 'por', 'tant'], ['of'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['the'], ['hy', 'phen', 'at', 'ed'], ['a']], 12, 4, 7, 3, 2, True], ['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['a'], ['e', 'Book', 'ing'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald']], 13, 2, 5, 1, 3, True], ['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['a'], ['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['the'], ['set']], 15, 5, 5, 2, 3, True], ['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']), ('control layout', [[['Mc', 'Don', 'ald'], ['ty', 'po', 'gra', 'phy'], ['Ber', 'lin'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['Ber', 'lin'], ['Ber', 'lin'], ['e', 'Book', 'ing']], 14, 2, 4, 2, 2, False], ['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking'])], [('regression: before/after minimums', [[['im', 'por', 'tant'], ['im', 'por', 'tant'], ['a'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy'], ['of'], ['rag', 'ged']], 13, 1, 4, 2, 3, False], ['important im-', 'portant a ty-', 'pography ty-', 'pography set', 'ragged typo-', 'graphy of', 'ragged']), ('regression: before/after minimums', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['hy', 'phen', 'at', 'ed'], ['the'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant']], 9, 1, 4, 1, 3, True], ['eBooking', 'McDonald', 'Berlin', 'hyphen-', 'ated the', 'typogra-', 'phy im-', 'portant']), ('partial-repair probe', [[['a'], ['Ber', 'lin'], ['im', 'por', 'tant'], ['ty', 'po', 'gra', 'phy'], ['e', 'Book', 'ing'], ['Ber', 'lin'], ['a'], ['im', 'por', 'tant']], 14, 5, 7, 2, 2, False], ['a Berlin im-', 'portant typo-', 'graphy eBook-', 'ing Berlin a', 'important']), ('partial-repair probe', [[['im', 'por', 'tant'], ['on', 'ly'], ['rag', 'ged'], ['set'], ['the']], 9, 4, 4, 3, 2, False], ['important', 'only rag-', 'ged set', 'the']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['a'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['set']], 14, 3, 4, 3, 2, True], ['a only typo-', 'graphy set']), ('control layout', [[['a'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['set'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['a']], 14, 2, 5, 2, 2, True], ['a McDonald', 'eBooking set', 'typography', 'ragged a'])], [('regression: before/after minimums', [[['rag', 'ged'], ['the'], ['hy', 'phen', 'at', 'ed'], ['Ber', 'lin'], ['e', 'Book', 'ing'], ['set'], ['of'], ['the'], ['im', 'por', 'tant']], 12, 5, 7, 2, 3, True], ['ragged the', 'hyphenated', 'Berlin', 'eBooking set', 'of the im-', 'portant']), ('regression: before/after minimums', [[['a'], ['of'], ['ty', 'po', 'gra', 'phy'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed'], ['ty', 'po', 'gra', 'phy']], 13, 3, 4, 3, 2, False], ['a of typogra-', 'phy only', 'hyphenated', 'typography']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['the'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['set'], ['rag', 'ged'], ['set'], ['Mc', 'Don', 'ald'], ['rag', 'ged']], 8, 5, 4, 1, 2, True], ['the', 'typogra-', 'phy', 'typogra-', 'phy set', 'ragged', 'set', 'McDonald', 'ragged']), ('control layout', [[['set'], ['the'], ['the'], ['set'], ['e', 'Book', 'ing'], ['on', 'ly'], ['in', 'ter', 'na', 'tion', 'al']], 13, 1, 5, 3, 3, True], ['set the the', 'set eBooking', 'only interna-', 'tional'])], [('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Mc', 'Don', 'ald'], ['set'], ['Mc', 'Don', 'ald'], ['the'], ['hy', 'phen', 'at', 'ed'], ['e', 'Book', 'ing'], ['im', 'por', 'tant']], 11, 2, 5, 2, 3, True], ['McDonald', 'important', 'McDonald', 'set McDon-', 'ald the hy-', 'phenated', 'eBooking', 'important']), ('regression: before/after minimums', [[['rag', 'ged'], ['e', 'Book', 'ing'], ['of'], ['ty', 'po', 'gra', 'phy'], ['im', 'por', 'tant'], ['of'], ['e', 'Book', 'ing'], ['rag', 'ged'], ['Ber', 'lin'], ['Mc', 'Don', 'ald']], 13, 5, 6, 1, 2, True], ['ragged eBook-', 'ing of typo-', 'graphy impor-', 'tant of e-', 'Booking rag-', 'ged Berlin', 'McDonald']), ('regression: before/after minimums', [[['the'], ['set'], ['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald']], 12, 4, 7, 2, 3, False], ['the set hy-', 'phenated', 'McDonald']), ('partial-repair probe', [[['in', 'ter', 'na', 'tion', 'al'], ['Mc', 'Don', 'ald'], ['a'], ['e', 'Book', 'ing'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['rag', 'ged'], ['on', 'ly'], ['hy', 'phen', 'at', 'ed']], 12, 5, 4, 3, 3, False], ['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('control layout', [[['rag', 'ged'], ['rag', 'ged'], ['set'], ['im', 'por', 'tant'], ['set'], ['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['hy', 'phen', 'at', 'ed']], 16, 4, 5, 3, 3, True], ['ragged ragged', 'set important', 'set eBooking', 'McDonald hyphen-', 'ated']), ('control layout', [[['hy', 'phen', 'at', 'ed'], ['Mc', 'Don', 'ald'], ['of'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 12, 4, 6, 2, 2, False], ['hyphenated', 'McDonald of', 'set interna-', 'tional'])], [('regression: before/after minimums', [[['Ber', 'lin'], ['the'], ['hy', 'phen', 'at', 'ed'], ['the'], ['Mc', 'Don', 'ald'], ['set'], ['in', 'ter', 'na', 'tion', 'al']], 8, 1, 7, 2, 3, False], ['Berlin', 'the hy-', 'phenated', 'the', 'McDonald', 'set in-', 'terna-', 'tional']), ('regression: before/after minimums', [[['the'], ['hy', 'phen', 'at', 'ed'], ['rag', 'ged'], ['the'], ['the'], ['set']], 8, 3, 5, 3, 2, False], ['the', 'hyphen-', 'ated', 'ragged', 'the the', 'set']), ('regression: before/after minimums', [[['Mc', 'Don', 'ald'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy'], ['ty', 'po', 'gra', 'phy'], ['rag', 'ged'], ['ty', 'po', 'gra', 'phy']], 9, 4, 6, 2, 3, False], ['McDonald', 'Berlin', 'McDonald', 'eBooking', 'only ty-', 'pography', 'typogra-', 'phy rag-', 'ged typo-', 'graphy']), ('regression: before/after minimums', [[['im', 'por', 'tant'], ['e', 'Book', 'ing'], ['e', 'Book', 'ing'], ['rag', 'ged']], 15, 1, 4, 1, 2, True], ['important e-', 'Booking eBook-', 'ing ragged']), ('zone exactly met', [[['the'], ['ty', 'po', 'gra', 'phy']], 10, 6, 4, 2, 2, False], ['the typo-', 'graphy']), ('capitalised word protected', [[['the'], ['Mc', 'Don', 'ald']], 10, 2, 4, 2, 2, False], ['the', 'McDonald']), ('control layout', [[['Mc', 'Don', 'ald'], ['im', 'por', 'tant'], ['Ber', 'lin'], ['Mc', 'Don', 'ald'], ['rag', 'ged'], ['Mc', 'Don', 'ald'], ['Mc', 'Don', 'ald']], 10, 5, 6, 3, 3, True], ['McDonald', 'important', 'Berlin', 'McDonald', 'ragged', 'McDonald', 'McDonald']), ('control layout', [[['e', 'Book', 'ing'], ['Mc', 'Don', 'ald'], ['e', 'Book', 'ing'], ['the'], ['on', 'ly'], ['ty', 'po', 'gra', 'phy']], 11, 3, 4, 2, 3, True], ['eBooking', 'McDonald', 'eBooking', 'the only', 'typography'])]]
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
regression: before/after minimums['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']['McDonald', 'ragged e-', 'Booking ty-', 'pography', 'Berlin ty-', 'pography a', 'ragged ty-', 'pography']Passed
regression: before/after minimums['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']['of important', 'of only', 'hyphenated', 'the hyphen-', 'ated a']Passed
partial-repair probe['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']['interna-', 'tional', 'McDonald a', 'eBooking', 'typography', 'ragged rag-', 'ged only', 'hyphenated']Passed
regression: before/after minimums['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']['McDonald im-', 'portant typo-', 'graphy a e-', 'Booking im-', 'portant Mc-', 'Donald inter-', 'national Mc-', 'Donald']Passed
zone exactly met['the typo-', 'graphy']['the typo-', 'graphy']Passed
capitalised word protected['the', 'McDonald']['the', 'McDonald']Passed
control layout['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']['eBooking typo-', 'graphy a impor-', 'tant only rag-', 'ged the set']Passed
control layout['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']['McDonald typo-', 'graphy Berlin', 'only hyphenat-', 'ed Berlin', 'Berlin Berlin', 'eBooking']Passed

SHA-256 / bb8a943e616fc9ad269282c03a4d41fac9d64d508c3804e2a6b7cb6c76025316

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

Case digest / 051f3b1e9a598db432e0eb82757cc02accd2a518b3b379b77b0cbb9a06f958fe