broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: label clearance', ['Note:', ['type', 'x'], 12, 5], ['Note: type x']), ('regression: label clearance', ['A.1.2', ['x', 'a', 'grid', 'baseline', 'a', 'on', 'x'], 12, 5], ['A.1.2 x a', '     grid', '     baseline', '     a on x']), ('regression: label clearance', ['(a)', ['type', 'is', 'at', 'on'], 20, 3], ['(a) type is at on']), ('regression: label clearance', ['1.', ['type', 'serif', 'a', 'the', 'at', 'kerning', 'at'], 17, 2], ['1. type serif a', '  the at kerning', '  at']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['ink', 'baseline', 'serif', 'on'], 16, 4], ['(a) ink baseline', '    serif on']), ('control layout', ['(a)', ['x', 'x', 'type'], 14, 5], ['(a)  x x type'])], [('regression: label clearance', ['Note:', ['baseline', 'baseline', 'at', 'grid', 'ink', 'type'], 21, 5], ['Note: baseline', '     baseline at grid', '     ink type']), ('regression: label clearance', ['1.', ['measure', 'grid', 'kerning'], 13, 2], ['1. measure', '  grid', '  kerning']), ('regression: label clearance', ['1.', ['x', 'the', 'kerning', 'x', 'baseline', 'grid'], 20, 2], ['1. x the kerning x', '  baseline grid']), ('regression: label clearance', ['Note:', ['baseline', 'serif', 'x', 'grid', 'serif', 'x', 'type'], 18, 5], ['Note: baseline', '     serif x grid', '     serif x type']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['ink', 'kerning'], 22, 5], ['1.   ink kerning']), ('control layout', ['A.1.2', ['x', 'ink', 'on'], 15, 3], ['A.1.2 x ink on'])], [('regression: label clearance', ['A.1.2', ['kerning', 'x', 'the', 'measure', 'ink', 'measure'], 13, 5], ['A.1.2 kerning', '     x the', '     measure', '     ink', '     measure']), ('regression: label clearance', ['10.', ['grid', 'is', 'type', 'of', 'of', 'of', 'a', 'on', 'ink'], 19, 3], ['10. grid is type of', '   of of a on ink']), ('regression: label clearance', ['iv.', ['x', 'x'], 13, 3], ['iv. x x']), ('regression: label clearance', ['(a)', ['of', 'of', 'grid', 'grid'], 15, 3], ['(a) of of grid', '   grid']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['A.1.2', ['ink', 'ink', 'on', 'serif', 'is', 'baseline', 'a', 'on', 'serif'], 16, 2], ['A.1.2 ink ink on', '  serif is', '  baseline a on', '  serif']), ('control layout', ['•', ['baseline', 'is', 'at'], 15, 2], ['• baseline is', '  at'])], [('regression: label clearance', ['(a)', ['at', 'on', 'of', 'grid', 'at', 'a', 'type', 'measure', 'grid'], 18, 3], ['(a) at on of grid', '   at a type', '   measure grid']), ('regression: label clearance', ['A.1.2', ['of', 'serif', 'at', 'serif', 'of', 'is'], 19, 5], ['A.1.2 of serif at', '     serif of is']), ('regression: label clearance', ['(a)', ['serif', 'x'], 19, 3], ['(a) serif x']), ('partial-repair probe', ['Note:', ['grid', 'on', 'at'], 22, 4], ['Note: grid on at']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['of', 'is'], 17, 4], ['iv. of is']), ('control layout', ['10.', ['measure', 'of', 'x', 'of', 'kerning', 'a', 'serif', 'baseline'], 20, 4], ['10. measure of x of', '    kerning a serif', '    baseline'])], [('regression: label clearance', ['A.1.2', ['at', 'of', 'ink', 'x', 'is', 'type', 'grid'], 18, 5], ['A.1.2 at of ink x', '     is type grid']), ('regression: label clearance', ['(a)', ['serif', 'x'], 19, 3], ['(a) serif x']), ('regression: label clearance', ['1.', ['x', 'type', 'baseline'], 22, 2], ['1. x type baseline']), ('regression: label clearance', ['(a)', ['at', 'on', 'of', 'grid', 'at', 'a', 'type', 'measure', 'grid'], 18, 3], ['(a) at on of grid', '   at a type', '   measure grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['type', 'on', 'the', 'measure'], 16, 5], ['(a)  type on the', '     measure']), ('control layout', ['Note:', ['at', 'of'], 16, 2], ['Note: at of'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) <= hang + 1 else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: label clearance', ['Note:', ['type', 'x'], 12, 5], ['Note: type x']), ('regression: label clearance', ['A.1.2', ['x', 'a', 'grid', 'baseline', 'a', 'on', 'x'], 12, 5], ['A.1.2 x a', '     grid', '     baseline', '     a on x']), ('regression: label clearance', ['(a)', ['type', 'is', 'at', 'on'], 20, 3], ['(a) type is at on']), ('regression: label clearance', ['1.', ['type', 'serif', 'a', 'the', 'at', 'kerning', 'at'], 17, 2], ['1. type serif a', '  the at kerning', '  at']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['ink', 'baseline', 'serif', 'on'], 16, 4], ['(a) ink baseline', '    serif on']), ('control layout', ['(a)', ['x', 'x', 'type'], 14, 5], ['(a)  x x type'])], [('regression: label clearance', ['Note:', ['baseline', 'baseline', 'at', 'grid', 'ink', 'type'], 21, 5], ['Note: baseline', '     baseline at grid', '     ink type']), ('regression: label clearance', ['1.', ['measure', 'grid', 'kerning'], 13, 2], ['1. measure', '  grid', '  kerning']), ('regression: label clearance', ['1.', ['x', 'the', 'kerning', 'x', 'baseline', 'grid'], 20, 2], ['1. x the kerning x', '  baseline grid']), ('regression: label clearance', ['Note:', ['baseline', 'serif', 'x', 'grid', 'serif', 'x', 'type'], 18, 5], ['Note: baseline', '     serif x grid', '     serif x type']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['ink', 'kerning'], 22, 5], ['1.   ink kerning']), ('control layout', ['A.1.2', ['x', 'ink', 'on'], 15, 3], ['A.1.2 x ink on'])], [('regression: label clearance', ['A.1.2', ['kerning', 'x', 'the', 'measure', 'ink', 'measure'], 13, 5], ['A.1.2 kerning', '     x the', '     measure', '     ink', '     measure']), ('regression: label clearance', ['10.', ['grid', 'is', 'type', 'of', 'of', 'of', 'a', 'on', 'ink'], 19, 3], ['10. grid is type of', '   of of a on ink']), ('regression: label clearance', ['iv.', ['x', 'x'], 13, 3], ['iv. x x']), ('regression: label clearance', ['(a)', ['of', 'of', 'grid', 'grid'], 15, 3], ['(a) of of grid', '   grid']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['A.1.2', ['ink', 'ink', 'on', 'serif', 'is', 'baseline', 'a', 'on', 'serif'], 16, 2], ['A.1.2 ink ink on', '  serif is', '  baseline a on', '  serif']), ('control layout', ['•', ['baseline', 'is', 'at'], 15, 2], ['• baseline is', '  at'])], [('regression: label clearance', ['(a)', ['at', 'on', 'of', 'grid', 'at', 'a', 'type', 'measure', 'grid'], 18, 3], ['(a) at on of grid', '   at a type', '   measure grid']), ('regression: label clearance', ['A.1.2', ['of', 'serif', 'at', 'serif', 'of', 'is'], 19, 5], ['A.1.2 of serif at', '     serif of is']), ('regression: label clearance', ['(a)', ['serif', 'x'], 19, 3], ['(a) serif x']), ('partial-repair probe', ['Note:', ['grid', 'on', 'at'], 22, 4], ['Note: grid on at']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['of', 'is'], 17, 4], ['iv. of is']), ('control layout', ['10.', ['measure', 'of', 'x', 'of', 'kerning', 'a', 'serif', 'baseline'], 20, 4], ['10. measure of x of', '    kerning a serif', '    baseline'])], [('regression: label clearance', ['A.1.2', ['at', 'of', 'ink', 'x', 'is', 'type', 'grid'], 18, 5], ['A.1.2 at of ink x', '     is type grid']), ('regression: label clearance', ['(a)', ['serif', 'x'], 19, 3], ['(a) serif x']), ('regression: label clearance', ['1.', ['x', 'type', 'baseline'], 22, 2], ['1. x type baseline']), ('regression: label clearance', ['(a)', ['at', 'on', 'of', 'grid', 'at', 'a', 'type', 'measure', 'grid'], 18, 3], ['(a) at on of grid', '   at a type', '   measure grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['type', 'on', 'the', 'measure'], 16, 5], ['(a)  type on the', '     measure']), ('control layout', ['Note:', ['at', 'of'], 16, 2], ['Note: at of'])]]
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)

prompt:
Labels exactly as wide as the hang touch the text.

Input [label, words, width, hang]. The label starts at column 0; first-line text starts at column hang when label+1 space fits, else right after label plus one space. Continuation lines are indented by hang. Greedy fill with unit spaces measuring absolute columns. Return padded lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else hang
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: overflowing label start', ['(a)', ['grid', 'measure', 'is', 'the', 'at', 'on', 'a'], 21, 3], ['(a) grid measure is', '   the at on a']), ('regression: overflowing label start', ['Note:', ['on', 'measure', 'type', 'is', 'serif', 'a'], 14, 5], ['Note: on', '     measure', '     type is', '     serif a']), ('regression: overflowing label start', ['Note:', ['measure', 'serif', 'kerning', 'is', 'baseline', 'type', 'at', 'of'], 16, 4], ['Note: measure', '    serif', '    kerning is', '    baseline', '    type at of']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['is', 'baseline', 'of', 'baseline', 'is', 'measure'], 22, 3], ['1. is baseline of', '   baseline is measure']), ('control layout', ['iv.', ['of', 'ink', 'a', 'type', 'is', 'baseline', 'is', 'kerning'], 12, 4], ['iv. of ink a', '    type is', '    baseline', '    is', '    kerning']), ('control layout', ['(a)', ['baseline', 'grid', 'serif', 'x', 'kerning'], 16, 4], ['(a) baseline', '    grid serif x', '    kerning'])], [('regression: overflowing label start', ['iv.', ['at', 'a', 'measure'], 21, 2], ['iv. at a measure']), ('regression: overflowing label start', ['Note:', ['on', 'grid', 'x', 'a', 'the'], 20, 4], ['Note: on grid x a', '    the']), ('regression: overflowing label start', ['(a)', ['a', 'grid', 'type'], 20, 2], ['(a) a grid type']), ('regression: overflowing label start', ['10.', ['on', 'the'], 18, 2], ['10. on the']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['type', 'kerning', 'kerning', 'type', 'of', 'measure'], 14, 5], ['•    type', '     kerning', '     kerning', '     type of', '     measure']), ('control layout', ['iv.', ['is', 'of', 'of', 'kerning', 'is', 'of', 'type'], 20, 4], ['iv. is of of kerning', '    is of type'])], [('regression: overflowing label start', ['Note:', ['type', 'of'], 12, 2], ['Note: type', '  of']), ('regression: overflowing label start', ['(a)', ['kerning', 'kerning', 'baseline'], 22, 2], ['(a) kerning kerning', '  baseline']), ('regression: overflowing label start', ['(a)', ['type', 'is', 'at', 'the', 'measure'], 16, 2], ['(a) type is at', '  the measure']), ('regression: overflowing label start', ['Note:', ['measure', 'baseline', 'is', 'baseline', 'ink', 'the', 'baseline'], 19, 5], ['Note: measure', '     baseline is', '     baseline ink', '     the baseline']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['(a)', ['on', 'measure', 'at', 'the', 'measure'], 12, 4], ['(a) on', '    measure', '    at the', '    measure']), ('control layout', ['(a)', ['baseline', 'type', 'is'], 22, 5], ['(a)  baseline type is'])], [('regression: overflowing label start', ['Note:', ['measure', 'serif', 'kerning', 'is', 'baseline', 'type', 'at', 'of'], 16, 4], ['Note: measure', '    serif', '    kerning is', '    baseline', '    type at of']), ('regression: overflowing label start', ['iv.', ['serif', 'a', 'ink'], 17, 3], ['iv. serif a ink']), ('regression: overflowing label start', ['Note:', ['a', 'a', 'type', 'kerning', 'measure'], 15, 2], ['Note: a a type', '  kerning', '  measure']), ('regression: overflowing label start', ['iv.', ['serif', 'is', 'at', 'measure', 'baseline', 'a', 'type'], 12, 2], ['iv. serif is', '  at measure', '  baseline a', '  type']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['1.', ['at', 'type', 'at', 'measure', 'is', 'is', 'is', 'is', 'on'], 12, 3], ['1. at type', '   at', '   measure', '   is is is', '   is on']), ('control layout', ['(a)', ['kerning', 'ink', 'of', 'is', 'kerning'], 15, 5], ['(a)  kerning', '     ink of is', '     kerning'])], [('regression: overflowing label start', ['10.', ['kerning', 'grid', 'on', 'at', 'ink', 'on', 'at', 'baseline', 'is'], 14, 2], ['10. kerning', '  grid on at', '  ink on at', '  baseline is']), ('regression: overflowing label start', ['A.1.2', ['x', 'a', 'grid', 'baseline', 'a', 'on', 'x'], 12, 5], ['A.1.2 x a', '     grid', '     baseline', '     a on x']), ('regression: overflowing label start', ['(a)', ['ink', 'kerning', 'kerning', 'grid'], 16, 2], ['(a) ink kerning', '  kerning grid']), ('regression: overflowing label start', ['Note:', ['type', 'type', 'of', 'on', 'on', 'kerning'], 20, 5], ['Note: type type of', '     on on kerning']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['is', 'of', 'of', 'kerning', 'is', 'of', 'type'], 20, 4], ['iv. is of of kerning', '    is of type']), ('control layout', ['•', ['baseline', 'serif', 'x', 'type'], 17, 4], ['•   baseline', '    serif x type'])]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label)
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: overflowing label start', ['(a)', ['grid', 'measure', 'is', 'the', 'at', 'on', 'a'], 21, 3], ['(a) grid measure is', '   the at on a']), ('regression: overflowing label start', ['Note:', ['on', 'measure', 'type', 'is', 'serif', 'a'], 14, 5], ['Note: on', '     measure', '     type is', '     serif a']), ('regression: overflowing label start', ['Note:', ['measure', 'serif', 'kerning', 'is', 'baseline', 'type', 'at', 'of'], 16, 4], ['Note: measure', '    serif', '    kerning is', '    baseline', '    type at of']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['is', 'baseline', 'of', 'baseline', 'is', 'measure'], 22, 3], ['1. is baseline of', '   baseline is measure']), ('control layout', ['iv.', ['of', 'ink', 'a', 'type', 'is', 'baseline', 'is', 'kerning'], 12, 4], ['iv. of ink a', '    type is', '    baseline', '    is', '    kerning']), ('control layout', ['(a)', ['baseline', 'grid', 'serif', 'x', 'kerning'], 16, 4], ['(a) baseline', '    grid serif x', '    kerning'])], [('regression: overflowing label start', ['iv.', ['at', 'a', 'measure'], 21, 2], ['iv. at a measure']), ('regression: overflowing label start', ['Note:', ['on', 'grid', 'x', 'a', 'the'], 20, 4], ['Note: on grid x a', '    the']), ('regression: overflowing label start', ['(a)', ['a', 'grid', 'type'], 20, 2], ['(a) a grid type']), ('regression: overflowing label start', ['10.', ['on', 'the'], 18, 2], ['10. on the']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['type', 'kerning', 'kerning', 'type', 'of', 'measure'], 14, 5], ['•    type', '     kerning', '     kerning', '     type of', '     measure']), ('control layout', ['iv.', ['is', 'of', 'of', 'kerning', 'is', 'of', 'type'], 20, 4], ['iv. is of of kerning', '    is of type'])], [('regression: overflowing label start', ['Note:', ['type', 'of'], 12, 2], ['Note: type', '  of']), ('regression: overflowing label start', ['(a)', ['kerning', 'kerning', 'baseline'], 22, 2], ['(a) kerning kerning', '  baseline']), ('regression: overflowing label start', ['(a)', ['type', 'is', 'at', 'the', 'measure'], 16, 2], ['(a) type is at', '  the measure']), ('regression: overflowing label start', ['Note:', ['measure', 'baseline', 'is', 'baseline', 'ink', 'the', 'baseline'], 19, 5], ['Note: measure', '     baseline is', '     baseline ink', '     the baseline']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['(a)', ['on', 'measure', 'at', 'the', 'measure'], 12, 4], ['(a) on', '    measure', '    at the', '    measure']), ('control layout', ['(a)', ['baseline', 'type', 'is'], 22, 5], ['(a)  baseline type is'])], [('regression: overflowing label start', ['Note:', ['measure', 'serif', 'kerning', 'is', 'baseline', 'type', 'at', 'of'], 16, 4], ['Note: measure', '    serif', '    kerning is', '    baseline', '    type at of']), ('regression: overflowing label start', ['iv.', ['serif', 'a', 'ink'], 17, 3], ['iv. serif a ink']), ('regression: overflowing label start', ['Note:', ['a', 'a', 'type', 'kerning', 'measure'], 15, 2], ['Note: a a type', '  kerning', '  measure']), ('regression: overflowing label start', ['iv.', ['serif', 'is', 'at', 'measure', 'baseline', 'a', 'type'], 12, 2], ['iv. serif is', '  at measure', '  baseline a', '  type']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['1.', ['at', 'type', 'at', 'measure', 'is', 'is', 'is', 'is', 'on'], 12, 3], ['1. at type', '   at', '   measure', '   is is is', '   is on']), ('control layout', ['(a)', ['kerning', 'ink', 'of', 'is', 'kerning'], 15, 5], ['(a)  kerning', '     ink of is', '     kerning'])], [('regression: overflowing label start', ['10.', ['kerning', 'grid', 'on', 'at', 'ink', 'on', 'at', 'baseline', 'is'], 14, 2], ['10. kerning', '  grid on at', '  ink on at', '  baseline is']), ('regression: overflowing label start', ['A.1.2', ['x', 'a', 'grid', 'baseline', 'a', 'on', 'x'], 12, 5], ['A.1.2 x a', '     grid', '     baseline', '     a on x']), ('regression: overflowing label start', ['(a)', ['ink', 'kerning', 'kerning', 'grid'], 16, 2], ['(a) ink kerning', '  kerning grid']), ('regression: overflowing label start', ['Note:', ['type', 'type', 'of', 'on', 'on', 'kerning'], 20, 5], ['Note: type type of', '     on on kerning']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['is', 'of', 'of', 'kerning', 'is', 'of', 'type'], 20, 4], ['iv. is of of kerning', '    is of type']), ('control layout', ['•', ['baseline', 'serif', 'x', 'type'], 17, 4], ['•   baseline', '    serif x type'])]]
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)

prompt:
Text overprints or abuts long labels.

Input [label, words, width, hang]. The label starts at column 0; first-line text starts at column hang when label+1 space fits, else right after label plus one space. Continuation lines are indented by hang. Greedy fill with unit spaces measuring absolute columns. Return padded lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('regression: continuation column', ['(a)', ['kerning', 'serif', 'the', 'of', 'kerning', 'the'], 14, 4], ['(a) kerning', '    serif the', '    of kerning', '    the']), ('partial-repair probe', ['iv.', ['measure', 'type', 'on', 'at', 'x'], 15, 2], ['iv. measure', '  type on at x']), ('partial-repair probe', ['A.1.2', ['at', 'serif', 'of', 'type', 'ink', 'measure'], 19, 3], ['A.1.2 at serif of', '   type ink measure']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['Note:', ['a', 'serif', 'at', 'ink', 'on', 'of'], 21, 5], ['Note: a serif at ink', '     on of']), ('control layout', ['A.1.2', ['grid', 'baseline', 'measure', 'measure', 'baseline'], 14, 2], ['A.1.2 grid', '  baseline', '  measure', '  measure', '  baseline']), ('control layout', ['•', ['the', 'x', 'a'], 17, 2], ['• the x a'])], [('regression: continuation column', ['•', ['ink', 'kerning', 'serif', 'grid', 'baseline', 'is', 'type', 'ink'], 21, 2], ['• ink kerning serif', '  grid baseline is', '  type ink']), ('regression: continuation column', ['iv.', ['ink', 'measure', 'kerning', 'on', 'of', 'serif', 'is', 'baseline'], 20, 4], ['iv. ink measure', '    kerning on of', '    serif is', '    baseline']), ('regression: continuation column', ['A.1.2', ['of', 'measure', 'kerning', 'kerning', 'baseline', 'serif', 'at'], 19, 4], ['A.1.2 of measure', '    kerning kerning', '    baseline serif', '    at']), ('partial-repair probe', ['A.1.2', ['grid', 'on', 'a', 'at', 'grid', 'grid'], 17, 2], ['A.1.2 grid on a', '  at grid grid']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['ink', 'type', 'at', 'kerning', 'x'], 16, 2], ['• ink type at', '  kerning x']), ('control layout', ['Note:', ['type', 'the', 'is', 'baseline', 'is'], 20, 5], ['Note: type the is', '     baseline is'])], [('regression: continuation column', ['(a)', ['at', 'is', 'kerning', 'x', 'at', 'of', 'on', 'on', 'ink'], 18, 5], ['(a)  at is kerning', '     x at of on on', '     ink']), ('regression: continuation column', ['•', ['baseline', 'serif', 'of', 'the', 'x', 'is', 'on'], 13, 4], ['•   baseline', '    serif of', '    the x is', '    on']), ('partial-repair probe', ['iv.', ['kerning', 'of', 'kerning', 'is', 'of', 'ink'], 16, 3], ['iv. kerning of', '   kerning is of', '   ink']), ('partial-repair probe', ['Note:', ['kerning', 'serif', 'type', 'is', 'at', 'the'], 15, 2], ['Note: kerning', '  serif type is', '  at the']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['the', 'is', 'serif'], 14, 2], ['(a) the is', '  serif']), ('control layout', ['(a)', ['at', 'of', 'on', 'of', 'kerning', 'of'], 19, 3], ['(a) at of on of', '   kerning of'])], [('regression: continuation column', ['iv.', ['ink', 'type', 'serif', 'kerning', 'the', 'a'], 14, 2], ['iv. ink type', '  serif', '  kerning the', '  a']), ('regression: continuation column', ['1.', ['serif', 'baseline', 'of', 'a', 'at', 'is', 'measure'], 13, 3], ['1. serif', '   baseline', '   of a at is', '   measure']), ('partial-repair probe', ['Note:', ['kerning', 'serif', 'type', 'is', 'at', 'the'], 15, 2], ['Note: kerning', '  serif type is', '  at the']), ('regression: continuation column', ['(a)', ['of', 'ink', 'baseline', 'ink', 'on', 'type', 'measure', 'baseline', 'grid'], 14, 2], ['(a) of ink', '  baseline ink', '  on type', '  measure', '  baseline', '  grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['on', 'measure', 'ink', 'ink'], 22, 4], ['•   on measure ink ink']), ('control layout', ['10.', ['at', 'type', 'on', 'kerning', 'on'], 22, 4], ['10. at type on kerning', '    on'])], [('regression: continuation column', ['(a)', ['kerning', 'baseline', 'baseline', 'x', 'the', 'x'], 16, 5], ['(a)  kerning', '     baseline', '     baseline x', '     the x']), ('regression: continuation column', ['iv.', ['of', 'at', 'ink', 'x', 'is', 'measure', 'on'], 16, 4], ['iv. of at ink x', '    is measure', '    on']), ('regression: continuation column', ['A.1.2', ['of', 'measure', 'kerning', 'kerning', 'baseline', 'serif', 'at'], 19, 4], ['A.1.2 of measure', '    kerning kerning', '    baseline serif', '    at']), ('regression: continuation column', ['A.1.2', ['on', 'at', 'of', 'kerning', 'type', 'of', 'measure', 'baseline', 'grid'], 18, 5], ['A.1.2 on at of', '     kerning type', '     of measure', '     baseline grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['ink', 'the', 'baseline', 'type'], 17, 3], ['iv. ink the', '   baseline type']), ('control layout', ['iv.', ['on', 'serif', 'baseline', 'x'], 14, 2], ['iv. on serif', '  baseline x'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = start + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('regression: continuation column', ['(a)', ['kerning', 'serif', 'the', 'of', 'kerning', 'the'], 14, 4], ['(a) kerning', '    serif the', '    of kerning', '    the']), ('partial-repair probe', ['iv.', ['measure', 'type', 'on', 'at', 'x'], 15, 2], ['iv. measure', '  type on at x']), ('partial-repair probe', ['A.1.2', ['at', 'serif', 'of', 'type', 'ink', 'measure'], 19, 3], ['A.1.2 at serif of', '   type ink measure']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['Note:', ['a', 'serif', 'at', 'ink', 'on', 'of'], 21, 5], ['Note: a serif at ink', '     on of']), ('control layout', ['A.1.2', ['grid', 'baseline', 'measure', 'measure', 'baseline'], 14, 2], ['A.1.2 grid', '  baseline', '  measure', '  measure', '  baseline']), ('control layout', ['•', ['the', 'x', 'a'], 17, 2], ['• the x a'])], [('regression: continuation column', ['•', ['ink', 'kerning', 'serif', 'grid', 'baseline', 'is', 'type', 'ink'], 21, 2], ['• ink kerning serif', '  grid baseline is', '  type ink']), ('regression: continuation column', ['iv.', ['ink', 'measure', 'kerning', 'on', 'of', 'serif', 'is', 'baseline'], 20, 4], ['iv. ink measure', '    kerning on of', '    serif is', '    baseline']), ('regression: continuation column', ['A.1.2', ['of', 'measure', 'kerning', 'kerning', 'baseline', 'serif', 'at'], 19, 4], ['A.1.2 of measure', '    kerning kerning', '    baseline serif', '    at']), ('partial-repair probe', ['A.1.2', ['grid', 'on', 'a', 'at', 'grid', 'grid'], 17, 2], ['A.1.2 grid on a', '  at grid grid']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['ink', 'type', 'at', 'kerning', 'x'], 16, 2], ['• ink type at', '  kerning x']), ('control layout', ['Note:', ['type', 'the', 'is', 'baseline', 'is'], 20, 5], ['Note: type the is', '     baseline is'])], [('regression: continuation column', ['(a)', ['at', 'is', 'kerning', 'x', 'at', 'of', 'on', 'on', 'ink'], 18, 5], ['(a)  at is kerning', '     x at of on on', '     ink']), ('regression: continuation column', ['•', ['baseline', 'serif', 'of', 'the', 'x', 'is', 'on'], 13, 4], ['•   baseline', '    serif of', '    the x is', '    on']), ('partial-repair probe', ['iv.', ['kerning', 'of', 'kerning', 'is', 'of', 'ink'], 16, 3], ['iv. kerning of', '   kerning is of', '   ink']), ('partial-repair probe', ['Note:', ['kerning', 'serif', 'type', 'is', 'at', 'the'], 15, 2], ['Note: kerning', '  serif type is', '  at the']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['(a)', ['the', 'is', 'serif'], 14, 2], ['(a) the is', '  serif']), ('control layout', ['(a)', ['at', 'of', 'on', 'of', 'kerning', 'of'], 19, 3], ['(a) at of on of', '   kerning of'])], [('regression: continuation column', ['iv.', ['ink', 'type', 'serif', 'kerning', 'the', 'a'], 14, 2], ['iv. ink type', '  serif', '  kerning the', '  a']), ('regression: continuation column', ['1.', ['serif', 'baseline', 'of', 'a', 'at', 'is', 'measure'], 13, 3], ['1. serif', '   baseline', '   of a at is', '   measure']), ('partial-repair probe', ['Note:', ['kerning', 'serif', 'type', 'is', 'at', 'the'], 15, 2], ['Note: kerning', '  serif type is', '  at the']), ('regression: continuation column', ['(a)', ['of', 'ink', 'baseline', 'ink', 'on', 'type', 'measure', 'baseline', 'grid'], 14, 2], ['(a) of ink', '  baseline ink', '  on type', '  measure', '  baseline', '  grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['on', 'measure', 'ink', 'ink'], 22, 4], ['•   on measure ink ink']), ('control layout', ['10.', ['at', 'type', 'on', 'kerning', 'on'], 22, 4], ['10. at type on kerning', '    on'])], [('regression: continuation column', ['(a)', ['kerning', 'baseline', 'baseline', 'x', 'the', 'x'], 16, 5], ['(a)  kerning', '     baseline', '     baseline x', '     the x']), ('regression: continuation column', ['iv.', ['of', 'at', 'ink', 'x', 'is', 'measure', 'on'], 16, 4], ['iv. of at ink x', '    is measure', '    on']), ('regression: continuation column', ['A.1.2', ['of', 'measure', 'kerning', 'kerning', 'baseline', 'serif', 'at'], 19, 4], ['A.1.2 of measure', '    kerning kerning', '    baseline serif', '    at']), ('regression: continuation column', ['A.1.2', ['on', 'at', 'of', 'kerning', 'type', 'of', 'measure', 'baseline', 'grid'], 18, 5], ['A.1.2 on at of', '     kerning type', '     of measure', '     baseline grid']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['iv.', ['ink', 'the', 'baseline', 'type'], 17, 3], ['iv. ink the', '   baseline type']), ('control layout', ['iv.', ['on', 'serif', 'baseline', 'x'], 14, 2], ['iv. on serif', '  baseline x'])]]
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)

prompt:
Continuation lines are filled as if they started at column 0.

Input [label, words, width, hang]. The label starts at column 0; first-line text starts at column hang when label+1 space fits, else right after label plus one space. Continuation lines are indented by hang. Greedy fill with unit spaces measuring absolute columns. Return padded lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need >= width:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: column fit boundary', ['1.', ['is', 'type', 'kerning', 'kerning', 'kerning', 'ink', 'measure', 'a', 'ink'], 18, 3], ['1. is type kerning', '   kerning kerning', '   ink measure a', '   ink']), ('partial-repair probe', ['Note:', ['type', 'type', 'of', 'on', 'on', 'kerning'], 20, 5], ['Note: type type of', '     on on kerning']), ('partial-repair probe', ['iv.', ['x', 'a', 'ink', 'at', 'serif', 'of', 'is', 'x', 'kerning'], 14, 5], ['iv.  x a ink', '     at serif', '     of is x', '     kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['on', 'of', 'the'], 16, 4], ['A.1.2 on of the']), ('control layout', ['Note:', ['is', 'serif'], 22, 4], ['Note: is serif']), ('control layout', ['•', ['a', 'is', 'measure', 'baseline', 'ink'], 21, 5], ['•    a is measure', '     baseline ink'])], [('regression: column fit boundary', ['•', ['the', 'ink', 'of', 'of', 'is'], 18, 5], ['•    the ink of of', '     is']), ('regression: column fit boundary', ['1.', ['kerning', 'baseline', 'measure', 'a', 'serif', 'x'], 18, 2], ['1. kerning', '  baseline measure', '  a serif x']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('partial-repair probe', ['1.', ['a', 'of', 'serif', 'type', 'the', 'ink', 'is', 'at', 'kerning'], 14, 3], ['1. a of serif', '   type the', '   ink is at', '   kerning']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['of', 'x', 'is'], 18, 4], ['•   of x is']), ('control layout', ['1.', ['serif', 'at'], 14, 3], ['1. serif at']), ('control layout', ['iv.', ['of', 'is'], 17, 2], ['iv. of is'])], [('regression: column fit boundary', ['iv.', ['type', 'a', 'of', 'of', 'is', 'is', 'baseline', 'kerning'], 13, 4], ['iv. type a of', '    of is is', '    baseline', '    kerning']), ('regression: column fit boundary', ['Note:', ['on', 'at', 'a', 'x', 'baseline', 'x', 'grid'], 18, 3], ['Note: on at a x', '   baseline x grid']), ('regression: column fit boundary', ['A.1.2', ['measure', 'is', 'grid', 'type', 'type', 'of', 'serif', 'at', 'ink'], 20, 3], ['A.1.2 measure is', '   grid type type of', '   serif at ink']), ('partial-repair probe', ['A.1.2', ['ink', 'grid', 'ink', 'serif', 'is', 'baseline'], 13, 2], ['A.1.2 ink', '  grid ink', '  serif is', '  baseline']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['a', 'kerning', 'measure', 'the', 'the', 'kerning', 'is'], 15, 3], ['•  a kerning', '   measure the', '   the kerning', '   is']), ('control layout', ['1.', ['is', 'x'], 18, 3], ['1. is x'])], [('regression: column fit boundary', ['•', ['is', 'x', 'at', 'type', 'kerning', 'the'], 14, 3], ['•  is x at', '   type', '   kerning the']), ('regression: column fit boundary', ['A.1.2', ['a', 'kerning', 'measure', 'a', 'at', 'measure'], 22, 2], ['A.1.2 a kerning', '  measure a at measure']), ('regression: column fit boundary', ['Note:', ['is', 'measure', 'a', 'x', 'type', 'on', 'measure', 'of'], 18, 2], ['Note: is measure a', '  x type on', '  measure of']), ('partial-repair probe', ['(a)', ['type', 'ink'], 12, 5], ['(a)  type', '     ink']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['baseline', 'grid', 'on', 'is', 'kerning'], 13, 2], ['A.1.2 baseline', '  grid on is', '  kerning']), ('control layout', ['Note:', ['ink', 'baseline', 'measure', 'type', 'type', 'ink', 'kerning', 'at', 'kerning'], 19, 5], ['Note: ink baseline', '     measure type', '     type ink', '     kerning at', '     kerning'])], [('regression: column fit boundary', ['•', ['measure', 'kerning', 'grid', 'of'], 20, 5], ['•    measure kerning', '     grid of']), ('regression: column fit boundary', ['10.', ['grid', 'is', 'type', 'of', 'of', 'of', 'a', 'on', 'ink'], 19, 3], ['10. grid is type of', '   of of a on ink']), ('regression: column fit boundary', ['(a)', ['of', 'ink', 'baseline', 'ink', 'on', 'type', 'measure', 'baseline', 'grid'], 14, 2], ['(a) of ink', '  baseline ink', '  on type', '  measure', '  baseline', '  grid']), ('partial-repair probe', ['1.', ['of', 'type', 'kerning', 'the', 'on', 'kerning', 'type', 'x', 'kerning'], 22, 4], ['1.  of type kerning', '    the on kerning', '    type x kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['of', 'of'], 20, 4], ['•   of of']), ('control layout', ['1.', ['ink', 'kerning'], 22, 5], ['1.   ink kerning'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width + 1:
            prefix = label.ljust(start) if first else ' ' * hang
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * hang
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: column fit boundary', ['1.', ['is', 'type', 'kerning', 'kerning', 'kerning', 'ink', 'measure', 'a', 'ink'], 18, 3], ['1. is type kerning', '   kerning kerning', '   ink measure a', '   ink']), ('partial-repair probe', ['Note:', ['type', 'type', 'of', 'on', 'on', 'kerning'], 20, 5], ['Note: type type of', '     on on kerning']), ('partial-repair probe', ['iv.', ['x', 'a', 'ink', 'at', 'serif', 'of', 'is', 'x', 'kerning'], 14, 5], ['iv.  x a ink', '     at serif', '     of is x', '     kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['on', 'of', 'the'], 16, 4], ['A.1.2 on of the']), ('control layout', ['Note:', ['is', 'serif'], 22, 4], ['Note: is serif']), ('control layout', ['•', ['a', 'is', 'measure', 'baseline', 'ink'], 21, 5], ['•    a is measure', '     baseline ink'])], [('regression: column fit boundary', ['•', ['the', 'ink', 'of', 'of', 'is'], 18, 5], ['•    the ink of of', '     is']), ('regression: column fit boundary', ['1.', ['kerning', 'baseline', 'measure', 'a', 'serif', 'x'], 18, 2], ['1. kerning', '  baseline measure', '  a serif x']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('partial-repair probe', ['1.', ['a', 'of', 'serif', 'type', 'the', 'ink', 'is', 'at', 'kerning'], 14, 3], ['1. a of serif', '   type the', '   ink is at', '   kerning']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['of', 'x', 'is'], 18, 4], ['•   of x is']), ('control layout', ['1.', ['serif', 'at'], 14, 3], ['1. serif at']), ('control layout', ['iv.', ['of', 'is'], 17, 2], ['iv. of is'])], [('regression: column fit boundary', ['iv.', ['type', 'a', 'of', 'of', 'is', 'is', 'baseline', 'kerning'], 13, 4], ['iv. type a of', '    of is is', '    baseline', '    kerning']), ('regression: column fit boundary', ['Note:', ['on', 'at', 'a', 'x', 'baseline', 'x', 'grid'], 18, 3], ['Note: on at a x', '   baseline x grid']), ('regression: column fit boundary', ['A.1.2', ['measure', 'is', 'grid', 'type', 'type', 'of', 'serif', 'at', 'ink'], 20, 3], ['A.1.2 measure is', '   grid type type of', '   serif at ink']), ('partial-repair probe', ['A.1.2', ['ink', 'grid', 'ink', 'serif', 'is', 'baseline'], 13, 2], ['A.1.2 ink', '  grid ink', '  serif is', '  baseline']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['•', ['a', 'kerning', 'measure', 'the', 'the', 'kerning', 'is'], 15, 3], ['•  a kerning', '   measure the', '   the kerning', '   is']), ('control layout', ['1.', ['is', 'x'], 18, 3], ['1. is x'])], [('regression: column fit boundary', ['•', ['is', 'x', 'at', 'type', 'kerning', 'the'], 14, 3], ['•  is x at', '   type', '   kerning the']), ('regression: column fit boundary', ['A.1.2', ['a', 'kerning', 'measure', 'a', 'at', 'measure'], 22, 2], ['A.1.2 a kerning', '  measure a at measure']), ('regression: column fit boundary', ['Note:', ['is', 'measure', 'a', 'x', 'type', 'on', 'measure', 'of'], 18, 2], ['Note: is measure a', '  x type on', '  measure of']), ('partial-repair probe', ['(a)', ['type', 'ink'], 12, 5], ['(a)  type', '     ink']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['baseline', 'grid', 'on', 'is', 'kerning'], 13, 2], ['A.1.2 baseline', '  grid on is', '  kerning']), ('control layout', ['Note:', ['ink', 'baseline', 'measure', 'type', 'type', 'ink', 'kerning', 'at', 'kerning'], 19, 5], ['Note: ink baseline', '     measure type', '     type ink', '     kerning at', '     kerning'])], [('regression: column fit boundary', ['•', ['measure', 'kerning', 'grid', 'of'], 20, 5], ['•    measure kerning', '     grid of']), ('regression: column fit boundary', ['10.', ['grid', 'is', 'type', 'of', 'of', 'of', 'a', 'on', 'ink'], 19, 3], ['10. grid is type of', '   of of a on ink']), ('regression: column fit boundary', ['(a)', ['of', 'ink', 'baseline', 'ink', 'on', 'type', 'measure', 'baseline', 'grid'], 14, 2], ['(a) of ink', '  baseline ink', '  on type', '  measure', '  baseline', '  grid']), ('partial-repair probe', ['1.', ['of', 'type', 'kerning', 'the', 'on', 'kerning', 'type', 'x', 'kerning'], 22, 4], ['1.  of type kerning', '    the on kerning', '    type x kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['•', ['of', 'of'], 20, 4], ['•   of of']), ('control layout', ['1.', ['ink', 'kerning'], 22, 5], ['1.   ink kerning'])]]
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)

prompt:
Words that end exactly at the right edge are wrapped.

Input [label, words, width, hang]. The label starts at column 0; first-line text starts at column hang when label+1 space fits, else right after label plus one space. Continuation lines are indented by hang. Greedy fill with unit spaces measuring absolute columns. Return padded lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * start
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * start
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: continuation indent', ['(a)', ['measure', 'the', 'at', 'type', 'the', 'is', 'type', 'of'], 16, 3], ['(a) measure the', '   at type the', '   is type of']), ('regression: continuation indent', ['Note:', ['a', 'serif', 'at', 'ink', 'on', 'of'], 21, 5], ['Note: a serif at ink', '     on of']), ('regression: continuation indent', ['1.', ['on', 'x', 'kerning', 'at', 'the', 'grid', 'is', 'the'], 13, 2], ['1. on x', '  kerning at', '  the grid is', '  the']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['10.', ['x', 'on', 'kerning'], 21, 2], ['10. x on kerning']), ('control layout', ['A.1.2', ['the', 'the'], 14, 3], ['A.1.2 the the']), ('control layout', ['1.', ['serif', 'on'], 16, 2], ['1. serif on'])], [('regression: continuation indent', ['Note:', ['on', 'at', 'a', 'x', 'baseline', 'x', 'grid'], 18, 3], ['Note: on at a x', '   baseline x grid']), ('regression: continuation indent', ['10.', ['is', 'is', 'x', 'x', 'baseline', 'grid', 'serif', 'the', 'on'], 17, 3], ['10. is is x x', '   baseline grid', '   serif the on']), ('partial-repair probe', ['10.', ['measure', 'at', 'kerning', 'a'], 22, 5], ['10.  measure at', '     kerning a']), ('partial-repair probe', ['iv.', ['x', 'a', 'on', 'ink', 'on', 'type', 'a'], 19, 5], ['iv.  x a on ink on', '     type a']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['type', 'x', 'ink'], 18, 2], ['A.1.2 type x ink']), ('control layout', ['10.', ['the', 'x', 'the'], 15, 2], ['10. the x the'])], [('regression: continuation indent', ['Note:', ['x', 'of', 'the', 'serif', 'a', 'ink', 'type'], 22, 4], ['Note: x of the serif a', '    ink type']), ('regression: continuation indent', ['(a)', ['measure', 'the', 'at', 'type', 'the', 'is', 'type', 'of'], 16, 3], ['(a) measure the', '   at type the', '   is type of']), ('partial-repair probe', ['1.', ['grid', 'grid', 'type', 'serif', 'baseline', 'is', 'x', 'is'], 13, 3], ['1. grid grid', '   type serif', '   baseline', '   is x is']), ('partial-repair probe', ['iv.', ['type', 'a', 'of', 'of', 'is', 'is', 'baseline', 'kerning'], 13, 4], ['iv. type a of', '    of is is', '    baseline', '    kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['A.1.2', ['type', 'measure'], 21, 3], ['A.1.2 type measure']), ('control layout', ['iv.', ['a', 'measure', 'the'], 21, 5], ['iv.  a measure the'])], [('regression: continuation indent', ['A.1.2', ['ink', 'ink', 'on', 'serif', 'is', 'baseline', 'a', 'on', 'serif'], 16, 2], ['A.1.2 ink ink on', '  serif is', '  baseline a on', '  serif']), ('regression: continuation indent', ['(a)', ['type', 'type', 'kerning', 'ink'], 19, 2], ['(a) type type', '  kerning ink']), ('regression: continuation indent', ['10.', ['kerning', 'grid', 'on', 'at', 'ink', 'on', 'at', 'baseline', 'is'], 14, 2], ['10. kerning', '  grid on at', '  ink on at', '  baseline is']), ('partial-repair probe', ['1.', ['a', 'serif', 'kerning', 'baseline'], 21, 4], ['1.  a serif kerning', '    baseline']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['Note:', ['type', 'x', 'at'], 16, 3], ['Note: type x at']), ('control layout', ['1.', ['on', 'is'], 18, 5], ['1.   on is'])], [('regression: continuation indent', ['(a)', ['x', 'ink', 'at', 'measure', 'the', 'type', 'a', 'is'], 17, 3], ['(a) x ink at', '   measure the', '   type a is']), ('regression: continuation indent', ['(a)', ['grid', 'is', 'of', 'a', 'of', 'on', 'x', 'at'], 22, 2], ['(a) grid is of a of on', '  x at']), ('partial-repair probe', ['1.', ['of', 'ink', 'ink', 'type', 'x', 'baseline', 'is', 'ink'], 17, 4], ['1.  of ink ink', '    type x', '    baseline is', '    ink']), ('partial-repair probe', ['iv.', ['serif', 'x', 'kerning', 'ink', 'ink', 'the', 'is'], 15, 5], ['iv.  serif x', '     kerning', '     ink ink', '     the is']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['serif', 'at'], 14, 3], ['1. serif at']), ('control layout', ['A.1.2', ['type', 'x', 'ink'], 18, 2], ['A.1.2 type x ink'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    label, words, width, hang = x
    lines = []
    first = True
    start = hang if len(label) + 1 <= hang else len(label) + 1
    cur = []
    col = start
    for w in words:
        need = col + len(w) if not cur else col + 1 + len(w)
        if cur and need > width:
            prefix = label.ljust(start) if first else ' ' * (hang - 1)
            lines.append(prefix + ' '.join(cur))
            first = False
            cur = [w]
            col = hang + len(w)
        else:
            cur.append(w)
            col = need
    if cur:
        prefix = label.ljust(start) if first else ' ' * (hang - 1)
        lines.append(prefix + ' '.join(cur))
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('regression: continuation indent', ['(a)', ['measure', 'the', 'at', 'type', 'the', 'is', 'type', 'of'], 16, 3], ['(a) measure the', '   at type the', '   is type of']), ('regression: continuation indent', ['Note:', ['a', 'serif', 'at', 'ink', 'on', 'of'], 21, 5], ['Note: a serif at ink', '     on of']), ('regression: continuation indent', ['1.', ['on', 'x', 'kerning', 'at', 'the', 'grid', 'is', 'the'], 13, 2], ['1. on x', '  kerning at', '  the grid is', '  the']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['10.', ['x', 'on', 'kerning'], 21, 2], ['10. x on kerning']), ('control layout', ['A.1.2', ['the', 'the'], 14, 3], ['A.1.2 the the']), ('control layout', ['1.', ['serif', 'on'], 16, 2], ['1. serif on'])], [('regression: continuation indent', ['Note:', ['on', 'at', 'a', 'x', 'baseline', 'x', 'grid'], 18, 3], ['Note: on at a x', '   baseline x grid']), ('regression: continuation indent', ['10.', ['is', 'is', 'x', 'x', 'baseline', 'grid', 'serif', 'the', 'on'], 17, 3], ['10. is is x x', '   baseline grid', '   serif the on']), ('partial-repair probe', ['10.', ['measure', 'at', 'kerning', 'a'], 22, 5], ['10.  measure at', '     kerning a']), ('partial-repair probe', ['iv.', ['x', 'a', 'on', 'ink', 'on', 'type', 'a'], 19, 5], ['iv.  x a on ink on', '     type a']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['A.1.2', ['type', 'x', 'ink'], 18, 2], ['A.1.2 type x ink']), ('control layout', ['10.', ['the', 'x', 'the'], 15, 2], ['10. the x the'])], [('regression: continuation indent', ['Note:', ['x', 'of', 'the', 'serif', 'a', 'ink', 'type'], 22, 4], ['Note: x of the serif a', '    ink type']), ('regression: continuation indent', ['(a)', ['measure', 'the', 'at', 'type', 'the', 'is', 'type', 'of'], 16, 3], ['(a) measure the', '   at type the', '   is type of']), ('partial-repair probe', ['1.', ['grid', 'grid', 'type', 'serif', 'baseline', 'is', 'x', 'is'], 13, 3], ['1. grid grid', '   type serif', '   baseline', '   is x is']), ('partial-repair probe', ['iv.', ['type', 'a', 'of', 'of', 'is', 'is', 'baseline', 'kerning'], 13, 4], ['iv. type a of', '    of is is', '    baseline', '    kerning']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['A.1.2', ['type', 'measure'], 21, 3], ['A.1.2 type measure']), ('control layout', ['iv.', ['a', 'measure', 'the'], 21, 5], ['iv.  a measure the'])], [('regression: continuation indent', ['A.1.2', ['ink', 'ink', 'on', 'serif', 'is', 'baseline', 'a', 'on', 'serif'], 16, 2], ['A.1.2 ink ink on', '  serif is', '  baseline a on', '  serif']), ('regression: continuation indent', ['(a)', ['type', 'type', 'kerning', 'ink'], 19, 2], ['(a) type type', '  kerning ink']), ('regression: continuation indent', ['10.', ['kerning', 'grid', 'on', 'at', 'ink', 'on', 'at', 'baseline', 'is'], 14, 2], ['10. kerning', '  grid on at', '  ink on at', '  baseline is']), ('partial-repair probe', ['1.', ['a', 'serif', 'kerning', 'baseline'], 21, 4], ['1.  a serif kerning', '    baseline']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('control layout', ['Note:', ['type', 'x', 'at'], 16, 3], ['Note: type x at']), ('control layout', ['1.', ['on', 'is'], 18, 5], ['1.   on is'])], [('regression: continuation indent', ['(a)', ['x', 'ink', 'at', 'measure', 'the', 'type', 'a', 'is'], 17, 3], ['(a) x ink at', '   measure the', '   type a is']), ('regression: continuation indent', ['(a)', ['grid', 'is', 'of', 'a', 'of', 'on', 'x', 'at'], 22, 2], ['(a) grid is of a of on', '  x at']), ('partial-repair probe', ['1.', ['of', 'ink', 'ink', 'type', 'x', 'baseline', 'is', 'ink'], 17, 4], ['1.  of ink ink', '    type x', '    baseline is', '    ink']), ('partial-repair probe', ['iv.', ['serif', 'x', 'kerning', 'ink', 'ink', 'the', 'is'], 15, 5], ['iv.  serif x', '     kerning', '     ink ink', '     the is']), ('label overflows hang', ['Note:', ['the', 'type', 'grid', 'is', 'on', 'serif'], 14, 3], ['Note: the type', '   grid is on', '   serif']), ('label exactly one short of hang', ['1.', ['the', 'type', 'grid', 'is', 'on'], 12, 3], ['1. the type', '   grid is', '   on']), ('control layout', ['1.', ['serif', 'at'], 14, 3], ['1. serif at']), ('control layout', ['A.1.2', ['type', 'x', 'ink'], 18, 2], ['A.1.2 type x ink'])]]
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)

prompt:
Continuation lines are indented under the first-line text instead of the hang.

Input [label, words, width, hang]. The label starts at column 0; first-line text starts at column hang when label+1 space fits, else right after label plus one space. Continuation lines are indented by hang. Greedy fill with unit spaces measuring absolute columns. Return padded lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width = x
    SINGLE = {'a', 'i', 'o', 'u', 'v', 'z', 'k', 's', 'w'}
    UNITS = {'kg', 'km', 'cm', 'mm', '%', 'pt', 'px'}
    groups = []
    k = 0
    while k < len(words):
        grp = [words[k]]
        while True:
            last = grp[-1]
            nxt = k + len(grp)
            if nxt >= len(words):
                break
            number = last.replace('.', '').replace(',', '').isdigit()
            if last in SINGLE or (number and words[nxt] in UNITS):
                grp.append(words[nxt])
            else:
                break
        groups.append(' '.join(grp))
        k += len(grp)
    lines, cur = [], ''
    for g in groups:
        cand = g if not cur else cur + ' ' + g
        if len(cand) <= width or not cur:
            cur = cand
        else:
            lines.append(cur)
            cur = g
    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: single-letter case folding', [['V', 'V', 'text', 'Praze', 'k', 'k', 'kg', '2.5', 'V', 'pt', 's', 'Praze'], 14], ['V V text Praze', 'k k kg 2.5', 'V pt s Praze']), ('regression: single-letter case folding', [['10', 'i', 's', 'řádek', 'o', 'V', 'Praze', 'kg', 'i', 'domě'], 16], ['10 i s řádek', 'o V Praze kg', 'i domě']), ('partial-repair probe', [['k', 'k', 'km', 'pt', 'o', 's', 'z', '10', 'řádek', 'i', 'z', 'km'], 11], ['k k km pt', 'o s z 10', 'řádek', 'i z km']), ('partial-repair probe', [['z', '2.5', 'i', 'v', 'o', 'sazba', 'text', 'kg', 'text', 'V', 'domě'], 16], ['z 2.5', 'i v o sazba text', 'kg text V domě']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['k', 'řádek', 'km', 'k'], 11], ['k řádek km', 'k']), ('control layout', [['s', 'i', 'km', 'k', 'pt', 'km', 'kg', 'o', 'kg', 'řádek', 'o'], 6], ['s i km', 'k pt', 'km kg', 'o kg', 'řádek', 'o'])], [('regression: single-letter case folding', [['domě', 'V', 's', 'Praze', 'k'], 6], ['domě', 'V s Praze', 'k']), ('regression: single-letter case folding', [['o', 'V', 'V', 'o', 'o', 'o', '2.5', 'i', 'kg', 'i'], 9], ['o V V o o o 2.5', 'i kg i']), ('regression: single-letter case folding', [['o', 's', 'text', 'V', '1,5', 'cm', '1,5', 'a', 'text', '1,5', 'a', '1,5'], 13], ['o s text', 'V 1,5 cm 1,5', 'a text 1,5', 'a 1,5']), ('partial-repair probe', [['z', 's', 'řádek', 'z', 'z', 'pt'], 13], ['z s řádek', 'z z pt']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['v', 'V', 'o', 's', 'Praze', 'k'], 14], ['v V o s Praze', 'k']), ('control layout', [['km', '2.5', 'km', 'sazba', 'text', 's'], 11], ['km 2.5 km', 'sazba text', 's'])], [('regression: single-letter case folding', [['a', 'řádek', 'text', 'V', 'i', 'V', 'i', 'i', 'o', 'sazba', 'km', 'Praze'], 8], ['a řádek', 'text', 'V i V i i o sazba', 'km Praze']), ('regression: single-letter case folding', [['o', 's', 'text', 'V', '1,5', 'cm', '1,5', 'a', 'text', '1,5', 'a', '1,5'], 13], ['o s text', 'V 1,5 cm 1,5', 'a text 1,5', 'a 1,5']), ('partial-repair probe', [['o', 'km', 'pt', '10', 'kg', 'Praze', 'text', 'k', 'sazba'], 7], ['o km pt', '10 kg', 'Praze', 'text', 'k sazba']), ('partial-repair probe', [['km', '2.5', 'pt', 'i', 'i', 'pt', 'sazba', 'řádek', 'o', 'domě', '1,5', 'cm'], 13], ['km 2.5 pt', 'i i pt sazba', 'řádek o domě', '1,5 cm']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['s', 'řádek', 'domě', 'cm', 'text', 'z', 'domě', 'i'], 16], ['s řádek domě cm', 'text z domě i']), ('control layout', [['2.5', 'řádek', 'pt', 'text', 'text', 'Praze', '1,5', 'text'], 15], ['2.5 řádek pt', 'text text Praze', '1,5 text'])], [('regression: single-letter case folding', [['v', 'Praze', 'Praze', 'v', '1,5', 'cm', 'k', 'V', '10'], 12], ['v Praze', 'Praze', 'v 1,5 cm', 'k V 10']), ('regression: single-letter case folding', [['Praze', 'k', '10', '1,5', 'sazba', 'a', 'text', 'V', '1,5', '10', 'kg'], 8], ['Praze', 'k 10 1,5', 'sazba', 'a text', 'V 1,5', '10 kg']), ('partial-repair probe', [['i', 'z', 'Praze', 'z', 'řádek', '10'], 8], ['i z Praze', 'z řádek', '10']), ('regression: single-letter case folding', [['1,5', 'km', 'domě', 'sazba', 'kg', 'V', 'v', 'text', 'domě', '1,5'], 11], ['1,5 km domě', 'sazba kg', 'V v text', 'domě 1,5']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['cm', 'k', 'V', 'z', 'řádek'], 14], ['cm k V z řádek']), ('control layout', [['sazba', 'domě', 'z', 'text', 'Praze', 's'], 10], ['sazba domě', 'z text', 'Praze s'])], [('regression: single-letter case folding', [['sazba', 'Praze', 'V', '1,5', 'k'], 15], ['sazba Praze', 'V 1,5 k']), ('regression: single-letter case folding', [['cm', '10', 's', 'k', 'V', 'o'], 6], ['cm 10', 's k V o']), ('regression: single-letter case folding', [['z', 'k', '10', 'z', '2.5', '1,5', 'V', '1,5', 'i', '10', 'sazba', 'kg'], 6], ['z k 10', 'z 2.5', '1,5', 'V 1,5', 'i 10', 'sazba', 'kg']), ('regression: single-letter case folding', [['a', 'z', '2.5', 'v', 'text', 'V', 'kg', 'domě', 'v'], 16], ['a z 2.5 v text', 'V kg domě v']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['řádek', 'Praze', '1,5', 'i', 'řádek', 'domě'], 11], ['řádek Praze', '1,5 i řádek', 'domě']), ('control layout', [['pt', 'v', 'text', 'z', '2.5'], 10], ['pt v text', 'z 2.5'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width = x
    SINGLE = {'a', 'i', 'o', 'u', 'v', 'z', 'k', 's', 'w'}
    UNITS = {'kg', 'km', 'cm', 'mm', '%', 'pt', 'px'}
    groups = []
    k = 0
    while k < len(words):
        grp = [words[k]]
        while True:
            last = grp[-1]
            nxt = k + len(grp)
            if nxt >= len(words):
                break
            number = last.replace('.', '').replace(',', '').isdigit()
            if last.upper() in SINGLE or (number and words[nxt] in UNITS):
                grp.append(words[nxt])
            else:
                break
        groups.append(' '.join(grp))
        k += len(grp)
    lines, cur = [], ''
    for g in groups:
        cand = g if not cur else cur + ' ' + g
        if len(cand) <= width or not cur:
            cur = cand
        else:
            lines.append(cur)
            cur = g
    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: single-letter case folding', [['V', 'V', 'text', 'Praze', 'k', 'k', 'kg', '2.5', 'V', 'pt', 's', 'Praze'], 14], ['V V text Praze', 'k k kg 2.5', 'V pt s Praze']), ('regression: single-letter case folding', [['10', 'i', 's', 'řádek', 'o', 'V', 'Praze', 'kg', 'i', 'domě'], 16], ['10 i s řádek', 'o V Praze kg', 'i domě']), ('partial-repair probe', [['k', 'k', 'km', 'pt', 'o', 's', 'z', '10', 'řádek', 'i', 'z', 'km'], 11], ['k k km pt', 'o s z 10', 'řádek', 'i z km']), ('partial-repair probe', [['z', '2.5', 'i', 'v', 'o', 'sazba', 'text', 'kg', 'text', 'V', 'domě'], 16], ['z 2.5', 'i v o sazba text', 'kg text V domě']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['k', 'řádek', 'km', 'k'], 11], ['k řádek km', 'k']), ('control layout', [['s', 'i', 'km', 'k', 'pt', 'km', 'kg', 'o', 'kg', 'řádek', 'o'], 6], ['s i km', 'k pt', 'km kg', 'o kg', 'řádek', 'o'])], [('regression: single-letter case folding', [['domě', 'V', 's', 'Praze', 'k'], 6], ['domě', 'V s Praze', 'k']), ('regression: single-letter case folding', [['o', 'V', 'V', 'o', 'o', 'o', '2.5', 'i', 'kg', 'i'], 9], ['o V V o o o 2.5', 'i kg i']), ('regression: single-letter case folding', [['o', 's', 'text', 'V', '1,5', 'cm', '1,5', 'a', 'text', '1,5', 'a', '1,5'], 13], ['o s text', 'V 1,5 cm 1,5', 'a text 1,5', 'a 1,5']), ('partial-repair probe', [['z', 's', 'řádek', 'z', 'z', 'pt'], 13], ['z s řádek', 'z z pt']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['v', 'V', 'o', 's', 'Praze', 'k'], 14], ['v V o s Praze', 'k']), ('control layout', [['km', '2.5', 'km', 'sazba', 'text', 's'], 11], ['km 2.5 km', 'sazba text', 's'])], [('regression: single-letter case folding', [['a', 'řádek', 'text', 'V', 'i', 'V', 'i', 'i', 'o', 'sazba', 'km', 'Praze'], 8], ['a řádek', 'text', 'V i V i i o sazba', 'km Praze']), ('regression: single-letter case folding', [['o', 's', 'text', 'V', '1,5', 'cm', '1,5', 'a', 'text', '1,5', 'a', '1,5'], 13], ['o s text', 'V 1,5 cm 1,5', 'a text 1,5', 'a 1,5']), ('partial-repair probe', [['o', 'km', 'pt', '10', 'kg', 'Praze', 'text', 'k', 'sazba'], 7], ['o km pt', '10 kg', 'Praze', 'text', 'k sazba']), ('partial-repair probe', [['km', '2.5', 'pt', 'i', 'i', 'pt', 'sazba', 'řádek', 'o', 'domě', '1,5', 'cm'], 13], ['km 2.5 pt', 'i i pt sazba', 'řádek o domě', '1,5 cm']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['s', 'řádek', 'domě', 'cm', 'text', 'z', 'domě', 'i'], 16], ['s řádek domě cm', 'text z domě i']), ('control layout', [['2.5', 'řádek', 'pt', 'text', 'text', 'Praze', '1,5', 'text'], 15], ['2.5 řádek pt', 'text text Praze', '1,5 text'])], [('regression: single-letter case folding', [['v', 'Praze', 'Praze', 'v', '1,5', 'cm', 'k', 'V', '10'], 12], ['v Praze', 'Praze', 'v 1,5 cm', 'k V 10']), ('regression: single-letter case folding', [['Praze', 'k', '10', '1,5', 'sazba', 'a', 'text', 'V', '1,5', '10', 'kg'], 8], ['Praze', 'k 10 1,5', 'sazba', 'a text', 'V 1,5', '10 kg']), ('partial-repair probe', [['i', 'z', 'Praze', 'z', 'řádek', '10'], 8], ['i z Praze', 'z řádek', '10']), ('regression: single-letter case folding', [['1,5', 'km', 'domě', 'sazba', 'kg', 'V', 'v', 'text', 'domě', '1,5'], 11], ['1,5 km domě', 'sazba kg', 'V v text', 'domě 1,5']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['cm', 'k', 'V', 'z', 'řádek'], 14], ['cm k V z řádek']), ('control layout', [['sazba', 'domě', 'z', 'text', 'Praze', 's'], 10], ['sazba domě', 'z text', 'Praze s'])], [('regression: single-letter case folding', [['sazba', 'Praze', 'V', '1,5', 'k'], 15], ['sazba Praze', 'V 1,5 k']), ('regression: single-letter case folding', [['cm', '10', 's', 'k', 'V', 'o'], 6], ['cm 10', 's k V o']), ('regression: single-letter case folding', [['z', 'k', '10', 'z', '2.5', '1,5', 'V', '1,5', 'i', '10', 'sazba', 'kg'], 6], ['z k 10', 'z 2.5', '1,5', 'V 1,5', 'i 10', 'sazba', 'kg']), ('regression: single-letter case folding', [['a', 'z', '2.5', 'v', 'text', 'V', 'kg', 'domě', 'v'], 16], ['a z 2.5 v text', 'V kg domě v']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['řádek', 'Praze', '1,5', 'i', 'řádek', 'domě'], 11], ['řádek Praze', '1,5 i řádek', 'domě']), ('control layout', [['pt', 'v', 'text', 'z', '2.5'], 10], ['pt v text', 'z 2.5'])]]
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)

prompt:
Capitalised single-letter words at sentence start dangle at line ends.

Input [words, width]. A single-letter preposition/conjunction (a i o u v z k s w, any case) is bound to the following word, chaining; a number (digits with optional . or , decimal) is bound to a following unit (kg km cm mm % pt px). Bound groups are unbreakable; greedy fill of groups with unit spaces; an overwide group is set alone. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width = x
    SINGLE = {'a', 'i', 'o', 'u', 'v', 'z', 'k', 's', 'w'}
    UNITS = {'kg', 'km', 'cm', 'mm', '%', 'pt', 'px'}
    groups = []
    k = 0
    while k < len(words):
        grp = [words[k]]
        while True:
            last = grp[-1]
            nxt = k + len(grp)
            if nxt >= len(words):
                break
            number = last.replace('.', '').replace(',', '').isdigit()
            if last.lower() in SINGLE or (number and words[nxt] in UNITS):
                grp.append(words[nxt])
                break
            else:
                break
        groups.append(' '.join(grp))
        k += len(grp)
    lines, cur = [], ''
    for g in groups:
        cand = g if not cur else cur + ' ' + g
        if len(cand) <= width or not cur:
            cur = cand
        else:
            lines.append(cur)
            cur = g
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('regression: binding chain', [['km', 'z', 'sazba', 'k', 'Praze', 's', 'V', 'k', 'text'], 15], ['km z sazba', 'k Praze', 's V k text']), ('partial-repair probe', [['10', 'i', 'a', 'pt', '10', 'domě', 'o', 'a', 'cm', 'a', 'sazba'], 9], ['10 i a pt', '10 domě', 'o a cm', 'a sazba']), ('regression: binding chain', [['text', 'kg', 'o', 'i', 'pt', 'i', 'a', 'o', 'V', 'řádek'], 9], ['text kg', 'o i pt', 'i a o V řádek']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['i', 'V', 'V', 'z', 'a', 'v'], 11], ['i V V z a v']), ('control layout', [['domě', 'k', 'a', 'a', 'pt', 'a', 'V', '10', 'pt'], 16], ['domě k a a pt', 'a V 10 pt'])], [('regression: binding chain', [['z', 'k', '2.5', 'i', 'V', 'o', 'i', 'z', 'z'], 10], ['z k 2.5', 'i V o i z z']), ('regression: binding chain', [['Praze', 'k', 'z', 'kg', 'a', 'i', 'a', 'text', 'cm', 'v'], 11], ['Praze', 'k z kg', 'a i a text', 'cm v']), ('regression: binding chain', [['2.5', '2.5', 'kg', 'z', 'a', 'pt', 'řádek', 'i', 'Praze', 'domě', 'V', 'v'], 14], ['2.5 2.5 kg', 'z a pt řádek', 'i Praze domě', 'V v']), ('regression: binding chain', [['2.5', 'k', 'cm', 's', 'V', 'cm', 's', 'pt', 's', 'Praze'], 14], ['2.5 k cm', 's V cm s pt', 's Praze']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['v', 'pt', 'pt', 'domě', 'sazba', 'o', '1,5', 'sazba', '10', '1,5'], 7], ['v pt pt', 'domě', 'sazba', 'o 1,5', 'sazba', '10 1,5']), ('control layout', [['kg', 'cm', 'o', 'kg', 'cm', 'domě', 'domě'], 12], ['kg cm o kg', 'cm domě domě'])], [('regression: binding chain', [['pt', 'cm', 'a', '2.5', 'i', 'domě', 'text', 's', 'o', 'o'], 8], ['pt cm', 'a 2.5', 'i domě', 'text', 's o o']), ('regression: binding chain', [['s', 'o', 'V', 'i', 'domě', 's', 'domě', 'pt', 'a', '1,5', 'o'], 9], ['s o V i domě', 's domě pt', 'a 1,5 o']), ('partial-repair probe', [['kg', 'v', 'km', 'V', 'cm', '10', 'text', 'a', 'kg'], 8], ['kg v km', 'V cm 10', 'text', 'a kg']), ('partial-repair probe', [['řádek', '2.5', '10', 'i', 'i', 'km', 'i', 'k'], 8], ['řádek', '2.5 10', 'i i km', 'i k']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['k', 'V', 'z', 'km', '1,5', '1,5', 'V', 'o', 's'], 12], ['k V z km 1,5', '1,5 V o s']), ('control layout', [['o', 'km', 'cm', '2.5'], 6], ['o km', 'cm 2.5'])], [('regression: binding chain', [['km', 'V', '10', 'km', '2.5', 'V'], 6], ['km', 'V 10 km', '2.5 V']), ('regression: binding chain', [['pt', 'k', '1,5', 'cm', 'k', 'i', 'a', 'v', 's', '10', 'cm', '10'], 13], ['pt k 1,5 cm', 'k i a v s 10 cm', '10']), ('regression: binding chain', [['Praze', 'i', 'o', 'domě'], 7], ['Praze', 'i o domě']), ('partial-repair probe', [['a', 'text', 'kg', 'o', 'sazba', 'v', 'km', 's', 'text'], 14], ['a text kg', 'o sazba v km', 's text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['V', 'Praze', 'kg', 'pt', 'km', 's', 'pt'], 8], ['V Praze', 'kg pt km', 's pt']), ('control layout', [['řádek', 'z', '10', 'i', 'o', '1,5'], 13], ['řádek z 10', 'i o 1,5'])], [('regression: binding chain', [['i', 'z', 'Praze', 'z', 'řádek', '10'], 8], ['i z Praze', 'z řádek', '10']), ('regression: binding chain', [['text', 'V', 'řádek', 'v', 'sazba', 's', 's', 'a', 'o', '10'], 14], ['text V řádek', 'v sazba', 's s a o 10']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('regression: binding chain', [['o', 'pt', 'domě', 's', 'a', 'text'], 6], ['o pt', 'domě', 's a text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['V', 'km', '2.5', 'Praze', '10', 'k'], 9], ['V km 2.5', 'Praze 10', 'k']), ('control layout', [['km', 'o', 'cm', 'km', 'sazba', 'k'], 7], ['km o cm', 'km', 'sazba k'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    words, width = x
    SINGLE = {'a', 'i', 'o', 'u', 'v', 'z', 'k', 's', 'w'}
    UNITS = {'kg', 'km', 'cm', 'mm', '%', 'pt', 'px'}
    groups = []
    k = 0
    while k < len(words):
        grp = [words[k]]
        while True:
            last = grp[-1]
            nxt = k + len(grp)
            if nxt >= len(words) - 1:
                break
            number = last.replace('.', '').replace(',', '').isdigit()
            if last.lower() in SINGLE or (number and words[nxt] in UNITS):
                grp.append(words[nxt])
            else:
                break
        groups.append(' '.join(grp))
        k += len(grp)
    lines, cur = [], ''
    for g in groups:
        cand = g if not cur else cur + ' ' + g
        if len(cand) <= width or not cur:
            cur = cand
        else:
            lines.append(cur)
            cur = g
    if cur:
        lines.append(cur)
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('regression: binding chain', [['km', 'z', 'sazba', 'k', 'Praze', 's', 'V', 'k', 'text'], 15], ['km z sazba', 'k Praze', 's V k text']), ('partial-repair probe', [['10', 'i', 'a', 'pt', '10', 'domě', 'o', 'a', 'cm', 'a', 'sazba'], 9], ['10 i a pt', '10 domě', 'o a cm', 'a sazba']), ('regression: binding chain', [['text', 'kg', 'o', 'i', 'pt', 'i', 'a', 'o', 'V', 'řádek'], 9], ['text kg', 'o i pt', 'i a o V řádek']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['i', 'V', 'V', 'z', 'a', 'v'], 11], ['i V V z a v']), ('control layout', [['domě', 'k', 'a', 'a', 'pt', 'a', 'V', '10', 'pt'], 16], ['domě k a a pt', 'a V 10 pt'])], [('regression: binding chain', [['z', 'k', '2.5', 'i', 'V', 'o', 'i', 'z', 'z'], 10], ['z k 2.5', 'i V o i z z']), ('regression: binding chain', [['Praze', 'k', 'z', 'kg', 'a', 'i', 'a', 'text', 'cm', 'v'], 11], ['Praze', 'k z kg', 'a i a text', 'cm v']), ('regression: binding chain', [['2.5', '2.5', 'kg', 'z', 'a', 'pt', 'řádek', 'i', 'Praze', 'domě', 'V', 'v'], 14], ['2.5 2.5 kg', 'z a pt řádek', 'i Praze domě', 'V v']), ('regression: binding chain', [['2.5', 'k', 'cm', 's', 'V', 'cm', 's', 'pt', 's', 'Praze'], 14], ['2.5 k cm', 's V cm s pt', 's Praze']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('control layout', [['v', 'pt', 'pt', 'domě', 'sazba', 'o', '1,5', 'sazba', '10', '1,5'], 7], ['v pt pt', 'domě', 'sazba', 'o 1,5', 'sazba', '10 1,5']), ('control layout', [['kg', 'cm', 'o', 'kg', 'cm', 'domě', 'domě'], 12], ['kg cm o kg', 'cm domě domě'])], [('regression: binding chain', [['pt', 'cm', 'a', '2.5', 'i', 'domě', 'text', 's', 'o', 'o'], 8], ['pt cm', 'a 2.5', 'i domě', 'text', 's o o']), ('regression: binding chain', [['s', 'o', 'V', 'i', 'domě', 's', 'domě', 'pt', 'a', '1,5', 'o'], 9], ['s o V i domě', 's domě pt', 'a 1,5 o']), ('partial-repair probe', [['kg', 'v', 'km', 'V', 'cm', '10', 'text', 'a', 'kg'], 8], ['kg v km', 'V cm 10', 'text', 'a kg']), ('partial-repair probe', [['řádek', '2.5', '10', 'i', 'i', 'km', 'i', 'k'], 8], ['řádek', '2.5 10', 'i i km', 'i k']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('control layout', [['k', 'V', 'z', 'km', '1,5', '1,5', 'V', 'o', 's'], 12], ['k V z km 1,5', '1,5 V o s']), ('control layout', [['o', 'km', 'cm', '2.5'], 6], ['o km', 'cm 2.5'])], [('regression: binding chain', [['km', 'V', '10', 'km', '2.5', 'V'], 6], ['km', 'V 10 km', '2.5 V']), ('regression: binding chain', [['pt', 'k', '1,5', 'cm', 'k', 'i', 'a', 'v', 's', '10', 'cm', '10'], 13], ['pt k 1,5 cm', 'k i a v s 10 cm', '10']), ('regression: binding chain', [['Praze', 'i', 'o', 'domě'], 7], ['Praze', 'i o domě']), ('partial-repair probe', [['a', 'text', 'kg', 'o', 'sazba', 'v', 'km', 's', 'text'], 14], ['a text kg', 'o sazba v km', 's text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['V', 'Praze', 'kg', 'pt', 'km', 's', 'pt'], 8], ['V Praze', 'kg pt km', 's pt']), ('control layout', [['řádek', 'z', '10', 'i', 'o', '1,5'], 13], ['řádek z 10', 'i o 1,5'])], [('regression: binding chain', [['i', 'z', 'Praze', 'z', 'řádek', '10'], 8], ['i z Praze', 'z řádek', '10']), ('regression: binding chain', [['text', 'V', 'řádek', 'v', 'sazba', 's', 's', 'a', 'o', '10'], 14], ['text V řádek', 'v sazba', 's s a o 10']), ('chained singles', [['text', 'v', 'a', 'k', 'domě'], 10], ['text', 'v a k domě']), ('regression: binding chain', [['o', 'pt', 'domě', 's', 'a', 'text'], 6], ['o pt', 'domě', 's a text']), ('sentence-initial V binds', [['V', 'Praze', 'text', 'sazba'], 8], ['V Praze', 'text', 'sazba']), ('decimal comma with unit', [['sazba', '1,5', 'cm', 'text'], 9], ['sazba', '1,5 cm', 'text']), ('control layout', [['V', 'km', '2.5', 'Praze', '10', 'k'], 9], ['V km 2.5', 'Praze 10', 'k']), ('control layout', [['km', 'o', 'cm', 'km', 'sazba', 'k'], 7], ['km o cm', 'km', 'sazba k'])]]
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)

prompt:
In "v a k domě" only the first preposition stays bound.

Input [words, width]. A single-letter preposition/conjunction (a i o u v z k s w, any case) is bound to the following word, chaining; a number (digits with optional . or , decimal) is bound to a following unit (kg km cm mm % pt px). Bound groups are unbreakable; greedy fill of groups with unit spaces; an overwide group is set alone. Return lines.

split: open-access