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

N = 1
observations = []
def solve(x):
    items, width = x
    lines = []
    start = 0
    n = len(items)
    while start < n:
        while start < n and items[start][0] != 'b':
            start += 1
        if start >= n:
            break
        total = 0
        last = None
        result = None
        i = start
        while i < n:
            it = items[i]
            if it[0] == 'p':
                if it[2] <= -10000:
                    result = (i, total + it[1], 'forced')
                    break
                if it[2] < 10000:
                    last = (i, total + it[1], 'penalty')
            elif it[0] == 'g':
                if items[i - 1][0] == 'b':
                    last = (i, total, 'glue')
                total += it[1]
            else:
                total += it[1]
            if total >= width and last is not None:
                result = last
                break
            i += 1
        if result is None:
            lines.append([total, 'end'])
            break
        lines.append([result[1], result[2]])
        start = result[0] + 1
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 6], ['g', 2], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1]], 9], [[9, 'glue'], [6, 'glue'], [5, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 0, -10000, False], ['g', 1], ['b', 5], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 2], ['b', 2], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 1], ['g', 1], ['b', 7], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['g', 1], ['b', 2], ['g', 1]], 7], [[5, 'forced'], [5, 'glue'], [3, 'penalty'], [11, 'glue'], [7, 'glue'], [7, 'glue'], [3, 'end']]), ('regression: overflow trigger', [[['b', 6], ['g', 1], ['b', 3], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 7], ['g', 1], ['b', 1], ['g', 1], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1]], 9], [[6, 'glue'], [6, 'penalty'], [9, 'glue'], [7, 'forced'], [2, 'end']]), ('partial-repair probe', [[['b', 4], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 1], ['b', 4], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 0, 10000, False], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 2], ['g', 2]], 8], [[4, 'forced'], [4, 'glue'], [4, 'glue'], [6, 'penalty'], [3, 'penalty'], [11, 'penalty'], [7, 'penalty'], [4, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 2], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['g', 2], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 2], ['p', 0, 900, False], ['p', 1, 50, True], ['g', 1]], 15], [[10, 'glue'], [15, 'penalty'], [10, 'penalty'], [12, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['p', 0, 900, False], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2]], 10], [[7, 'glue'], [7, 'penalty'], [5, 'glue'], [7, 'glue'], [8, 'penalty'], [5, 'end']])], [('regression: overflow trigger', [[['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['g', 1], ['b', 4], ['p', 0, 9999, False], ['g', 2], ['b', 6], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2]], 7], [[7, 'glue'], [4, 'glue'], [6, 'glue'], [1, 'forced'], [7, 'glue'], [4, 'penalty'], [6, 'penalty'], [5, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['g', 1]], 8], [[6, 'penalty'], [5, 'glue'], [5, 'glue'], [6, 'penalty'], [6, 'forced'], [4, 'glue'], [4, 'glue'], [8, 'end']]), ('partial-repair probe', [[['b', 1], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['g', 2]], 12], [[9, 'penalty'], [7, 'penalty'], [10, 'glue'], [10, 'end']]), ('regression: overflow trigger', [[['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['p', 0, 900, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2]], 7], [[7, 'penalty'], [9, 'forced'], [10, 'glue'], [1, 'forced'], [7, 'penalty'], [2, 'penalty'], [6, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 2], ['b', 4], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['p', 0, 10000, False], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2]], 18], [[15, 'forced'], [13, 'forced'], [14, 'penalty'], [5, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1]], 16], [[14, 'glue'], [15, 'glue'], [12, 'end']])], [('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['g', 1], ['g', 1]], 17], [[13, 'glue'], [17, 'glue']]), ('partial-repair probe', [[['b', 5], ['p', 0, -5000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1]], 12], [[5, 'penalty'], [7, 'glue'], [11, 'glue'], [7, 'glue'], [7, 'end']]), ('partial-repair probe', [[['b', 2], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 1]], 7], [[7, 'penalty'], [6, 'penalty'], [7, 'glue'], [7, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 1], ['b', 5], ['g', 1], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 2], ['g', 1], ['b', 5], ['g', 1]], 12], [[10, 'glue'], [11, 'glue'], [6, 'end']]), ('control layout', [[['b', 6], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2]], 14], [[12, 'glue'], [5, 'forced'], [8, 'end']])], [('regression: overflow trigger', [[['b', 5], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 3], ['p', 0, -5000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 5], ['g', 2]], 11], [[11, 'glue'], [10, 'penalty'], [11, 'glue']]), ('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 1]], 8], [[2, 'glue'], [8, 'glue'], [5, 'glue'], [5, 'penalty'], [8, 'penalty'], [5, 'end']]), ('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('partial-repair probe', [[['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 3], ['g', 1], ['g', 1]], 17], [[10, 'glue'], [15, 'penalty'], [15, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 1]], 10], [[7, 'glue'], [8, 'forced'], [7, 'glue'], [6, 'end']]), ('control layout', [[['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 17], [[16, 'glue'], [11, 'end']])], [('regression: overflow trigger', [[['b', 6], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1]], 12], [[12, 'penalty'], [12, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1]], 8], [[3, 'glue'], [8, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 9], [[11, 'glue'], [10, 'penalty']]), ('regression: overflow trigger', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 1], ['g', 1]], 13], [[13, 'glue'], [12, 'glue'], [12, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 3], ['g', 1], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 1], ['g', 1], ['b', 3], ['g', 1]], 14], [[8, 'glue'], [11, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 7], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 2]], 10], [[7, 'glue'], [7, 'glue'], [7, 'glue'], [8, 'glue'], [9, 'end']])]]
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):
    items, width = x
    lines = []
    start = 0
    n = len(items)
    while start < n:
        while start < n and items[start][0] != 'b':
            start += 1
        if start >= n:
            break
        total = 0
        last = None
        result = None
        i = start
        while i < n:
            it = items[i]
            if it[0] == 'p':
                if it[2] <= -10000:
                    result = (i, total + it[1], 'forced')
                    break
                if it[2] < 10000:
                    last = (i, total + it[1], 'penalty')
            elif it[0] == 'g':
                if items[i - 1][0] == 'b':
                    last = (i, total, 'glue')
                total += it[1]
            else:
                total += it[1]
            if total > width + 1 and last is not None:
                result = last
                break
            i += 1
        if result is None:
            lines.append([total, 'end'])
            break
        lines.append([result[1], result[2]])
        start = result[0] + 1
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 6], ['g', 2], ['b', 4], ['p', 0, 9999, False], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['p', 0, 10000, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1]], 9], [[9, 'glue'], [6, 'glue'], [5, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 0, -10000, False], ['g', 1], ['b', 5], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 2], ['b', 2], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 1], ['g', 1], ['b', 7], ['g', 1], ['b', 5], ['g', 1], ['b', 1], ['g', 1], ['b', 2], ['g', 1]], 7], [[5, 'forced'], [5, 'glue'], [3, 'penalty'], [11, 'glue'], [7, 'glue'], [7, 'glue'], [3, 'end']]), ('regression: overflow trigger', [[['b', 6], ['g', 1], ['b', 3], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2], ['b', 7], ['g', 1], ['b', 1], ['g', 1], ['b', 7], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['p', 1, 50, True], ['g', 1]], 9], [[6, 'glue'], [6, 'penalty'], [9, 'glue'], [7, 'forced'], [2, 'end']]), ('partial-repair probe', [[['b', 4], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 1], ['b', 4], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 2], ['p', 0, 10000, False], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 2], ['g', 2]], 8], [[4, 'forced'], [4, 'glue'], [4, 'glue'], [6, 'penalty'], [3, 'penalty'], [11, 'penalty'], [7, 'penalty'], [4, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 2], ['g', 2], ['b', 2], ['g', 1], ['b', 3], ['g', 2], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 7], ['g', 1], ['g', 1], ['b', 2], ['p', 0, 900, False], ['p', 1, 50, True], ['g', 1]], 15], [[10, 'glue'], [15, 'penalty'], [10, 'penalty'], [12, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 7], ['p', 0, 9999, False], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 2], ['b', 1], ['p', 0, 900, False], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2]], 10], [[7, 'glue'], [7, 'penalty'], [5, 'glue'], [7, 'glue'], [8, 'penalty'], [5, 'end']])], [('regression: overflow trigger', [[['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['g', 1], ['b', 4], ['p', 0, 9999, False], ['g', 2], ['b', 6], ['p', 0, -5000, False], ['g', 1], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2]], 7], [[7, 'glue'], [4, 'glue'], [6, 'glue'], [1, 'forced'], [7, 'glue'], [4, 'penalty'], [6, 'penalty'], [5, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 6], ['g', 1], ['g', 1]], 8], [[6, 'penalty'], [5, 'glue'], [5, 'glue'], [6, 'penalty'], [6, 'forced'], [4, 'glue'], [4, 'glue'], [8, 'end']]), ('partial-repair probe', [[['b', 1], ['g', 2], ['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 1], ['b', 2], ['g', 2], ['b', 4], ['g', 2]], 12], [[9, 'penalty'], [7, 'penalty'], [10, 'glue'], [10, 'end']]), ('regression: overflow trigger', [[['b', 6], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 6], ['p', 0, 10000, False], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 3], ['g', 2], ['b', 2], ['p', 0, 900, False], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2]], 7], [[7, 'penalty'], [9, 'forced'], [10, 'glue'], [1, 'forced'], [7, 'penalty'], [2, 'penalty'], [6, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 2], ['b', 4], ['g', 2], ['b', 3], ['p', 0, -10000, False], ['g', 1], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 2], ['b', 2], ['p', 0, -10000, False], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['p', 0, 10000, False], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 2]], 18], [[15, 'forced'], [13, 'forced'], [14, 'penalty'], [5, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 5], ['g', 2], ['b', 2], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 2], ['b', 2], ['g', 1], ['g', 1], ['b', 7], ['p', 1, 50, True], ['g', 1]], 16], [[14, 'glue'], [15, 'glue'], [12, 'end']])], [('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('regression: overflow trigger', [[['b', 5], ['p', 1, 50, True], ['g', 2], ['b', 3], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 2], ['b', 7], ['g', 1], ['g', 1]], 17], [[13, 'glue'], [17, 'glue']]), ('partial-repair probe', [[['b', 5], ['p', 0, -5000, False], ['g', 2], ['b', 7], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['g', 1], ['b', 5], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['p', 1, 50, True], ['g', 1]], 12], [[5, 'penalty'], [7, 'glue'], [11, 'glue'], [7, 'glue'], [7, 'end']]), ('partial-repair probe', [[['b', 2], ['g', 1], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 6], ['p', 0, 900, False], ['g', 1], ['b', 7], ['g', 1], ['b', 7], ['g', 1]], 7], [[7, 'penalty'], [6, 'penalty'], [7, 'glue'], [7, 'glue']]), ('inhibited penalty', [[['b', 5], ['p', 0, 10000, False], ['b', 4], ['g', 1], ['b', 3]], 7], [[9, 'glue'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['g', 1], ['b', 5], ['g', 1], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 2], ['g', 1], ['b', 5], ['g', 1]], 12], [[10, 'glue'], [11, 'glue'], [6, 'end']]), ('control layout', [[['b', 6], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 5], ['p', 0, -10000, False], ['g', 1], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 2]], 14], [[12, 'glue'], [5, 'forced'], [8, 'end']])], [('regression: overflow trigger', [[['b', 5], ['g', 1], ['g', 1], ['b', 4], ['g', 1], ['b', 3], ['p', 0, -5000, False], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 2], ['b', 5], ['g', 2]], 11], [[11, 'glue'], [10, 'penalty'], [11, 'glue']]), ('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 5], ['g', 2], ['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 1], ['b', 4], ['g', 1]], 8], [[2, 'glue'], [8, 'glue'], [5, 'glue'], [5, 'penalty'], [8, 'penalty'], [5, 'end']]), ('regression: overflow trigger', [[['b', 2], ['g', 1], ['b', 4], ['g', 2], ['b', 1], ['p', 1, 50, True], ['g', 1], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 2], ['b', 6], ['g', 1]], 16], [[11, 'penalty'], [14, 'glue'], [16, 'end']]), ('partial-repair probe', [[['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['b', 6], ['p', 1, 50, True], ['g', 1], ['b', 5], ['p', 1, 50, True], ['g', 1], ['b', 2], ['g', 2], ['b', 3], ['g', 1], ['g', 1]], 17], [[10, 'glue'], [15, 'penalty'], [15, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('control layout', [[['b', 4], ['p', 1, 50, True], ['g', 2], ['b', 1], ['g', 1], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['p', 0, -10000, False], ['g', 1], ['b', 7], ['g', 2], ['b', 5], ['g', 1]], 10], [[7, 'glue'], [8, 'forced'], [7, 'glue'], [6, 'end']]), ('control layout', [[['b', 2], ['p', 1, 50, True], ['g', 1], ['b', 5], ['g', 2], ['b', 6], ['g', 2], ['b', 6], ['g', 1], ['b', 1], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 17], [[16, 'glue'], [11, 'end']])], [('regression: overflow trigger', [[['b', 6], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 2], ['b', 4], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1]], 12], [[12, 'penalty'], [12, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 3], ['g', 1], ['b', 6], ['g', 1], ['b', 1], ['g', 2], ['b', 3], ['p', 1, 50, True], ['g', 1], ['b', 3], ['g', 1]], 8], [[3, 'glue'], [8, 'glue'], [8, 'end']]), ('regression: overflow trigger', [[['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 6], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 1, 50, True], ['g', 1]], 9], [[11, 'glue'], [10, 'penalty']]), ('regression: overflow trigger', [[['b', 6], ['g', 1], ['b', 6], ['g', 2], ['b', 3], ['p', 0, 10000, False], ['g', 1], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 2], ['b', 4], ['g', 1], ['b', 2], ['g', 2], ['b', 5], ['g', 1], ['b', 2], ['g', 1], ['g', 1]], 13], [[13, 'glue'], [12, 'glue'], [12, 'glue']]), ('hyphen penalty taken', [[['b', 5], ['p', 1, 50, True], ['b', 4], ['g', 1], ['b', 3]], 7], [[6, 'penalty'], [4, 'glue'], [3, 'end']]), ('forced break', [[['b', 2], ['g', 1], ['b', 2], ['p', 0, -10000, False], ['b', 3]], 20], [[5, 'forced'], [3, 'end']]), ('control layout', [[['b', 3], ['g', 2], ['b', 3], ['g', 1], ['g', 1], ['b', 3], ['p', 0, 10000, False], ['g', 2], ['b', 1], ['g', 1], ['b', 3], ['g', 1]], 14], [[8, 'glue'], [11, 'end']]), ('control layout', [[['b', 7], ['g', 2], ['b', 7], ['g', 1], ['b', 7], ['g', 1], ['b', 1], ['p', 0, 10000, False], ['g', 1], ['b', 6], ['g', 2], ['b', 7], ['p', 1, 50, True], ['g', 2]], 10], [[7, 'glue'], [7, 'glue'], [7, 'glue'], [8, 'glue'], [9, 'end']])]]
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:
Lines that exactly fill the measure are broken early.

Input [items, width]; items are ["b",w], ["g",w] or ["p",w,cost,flag]. Legal breaks: glue immediately after a box; penalty with cost < 10000 (width counted only if broken there); cost <= -10000 forces a break. Discardable glue/penalties at a line start are dropped. First-fit: when the running width exceeds the measure, break at the last legal breakpoint. Return [[line width, break kind]] with kinds glue/penalty/forced/end.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('regression: last-line justification', [[8, 5, 2], 16, True, 3, 1, 5], [0, 11, 19]), ('regression: last-line justification', [[3, 9, 2, 2, 7], 43, True, 3, 1, 7], [0, 6, 18, 23, 28]), ('regression: last-line justification', [[5, 9], 15, True, 2, 1, 6], [0, 7]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[9, 3, 2], 15, False, 3, 3, 4], ['overfull']), ('control layout', [[7, 6, 5, 6, 2], 42, False, 2, 2, 3], [0, 9, 17, 24, 32])], [('regression: last-line justification', [[4, 5, 3, 6, 3], 41, True, 3, 3, 7], [0, 7, 15, 21, 30]), ('regression: last-line justification', [[9, 2, 8], 20, True, 2, 1, 3], [0, 11, 15]), ('regression: last-line justification', [[5, 9, 5, 7, 2], 32, True, 3, 3, 4], [0, 8, 20, 28, 38]), ('regression: last-line justification', [[7, 5, 4, 6, 9], 43, True, 2, 2, 4], [0, 9, 16, 22, 30]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 9, 9, 3, 8], 36, False, 3, 3, 7], ['overfull']), ('control layout', [[6, 4, 6, 4, 8], 51, False, 2, 2, 4], [0, 8, 14, 22, 28])], [('regression: last-line justification', [[7, 8, 3, 7, 9], 37, True, 2, 2, 5], [0, 9, 19, 24, 33]), ('regression: last-line justification', [[4, 5, 3, 4], 28, True, 3, 3, 6], [0, 7, 15, 21]), ('regression: last-line justification', [[9, 8, 3], 21, True, 2, 1, 5], [0, 11, 21]), ('regression: last-line justification', [[4, 8, 4, 8], 26, True, 2, 1, 5], [0, 6, 16, 22]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[4, 3, 2, 3, 5, 4], 55, True, 2, 2, 6], [0, 6, 11, 15, 20, 27]), ('control layout', [[7, 4], 17, False, 3, 1, 7], [0, 13])], [('regression: last-line justification', [[2, 8, 3, 2, 2, 4], 27, True, 2, 2, 6], [0, 4, 14, 19, 23, 27]), ('regression: last-line justification', [[7, 5], 14, True, 3, 2, 7], [0, 10]), ('regression: last-line justification', [[7, 3, 8], 21, True, 3, 3, 6], [0, 10, 16]), ('regression: last-line justification', [[5, 9, 5, 7, 2], 32, True, 3, 3, 4], [0, 8, 20, 28, 38]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[7, 2], 15, False, 3, 2, 4], [0, 10]), ('control layout', [[7, 3, 9, 5, 8], 40, False, 2, 2, 3], [0, 9, 14, 25, 32])], [('regression: last-line justification', [[2, 2], 4, True, 3, 2, 7], [0, 5]), ('regression: last-line justification', [[9, 8, 8, 7, 5], 53, True, 3, 3, 4], [0, 12, 23, 34, 44]), ('regression: last-line justification', [[5, 2, 2, 8, 9], 35, True, 3, 3, 4], [0, 8, 13, 18, 29]), ('regression: last-line justification', [[3, 8], 14, True, 2, 1, 6], [0, 5]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[4, 3, 9], 24, False, 2, 2, 6], [0, 8, 15]), ('control layout', [[4, 9, 9, 7], 45, False, 3, 1, 4], [0, 7, 19, 31])]]
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):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last and gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('regression: last-line justification', [[8, 5, 2], 16, True, 3, 1, 5], [0, 11, 19]), ('regression: last-line justification', [[3, 9, 2, 2, 7], 43, True, 3, 1, 7], [0, 6, 18, 23, 28]), ('regression: last-line justification', [[5, 9], 15, True, 2, 1, 6], [0, 7]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[9, 3, 2], 15, False, 3, 3, 4], ['overfull']), ('control layout', [[7, 6, 5, 6, 2], 42, False, 2, 2, 3], [0, 9, 17, 24, 32])], [('regression: last-line justification', [[4, 5, 3, 6, 3], 41, True, 3, 3, 7], [0, 7, 15, 21, 30]), ('regression: last-line justification', [[9, 2, 8], 20, True, 2, 1, 3], [0, 11, 15]), ('regression: last-line justification', [[5, 9, 5, 7, 2], 32, True, 3, 3, 4], [0, 8, 20, 28, 38]), ('regression: last-line justification', [[7, 5, 4, 6, 9], 43, True, 2, 2, 4], [0, 9, 16, 22, 30]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 9, 9, 3, 8], 36, False, 3, 3, 7], ['overfull']), ('control layout', [[6, 4, 6, 4, 8], 51, False, 2, 2, 4], [0, 8, 14, 22, 28])], [('regression: last-line justification', [[7, 8, 3, 7, 9], 37, True, 2, 2, 5], [0, 9, 19, 24, 33]), ('regression: last-line justification', [[4, 5, 3, 4], 28, True, 3, 3, 6], [0, 7, 15, 21]), ('regression: last-line justification', [[9, 8, 3], 21, True, 2, 1, 5], [0, 11, 21]), ('regression: last-line justification', [[4, 8, 4, 8], 26, True, 2, 1, 5], [0, 6, 16, 22]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[4, 3, 2, 3, 5, 4], 55, True, 2, 2, 6], [0, 6, 11, 15, 20, 27]), ('control layout', [[7, 4], 17, False, 3, 1, 7], [0, 13])], [('regression: last-line justification', [[2, 8, 3, 2, 2, 4], 27, True, 2, 2, 6], [0, 4, 14, 19, 23, 27]), ('regression: last-line justification', [[7, 5], 14, True, 3, 2, 7], [0, 10]), ('regression: last-line justification', [[7, 3, 8], 21, True, 3, 3, 6], [0, 10, 16]), ('regression: last-line justification', [[5, 9, 5, 7, 2], 32, True, 3, 3, 4], [0, 8, 20, 28, 38]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[7, 2], 15, False, 3, 2, 4], [0, 10]), ('control layout', [[7, 3, 9, 5, 8], 40, False, 2, 2, 3], [0, 9, 14, 25, 32])], [('regression: last-line justification', [[2, 2], 4, True, 3, 2, 7], [0, 5]), ('regression: last-line justification', [[9, 8, 8, 7, 5], 53, True, 3, 3, 4], [0, 12, 23, 34, 44]), ('regression: last-line justification', [[5, 2, 2, 8, 9], 35, True, 3, 3, 4], [0, 8, 13, 18, 29]), ('regression: last-line justification', [[3, 8], 14, True, 2, 1, 6], [0, 5]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[4, 3, 9], 24, False, 2, 2, 6], [0, 8, 15]), ('control layout', [[4, 9, 9, 7], 45, False, 3, 1, 4], [0, 7, 19, 31])]]
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:
The final line of a paragraph is stretched across the measure.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k < rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: remainder placement', [[7, 2, 8, 4, 4], 46, False, 2, 2, 6], [0, 12, 19, 32, 42]), ('regression: remainder placement', [[6, 4, 4, 7, 3, 5], 38, False, 3, 1, 6], [0, 7, 13, 19, 28, 33]), ('regression: remainder placement', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('regression: remainder placement', [[8, 9, 7, 2, 9, 4], 53, False, 3, 1, 7], [0, 10, 22, 32, 37, 49]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2, 9, 6, 3], 32, True, 3, 2, 5], [0, 5, 17, 26]), ('control layout', [[8, 3, 3, 2], 22, False, 3, 1, 4], [0, 10, 15, 20])], [('regression: remainder placement', [[2, 7, 5], 25, False, 2, 2, 6], [0, 7, 20]), ('regression: remainder placement', [[6, 8, 5], 24, False, 3, 1, 4], [0, 8, 19]), ('regression: remainder placement', [[3, 2, 5, 8], 31, False, 3, 2, 5], [0, 7, 13, 23]), ('regression: remainder placement', [[5, 9, 8, 2, 7, 4], 58, False, 3, 1, 7], [0, 9, 22, 35, 42, 54]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[2, 7, 7], 18, False, 2, 2, 3], ['overfull']), ('control layout', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26])], [('regression: remainder placement', [[2, 4, 6], 25, False, 3, 2, 7], [0, 8, 19]), ('regression: remainder placement', [[9, 8, 8, 9], 41, False, 2, 1, 4], [0, 11, 21, 32]), ('regression: remainder placement', [[4, 9, 9], 29, False, 2, 2, 4], [0, 7, 20]), ('regression: remainder placement', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[7, 9], 21, False, 3, 3, 7], [0, 12])], [('regression: remainder placement', [[5, 5, 4, 8, 7, 9], 51, False, 3, 1, 5], [0, 7, 14, 21, 32, 42]), ('regression: remainder placement', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('regression: remainder placement', [[8, 9, 3, 7, 9, 8], 51, False, 2, 1, 5], [0, 9, 19, 23, 32, 43]), ('regression: remainder placement', [[6, 3, 2], 14, False, 2, 1, 5], [0, 7, 12]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 6, 8, 6, 6, 9], 75, False, 2, 1, 6], [0, 4, 12, 22, 30, 38]), ('control layout', [[9, 3], 15, False, 2, 2, 5], [0, 12])], [('regression: remainder placement', [[7, 3, 6, 6, 7], 36, False, 2, 1, 6], [0, 8, 13, 21, 29]), ('regression: remainder placement', [[3, 9, 4, 9, 4, 4], 44, False, 2, 2, 3], [0, 5, 16, 22, 33, 40]), ('regression: remainder placement', [[8, 8, 5, 6], 34, False, 2, 2, 5], [0, 10, 20, 28]), ('regression: remainder placement', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[6, 3, 9, 8, 2], 48, False, 3, 3, 7], [0, 11, 19, 33, 46]), ('control layout', [[7, 2, 9, 2, 8], 29, False, 3, 3, 4], ['overfull'])]]
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, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k > gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: remainder placement', [[7, 2, 8, 4, 4], 46, False, 2, 2, 6], [0, 12, 19, 32, 42]), ('regression: remainder placement', [[6, 4, 4, 7, 3, 5], 38, False, 3, 1, 6], [0, 7, 13, 19, 28, 33]), ('regression: remainder placement', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('regression: remainder placement', [[8, 9, 7, 2, 9, 4], 53, False, 3, 1, 7], [0, 10, 22, 32, 37, 49]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2, 9, 6, 3], 32, True, 3, 2, 5], [0, 5, 17, 26]), ('control layout', [[8, 3, 3, 2], 22, False, 3, 1, 4], [0, 10, 15, 20])], [('regression: remainder placement', [[2, 7, 5], 25, False, 2, 2, 6], [0, 7, 20]), ('regression: remainder placement', [[6, 8, 5], 24, False, 3, 1, 4], [0, 8, 19]), ('regression: remainder placement', [[3, 2, 5, 8], 31, False, 3, 2, 5], [0, 7, 13, 23]), ('regression: remainder placement', [[5, 9, 8, 2, 7, 4], 58, False, 3, 1, 7], [0, 9, 22, 35, 42, 54]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[2, 7, 7], 18, False, 2, 2, 3], ['overfull']), ('control layout', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26])], [('regression: remainder placement', [[2, 4, 6], 25, False, 3, 2, 7], [0, 8, 19]), ('regression: remainder placement', [[9, 8, 8, 9], 41, False, 2, 1, 4], [0, 11, 21, 32]), ('regression: remainder placement', [[4, 9, 9], 29, False, 2, 2, 4], [0, 7, 20]), ('regression: remainder placement', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[7, 9], 21, False, 3, 3, 7], [0, 12])], [('regression: remainder placement', [[5, 5, 4, 8, 7, 9], 51, False, 3, 1, 5], [0, 7, 14, 21, 32, 42]), ('regression: remainder placement', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('regression: remainder placement', [[8, 9, 3, 7, 9, 8], 51, False, 2, 1, 5], [0, 9, 19, 23, 32, 43]), ('regression: remainder placement', [[6, 3, 2], 14, False, 2, 1, 5], [0, 7, 12]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 6, 8, 6, 6, 9], 75, False, 2, 1, 6], [0, 4, 12, 22, 30, 38]), ('control layout', [[9, 3], 15, False, 2, 2, 5], [0, 12])], [('regression: remainder placement', [[7, 3, 6, 6, 7], 36, False, 2, 1, 6], [0, 8, 13, 21, 29]), ('regression: remainder placement', [[3, 9, 4, 9, 4, 4], 44, False, 2, 2, 3], [0, 5, 16, 22, 33, 40]), ('regression: remainder placement', [[8, 8, 5, 6], 34, False, 2, 2, 5], [0, 10, 20, 28]), ('regression: remainder placement', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[6, 3, 9, 8, 2], 48, False, 3, 3, 7], [0, 11, 19, 33, 46]), ('control layout', [[7, 2, 9, 2, 8], 29, False, 3, 3, 4], ['overfull'])]]
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:
Extra spacing units cluster on the left side of the line.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per <= lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('regression: minimum space check', [[5, 2], 10, False, 3, 3, 7], [0, 8]), ('partial-repair probe', [[7, 2, 5, 6, 9], 33, False, 2, 2, 3], ['overfull']), ('partial-repair probe', [[2, 5, 2], 12, False, 2, 2, 4], ['overfull']), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[5, 7, 9, 9, 7], 53, False, 2, 2, 5], [0, 9, 20, 33, 46]), ('control layout', [[8, 7, 3], 35, True, 2, 1, 6], [0, 10, 19])], [('regression: minimum space check', [[4, 6, 3], 20, False, 3, 3, 7], [0, 7, 17]), ('regression: minimum space check', [[8, 2], 12, False, 3, 2, 5], [0, 10]), ('partial-repair probe', [[7, 8, 8, 5, 8, 3], 41, False, 2, 1, 6], ['overfull']), ('partial-repair probe', [[9, 6, 3, 5], 28, False, 2, 2, 5], ['overfull']), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[6, 3], 10, True, 3, 3, 4], [0, 9]), ('control layout', [[4], 7, False, 2, 1, 3], [0])], [('regression: minimum space check', [[5, 7, 5, 6, 9, 5], 43, False, 3, 1, 6], [0, 6, 14, 20, 27, 38]), ('regression: minimum space check', [[6, 4, 4, 7, 3, 5], 38, False, 3, 1, 6], [0, 7, 13, 19, 28, 33]), ('partial-repair probe', [[6, 5, 9], 23, False, 2, 2, 3], ['overfull']), ('partial-repair probe', [[8, 6, 4], 22, False, 3, 3, 5], ['overfull']), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[7], 10, False, 2, 1, 4], [0]), ('control layout', [[7], 10, False, 3, 3, 7], [0])], [('regression: minimum space check', [[4, 6, 3], 20, False, 3, 3, 7], [0, 7, 17]), ('regression: minimum space check', [[2, 2, 5, 5, 2], 24, False, 3, 2, 7], [0, 4, 8, 15, 22]), ('partial-repair probe', [[8, 5, 3, 2, 5, 9], 35, False, 2, 1, 3], ['overfull']), ('partial-repair probe', [[5, 7, 8, 5, 5], 31, False, 3, 1, 5], ['overfull']), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[4, 7, 7, 4, 6, 3], 50, False, 2, 2, 3], [0, 6, 15, 24, 30, 38]), ('control layout', [[5, 6, 7], 24, False, 3, 2, 7], [0, 8, 17])], [('regression: minimum space check', [[6, 3, 2], 14, False, 2, 1, 5], [0, 7, 12]), ('regression: minimum space check', [[9, 5], 17, False, 3, 3, 5], [0, 12]), ('partial-repair probe', [[4, 8, 8], 23, False, 2, 2, 5], ['overfull']), ('partial-repair probe', [[7, 2, 5, 6, 9], 33, False, 2, 2, 3], ['overfull']), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[9], 9, False, 3, 3, 6], [0]), ('control layout', [[3, 9, 2, 3], 26, False, 3, 2, 5], [0, 6, 18, 23])]]
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, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if space < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('regression: minimum space check', [[5, 2], 10, False, 3, 3, 7], [0, 8]), ('partial-repair probe', [[7, 2, 5, 6, 9], 33, False, 2, 2, 3], ['overfull']), ('partial-repair probe', [[2, 5, 2], 12, False, 2, 2, 4], ['overfull']), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[5, 7, 9, 9, 7], 53, False, 2, 2, 5], [0, 9, 20, 33, 46]), ('control layout', [[8, 7, 3], 35, True, 2, 1, 6], [0, 10, 19])], [('regression: minimum space check', [[4, 6, 3], 20, False, 3, 3, 7], [0, 7, 17]), ('regression: minimum space check', [[8, 2], 12, False, 3, 2, 5], [0, 10]), ('partial-repair probe', [[7, 8, 8, 5, 8, 3], 41, False, 2, 1, 6], ['overfull']), ('partial-repair probe', [[9, 6, 3, 5], 28, False, 2, 2, 5], ['overfull']), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[6, 3], 10, True, 3, 3, 4], [0, 9]), ('control layout', [[4], 7, False, 2, 1, 3], [0])], [('regression: minimum space check', [[5, 7, 5, 6, 9, 5], 43, False, 3, 1, 6], [0, 6, 14, 20, 27, 38]), ('regression: minimum space check', [[6, 4, 4, 7, 3, 5], 38, False, 3, 1, 6], [0, 7, 13, 19, 28, 33]), ('partial-repair probe', [[6, 5, 9], 23, False, 2, 2, 3], ['overfull']), ('partial-repair probe', [[8, 6, 4], 22, False, 3, 3, 5], ['overfull']), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[7], 10, False, 2, 1, 4], [0]), ('control layout', [[7], 10, False, 3, 3, 7], [0])], [('regression: minimum space check', [[4, 6, 3], 20, False, 3, 3, 7], [0, 7, 17]), ('regression: minimum space check', [[2, 2, 5, 5, 2], 24, False, 3, 2, 7], [0, 4, 8, 15, 22]), ('partial-repair probe', [[8, 5, 3, 2, 5, 9], 35, False, 2, 1, 3], ['overfull']), ('partial-repair probe', [[5, 7, 8, 5, 5], 31, False, 3, 1, 5], ['overfull']), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[4, 7, 7, 4, 6, 3], 50, False, 2, 2, 3], [0, 6, 15, 24, 30, 38]), ('control layout', [[5, 6, 7], 24, False, 3, 2, 7], [0, 8, 17])], [('regression: minimum space check', [[6, 3, 2], 14, False, 2, 1, 5], [0, 7, 12]), ('regression: minimum space check', [[9, 5], 17, False, 3, 3, 5], [0, 12]), ('partial-repair probe', [[4, 8, 8], 23, False, 2, 2, 5], ['overfull']), ('partial-repair probe', [[7, 2, 5, 6, 9], 33, False, 2, 2, 3], ['overfull']), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[9], 9, False, 3, 3, 6], [0]), ('control layout', [[3, 9, 2, 3], 26, False, 3, 2, 5], [0, 6, 18, 23])]]
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:
Lines set at exactly the minimum space are rejected as overfull.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: maximum space with remainder', [[3, 5, 4, 9, 8, 2], 67, False, 3, 3, 7], [0, 6, 14, 21, 33, 44]), ('regression: maximum space with remainder', [[4, 3, 7, 3, 7], 42, False, 2, 2, 4], [0, 6, 11, 20, 25]), ('partial-repair probe', [[7, 2, 8, 7, 9], 55, False, 3, 3, 6], [0, 12, 19, 33, 46]), ('partial-repair probe', [[4, 5, 8, 9, 5, 6], 55, False, 3, 2, 4], [0, 7, 15, 27, 40, 49]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 9, 6, 5, 6, 5], 53, True, 3, 3, 4], [0, 5, 17, 26, 34, 43]), ('control layout', [[9], 9, False, 3, 3, 6], [0])], [('regression: maximum space with remainder', [[7, 3, 4, 2, 9], 51, False, 3, 3, 6], [0, 10, 16, 23, 28]), ('regression: maximum space with remainder', [[4, 3, 7, 3, 7], 42, False, 2, 2, 4], [0, 6, 11, 20, 25]), ('partial-repair probe', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('partial-repair probe', [[7, 2, 8, 7, 9], 55, False, 3, 3, 6], [0, 12, 19, 33, 46]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('control layout', [[8, 9, 3, 7, 9, 8], 51, False, 2, 1, 5], [0, 9, 19, 23, 32, 43])], [('regression: maximum space with remainder', [[3, 5, 4, 9, 8, 2], 67, False, 3, 3, 7], [0, 6, 14, 21, 33, 44]), ('regression: maximum space with remainder', [[9, 8, 7, 8, 9], 59, False, 2, 1, 4], [0, 11, 21, 30, 40]), ('partial-repair probe', [[3, 7, 7, 8, 9], 41, False, 2, 1, 3], [0, 4, 13, 22, 32]), ('partial-repair probe', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[5, 5, 5, 3, 7], 32, False, 3, 2, 6], ['overfull']), ('control layout', [[2, 2, 5, 5, 2], 24, False, 3, 2, 7], [0, 4, 8, 15, 22])], [('regression: maximum space with remainder', [[8, 7, 6, 6, 6], 52, False, 3, 2, 4], [0, 11, 21, 30, 39]), ('regression: maximum space with remainder', [[7, 3, 4, 2, 9], 51, False, 3, 3, 6], [0, 10, 16, 23, 28]), ('partial-repair probe', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('partial-repair probe', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[7, 7, 7, 6, 2], 37, False, 3, 1, 5], [0, 9, 18, 27, 35]), ('control layout', [[5, 5, 5, 3, 7], 32, False, 3, 2, 6], ['overfull'])], [('regression: maximum space with remainder', [[6, 3, 4, 3], 30, False, 2, 1, 4], [0, 8, 13, 19]), ('regression: maximum space with remainder', [[8, 8, 6, 7], 43, False, 3, 1, 4], [0, 11, 22, 31]), ('partial-repair probe', [[2, 4, 9, 5], 31, False, 3, 2, 4], [0, 5, 13, 26]), ('partial-repair probe', [[2, 2, 3, 9], 30, False, 3, 2, 5], [0, 6, 13, 21]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[7, 7, 7, 6, 2], 37, False, 3, 1, 5], [0, 9, 18, 27, 35]), ('control layout', [[2, 7, 9, 4, 8], 39, False, 3, 3, 7], ['overfull'])]]
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, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + rem > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: maximum space with remainder', [[3, 5, 4, 9, 8, 2], 67, False, 3, 3, 7], [0, 6, 14, 21, 33, 44]), ('regression: maximum space with remainder', [[4, 3, 7, 3, 7], 42, False, 2, 2, 4], [0, 6, 11, 20, 25]), ('partial-repair probe', [[7, 2, 8, 7, 9], 55, False, 3, 3, 6], [0, 12, 19, 33, 46]), ('partial-repair probe', [[4, 5, 8, 9, 5, 6], 55, False, 3, 2, 4], [0, 7, 15, 27, 40, 49]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 9, 6, 5, 6, 5], 53, True, 3, 3, 4], [0, 5, 17, 26, 34, 43]), ('control layout', [[9], 9, False, 3, 3, 6], [0])], [('regression: maximum space with remainder', [[7, 3, 4, 2, 9], 51, False, 3, 3, 6], [0, 10, 16, 23, 28]), ('regression: maximum space with remainder', [[4, 3, 7, 3, 7], 42, False, 2, 2, 4], [0, 6, 11, 20, 25]), ('partial-repair probe', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('partial-repair probe', [[7, 2, 8, 7, 9], 55, False, 3, 3, 6], [0, 12, 19, 33, 46]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[8, 7, 2, 8, 4, 4], 56, False, 3, 2, 7], [0, 12, 23, 30, 43, 52]), ('control layout', [[8, 9, 3, 7, 9, 8], 51, False, 2, 1, 5], [0, 9, 19, 23, 32, 43])], [('regression: maximum space with remainder', [[3, 5, 4, 9, 8, 2], 67, False, 3, 3, 7], [0, 6, 14, 21, 33, 44]), ('regression: maximum space with remainder', [[9, 8, 7, 8, 9], 59, False, 2, 1, 4], [0, 11, 21, 30, 40]), ('partial-repair probe', [[3, 7, 7, 8, 9], 41, False, 2, 1, 3], [0, 4, 13, 22, 32]), ('partial-repair probe', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[5, 5, 5, 3, 7], 32, False, 3, 2, 6], ['overfull']), ('control layout', [[2, 2, 5, 5, 2], 24, False, 3, 2, 7], [0, 4, 8, 15, 22])], [('regression: maximum space with remainder', [[8, 7, 6, 6, 6], 52, False, 3, 2, 4], [0, 11, 21, 30, 39]), ('regression: maximum space with remainder', [[7, 3, 4, 2, 9], 51, False, 3, 3, 6], [0, 10, 16, 23, 28]), ('partial-repair probe', [[8, 9, 2, 3, 5], 46, False, 2, 1, 5], [0, 12, 26, 33, 41]), ('partial-repair probe', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[7, 7, 7, 6, 2], 37, False, 3, 1, 5], [0, 9, 18, 27, 35]), ('control layout', [[5, 5, 5, 3, 7], 32, False, 3, 2, 6], ['overfull'])], [('regression: maximum space with remainder', [[6, 3, 4, 3], 30, False, 2, 1, 4], [0, 8, 13, 19]), ('regression: maximum space with remainder', [[8, 8, 6, 7], 43, False, 3, 1, 4], [0, 11, 22, 31]), ('partial-repair probe', [[2, 4, 9, 5], 31, False, 3, 2, 4], [0, 5, 13, 26]), ('partial-repair probe', [[2, 2, 3, 9], 30, False, 3, 2, 5], [0, 6, 13, 21]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('control layout', [[7, 7, 7, 6, 2], 37, False, 3, 1, 5], [0, 9, 18, 27, 35]), ('control layout', [[2, 7, 9, 4, 8], 39, False, 3, 3, 7], ['overfull'])]]
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:
Lines whose widest gap exceeds the maximum stay justified.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + lo
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('regression: ragged fallback spacing', [[4, 7, 7, 7], 32, True, 2, 1, 3], [0, 6, 15, 24]), ('regression: ragged fallback spacing', [[3, 5], 14, False, 3, 2, 4], [0, 6]), ('partial-repair probe', [[3, 9], 17, False, 3, 3, 4], [0, 6]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[9, 9, 9, 5, 4, 4], 48, False, 3, 3, 4], ['overfull']), ('control layout', [[6], 7, False, 2, 2, 4], [0])], [('regression: ragged fallback spacing', [[7, 9, 6], 27, True, 3, 1, 4], [0, 10, 22]), ('regression: ragged fallback spacing', [[8, 5, 5, 8, 5], 57, True, 3, 2, 5], [0, 11, 19, 27, 38]), ('regression: ragged fallback spacing', [[6, 6], 22, False, 3, 1, 7], [0, 9]), ('regression: ragged fallback spacing', [[3, 3, 4, 4, 5], 38, False, 2, 1, 3], [0, 5, 10, 16, 22]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[7, 2, 5, 3], 21, False, 2, 1, 5], [0, 8, 11, 18]), ('control layout', [[3, 3], 8, False, 3, 1, 5], [0, 5])], [('regression: ragged fallback spacing', [[7, 6], 18, False, 2, 1, 3], [0, 9]), ('regression: ragged fallback spacing', [[6, 3, 4, 3], 30, False, 2, 1, 4], [0, 8, 13, 19]), ('partial-repair probe', [[7, 4, 2, 7, 4], 25, True, 3, 3, 6], [0, 10, 17, 22, 32]), ('regression: ragged fallback spacing', [[7, 4], 16, False, 2, 1, 3], [0, 9]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 8, 3, 8], 27, False, 3, 3, 6], ['overfull']), ('control layout', [[8], 9, False, 2, 2, 4], [0])], [('regression: ragged fallback spacing', [[6, 6], 22, False, 3, 1, 7], [0, 9]), ('regression: ragged fallback spacing', [[4, 7], 18, False, 3, 2, 6], [0, 7]), ('partial-repair probe', [[7, 8, 3, 7, 9], 37, True, 2, 2, 5], [0, 9, 19, 24, 33]), ('regression: ragged fallback spacing', [[8, 4], 18, False, 3, 2, 5], [0, 11]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[3, 7, 7, 8, 9], 41, False, 2, 1, 3], [0, 4, 13, 22, 32]), ('control layout', [[6, 3, 2, 7, 8, 2], 47, False, 3, 3, 6], [0, 9, 16, 22, 33, 45])], [('regression: ragged fallback spacing', [[5, 5, 6, 4, 2], 50, False, 2, 1, 5], [0, 7, 14, 22, 28]), ('regression: ragged fallback spacing', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26]), ('regression: ragged fallback spacing', [[7, 2, 9, 2, 4, 6], 59, True, 2, 1, 4], [0, 9, 13, 24, 28, 34]), ('regression: ragged fallback spacing', [[6, 3, 8], 28, False, 3, 2, 5], [0, 9, 15]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[6, 4, 8, 8, 2], 31, False, 3, 1, 4], ['overfull']), ('control layout', [[5, 8, 2, 5, 5], 30, False, 3, 1, 5], [0, 6, 15, 18, 25])]]
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, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + hi
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words)
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('regression: ragged fallback spacing', [[4, 7, 7, 7], 32, True, 2, 1, 3], [0, 6, 15, 24]), ('regression: ragged fallback spacing', [[3, 5], 14, False, 3, 2, 4], [0, 6]), ('partial-repair probe', [[3, 9], 17, False, 3, 3, 4], [0, 6]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[9, 9, 9, 5, 4, 4], 48, False, 3, 3, 4], ['overfull']), ('control layout', [[6], 7, False, 2, 2, 4], [0])], [('regression: ragged fallback spacing', [[7, 9, 6], 27, True, 3, 1, 4], [0, 10, 22]), ('regression: ragged fallback spacing', [[8, 5, 5, 8, 5], 57, True, 3, 2, 5], [0, 11, 19, 27, 38]), ('regression: ragged fallback spacing', [[6, 6], 22, False, 3, 1, 7], [0, 9]), ('regression: ragged fallback spacing', [[3, 3, 4, 4, 5], 38, False, 2, 1, 3], [0, 5, 10, 16, 22]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[7, 2, 5, 3], 21, False, 2, 1, 5], [0, 8, 11, 18]), ('control layout', [[3, 3], 8, False, 3, 1, 5], [0, 5])], [('regression: ragged fallback spacing', [[7, 6], 18, False, 2, 1, 3], [0, 9]), ('regression: ragged fallback spacing', [[6, 3, 4, 3], 30, False, 2, 1, 4], [0, 8, 13, 19]), ('partial-repair probe', [[7, 4, 2, 7, 4], 25, True, 3, 3, 6], [0, 10, 17, 22, 32]), ('regression: ragged fallback spacing', [[7, 4], 16, False, 2, 1, 3], [0, 9]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[2, 8, 3, 8], 27, False, 3, 3, 6], ['overfull']), ('control layout', [[8], 9, False, 2, 2, 4], [0])], [('regression: ragged fallback spacing', [[6, 6], 22, False, 3, 1, 7], [0, 9]), ('regression: ragged fallback spacing', [[4, 7], 18, False, 3, 2, 6], [0, 7]), ('partial-repair probe', [[7, 8, 3, 7, 9], 37, True, 2, 2, 5], [0, 9, 19, 24, 33]), ('regression: ragged fallback spacing', [[8, 4], 18, False, 3, 2, 5], [0, 11]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[3, 7, 7, 8, 9], 41, False, 2, 1, 3], [0, 4, 13, 22, 32]), ('control layout', [[6, 3, 2, 7, 8, 2], 47, False, 3, 3, 6], [0, 9, 16, 22, 33, 45])], [('regression: ragged fallback spacing', [[5, 5, 6, 4, 2], 50, False, 2, 1, 5], [0, 7, 14, 22, 28]), ('regression: ragged fallback spacing', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26]), ('regression: ragged fallback spacing', [[7, 2, 9, 2, 4, 6], 59, True, 2, 1, 4], [0, 9, 13, 24, 28, 34]), ('regression: ragged fallback spacing', [[6, 3, 8], 28, False, 3, 2, 5], [0, 9, 15]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[6, 4, 8, 8, 2], 31, False, 3, 1, 4], ['overfull']), ('control layout', [[5, 8, 2, 5, 5], 30, False, 3, 1, 5], [0, 6, 15, 18, 25])]]
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:
Ragged lines are set with the wrong space width.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


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

N = 1
observations = []
def solve(x):
    words, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words) - sp * gaps
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('regression: space budget', [[9, 8, 5, 8, 9], 51, False, 2, 1, 4], [0, 12, 23, 31, 42]), ('regression: space budget', [[5, 3, 6, 5, 6, 4], 49, False, 3, 3, 5], [0, 9, 16, 26, 35, 45]), ('partial-repair probe', [[6, 2, 9], 19, False, 2, 2, 3], ['overfull']), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[3, 9, 3, 2, 3, 5], 49, True, 2, 2, 6], [0, 5, 16, 21, 25, 30]), ('control layout', [[5], 7, False, 3, 3, 7], [0])], [('regression: space budget', [[8, 7, 6, 6, 6], 52, False, 3, 2, 4], [0, 11, 21, 30, 39]), ('regression: space budget', [[4, 8], 20, False, 3, 1, 5], [0, 7]), ('partial-repair probe', [[2, 6, 2, 7], 22, False, 2, 2, 5], ['overfull']), ('regression: space budget', [[6, 8, 2, 8, 3], 42, False, 3, 1, 5], [0, 9, 21, 27, 39]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[6], 6, False, 2, 1, 4], [0]), ('control layout', [[2, 5, 3, 7, 9, 7], 44, True, 3, 3, 7], [0, 5, 13, 19, 29, 41])], [('regression: space budget', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('regression: space budget', [[3, 6, 3], 26, False, 2, 2, 5], [0, 5, 13]), ('regression: space budget', [[5, 6, 7, 8], 38, False, 2, 2, 5], [0, 9, 19, 30]), ('regression: space budget', [[3, 9, 2, 3], 26, False, 3, 2, 5], [0, 6, 18, 23]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[6], 7, False, 2, 2, 4], [0]), ('control layout', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26])], [('regression: space budget', [[3, 5, 9, 6, 8], 39, False, 2, 2, 5], [0, 5, 12, 23, 31]), ('regression: space budget', [[5, 6, 7, 6, 3], 47, False, 3, 1, 5], [0, 10, 21, 33, 44]), ('regression: space budget', [[2, 2, 4, 5], 19, False, 2, 2, 4], [0, 4, 8, 14]), ('regression: space budget', [[2, 6, 9, 2], 28, False, 2, 2, 3], [0, 5, 14, 26]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2, 5, 3, 7, 9, 7], 44, True, 3, 3, 7], [0, 5, 13, 19, 29, 41]), ('control layout', [[2, 2], 4, True, 3, 2, 7], [0, 5])], [('regression: space budget', [[5, 4, 3, 2], 23, False, 2, 2, 5], [0, 8, 15, 21]), ('regression: space budget', [[2, 6, 8, 6, 6, 9], 75, False, 2, 1, 6], [0, 4, 12, 22, 30, 38]), ('regression: space budget', [[2, 4, 6, 4, 7, 2], 43, False, 2, 1, 6], [0, 5, 12, 22, 30, 41]), ('regression: space budget', [[5, 7, 5, 6, 9, 5], 43, False, 3, 1, 6], [0, 6, 14, 20, 27, 38]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2], 6, False, 2, 1, 4], [0]), ('control layout', [[2], 6, False, 3, 1, 5], [0])]]
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, target, is_last, sp, lo, hi = x
    n = len(words)
    gaps = n - 1
    def natural():
        pos, xx = [], 0
        for w in words:
            pos.append(xx)
            xx += w + sp
        return pos
    if is_last or gaps == 0:
        return natural()
    space = target - sum(words[:-1])
    per, rem = divmod(space, gaps)
    if per < lo:
        return ['overfull']
    if per + (1 if rem else 0) > hi:
        return natural()
    pos, xx = [], 0
    for k, w in enumerate(words):
        pos.append(xx)
        if k < gaps:
            xx += w + per + (1 if k >= gaps - rem else 0)
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('regression: space budget', [[9, 8, 5, 8, 9], 51, False, 2, 1, 4], [0, 12, 23, 31, 42]), ('regression: space budget', [[5, 3, 6, 5, 6, 4], 49, False, 3, 3, 5], [0, 9, 16, 26, 35, 45]), ('partial-repair probe', [[6, 2, 9], 19, False, 2, 2, 3], ['overfull']), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[3, 9, 3, 2, 3, 5], 49, True, 2, 2, 6], [0, 5, 16, 21, 25, 30]), ('control layout', [[5], 7, False, 3, 3, 7], [0])], [('regression: space budget', [[8, 7, 6, 6, 6], 52, False, 3, 2, 4], [0, 11, 21, 30, 39]), ('regression: space budget', [[4, 8], 20, False, 3, 1, 5], [0, 7]), ('partial-repair probe', [[2, 6, 2, 7], 22, False, 2, 2, 5], ['overfull']), ('regression: space budget', [[6, 8, 2, 8, 3], 42, False, 3, 1, 5], [0, 9, 21, 27, 39]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('exactly minimum share', [[3, 3, 3], 11, False, 2, 1, 4], [0, 4, 8]), ('control layout', [[6], 6, False, 2, 1, 4], [0]), ('control layout', [[2, 5, 3, 7, 9, 7], 44, True, 3, 3, 7], [0, 5, 13, 19, 29, 41])], [('regression: space budget', [[6, 8, 6, 8, 7], 49, False, 2, 2, 4], [0, 9, 20, 30, 42]), ('regression: space budget', [[3, 6, 3], 26, False, 2, 2, 5], [0, 5, 13]), ('regression: space budget', [[5, 6, 7, 8], 38, False, 2, 2, 5], [0, 9, 19, 30]), ('regression: space budget', [[3, 9, 2, 3], 26, False, 3, 2, 5], [0, 6, 18, 23]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('control layout', [[6], 7, False, 2, 2, 4], [0]), ('control layout', [[9, 8, 3, 8], 40, False, 2, 1, 3], [0, 11, 21, 26])], [('regression: space budget', [[3, 5, 9, 6, 8], 39, False, 2, 2, 5], [0, 5, 12, 23, 31]), ('regression: space budget', [[5, 6, 7, 6, 3], 47, False, 3, 1, 5], [0, 10, 21, 33, 44]), ('regression: space budget', [[2, 2, 4, 5], 19, False, 2, 2, 4], [0, 4, 8, 14]), ('regression: space budget', [[2, 6, 9, 2], 28, False, 2, 2, 3], [0, 5, 14, 26]), ('single word line', [[7], 20, False, 2, 1, 4], [0]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2, 5, 3, 7, 9, 7], 44, True, 3, 3, 7], [0, 5, 13, 19, 29, 41]), ('control layout', [[2, 2], 4, True, 3, 2, 7], [0, 5])], [('regression: space budget', [[5, 4, 3, 2], 23, False, 2, 2, 5], [0, 8, 15, 21]), ('regression: space budget', [[2, 6, 8, 6, 6, 9], 75, False, 2, 1, 6], [0, 4, 12, 22, 30, 38]), ('regression: space budget', [[2, 4, 6, 4, 7, 2], 43, False, 2, 1, 6], [0, 5, 12, 22, 30, 41]), ('regression: space budget', [[5, 7, 5, 6, 9, 5], 43, False, 3, 1, 6], [0, 6, 14, 20, 27, 38]), ('last line ragged', [[3, 4, 5], 20, True, 2, 1, 6], [0, 5, 11]), ('remainder goes to right gaps', [[3, 4, 5, 2], 20, False, 2, 1, 4], [0, 5, 11, 18]), ('control layout', [[2], 6, False, 2, 1, 4], [0]), ('control layout', [[2], 6, False, 3, 1, 5], [0])]]
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:
Justified lines come out too wide.

Input [word widths, target width, is_last, natural space, min space, max space]. Last lines and single-word lines are set ragged with natural spaces. Otherwise distribute target-sum(words) over the gaps: equal share with the remainder units added to the rightmost gaps; a share below min space is ["overfull"]; if any gap would exceed max space fall back to ragged. Return word x positions.

split: open-access


prompt:
One line too many is narrowed around the drop cap.

Input [word widths, width, cap lines, cap width, gap, indent]. With a drop cap its first letter moves into the cap (first word loses one unit) and the first cap-lines lines are narrowed by cap width + gap; the first-line indent applies only without a cap. Greedy fill with unit spaces; a word too wide for an empty line is set alone. Return [[words on line, used width]].

split: open-access


prompt:
Text beside the drop cap touches the cap.

Input [word widths, width, cap lines, cap width, gap, indent]. With a drop cap its first letter moves into the cap (first word loses one unit) and the first cap-lines lines are narrowed by cap width + gap; the first-line indent applies only without a cap. Greedy fill with unit spaces; a word too wide for an empty line is set alone. Return [[words on line, used width]].

split: open-access


prompt:
Paragraphs with a drop cap are also indented.

Input [word widths, width, cap lines, cap width, gap, indent]. With a drop cap its first letter moves into the cap (first word loses one unit) and the first cap-lines lines are narrowed by cap width + gap; the first-line indent applies only without a cap. Greedy fill with unit spaces; a word too wide for an empty line is set alone. Return [[words on line, used width]].

split: open-access


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

N = 1
observations = []
def solve(x):
    words, width, cap_lines, cap_width, gap, indent = x
    lens = list(words)
    if cap_lines > 0:
        lens[0] = lens[0]
    def avail(li):
        base = width
        if li < cap_lines:
            base -= cap_width + gap
        elif cap_lines == 0 and li == 0:
            base -= indent
        return base
    lines = []
    cur = []
    used = 0
    for w in lens:
        li = len(lines)
        need = w if not cur else used + 1 + w
        if need <= avail(li) or not cur:
            cur.append(w)
            used = need
        else:
            lines.append([len(cur), used])
            cur = [w]
            used = w
    if cur:
        lines.append([len(cur), used])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('regression: initial letter consumption', [[7, 1, 4, 6, 4, 3, 7, 5], 13, 2, 5, 2, 3], [[1, 6], [2, 6], [2, 11], [2, 11], [1, 5]]), ('partial-repair probe', [[7, 1, 8, 5], 16, 0, 5, 1, 3], [[2, 9], [2, 14]]), ('partial-repair probe', [[1, 8, 8, 5, 8, 1, 2, 5], 17, 0, 2, 1, 3], [[2, 10], [2, 14], [3, 13], [1, 5]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('partial-repair probe', [[5, 2, 6, 6, 2, 6, 3, 3, 5, 3], 16, 0, 2, 1, 3], [[2, 8], [3, 16], [3, 14], [2, 9]]), ('partial-repair probe', [[6, 6, 8, 8, 8, 2, 3], 15, 0, 5, 1, 4], [[1, 6], [2, 15], [1, 8], [3, 15]]), ('partial-repair probe', [[1, 2, 6, 7, 1, 8], 20, 0, 3, 2, 2], [[3, 11], [3, 18]])], [('regression: initial letter consumption', [[8, 1, 6, 4, 1, 7, 7], 24, 2, 5, 2, 1], [[3, 16], [3, 14], [1, 7]]), ('regression: initial letter consumption', [[1, 2, 7, 6, 5, 2, 3], 17, 3, 5, 1, 3], [[3, 11], [1, 6], [2, 8], [1, 3]]), ('partial-repair probe', [[1, 8, 7, 5, 7, 8], 15, 0, 2, 2, 3], [[2, 10], [2, 13], [1, 7], [1, 8]]), ('partial-repair probe', [[2, 3, 3, 1, 7, 5, 6, 1, 3, 3, 5], 14, 0, 3, 1, 2], [[4, 12], [2, 13], [3, 12], [2, 9]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('regression: initial letter consumption', [[3, 4, 3, 1, 5, 7, 5, 6, 6, 5, 5], 19, 2, 4, 2, 2], [[4, 13], [2, 13], [3, 19], [2, 11]]), ('partial-repair probe', [[6, 8, 2, 2, 5, 4, 5, 7], 24, 0, 2, 1, 2], [[4, 21], [4, 24]])], [('regression: initial letter consumption', [[2, 6, 7, 8, 2, 8, 5, 5, 1, 1, 5], 12, 3, 2, 1, 1], [[2, 8], [1, 7], [1, 8], [2, 11], [2, 11], [3, 9]]), ('regression: initial letter consumption', [[7, 2, 3, 8, 2, 8, 7], 22, 2, 5, 1, 1], [[3, 13], [2, 11], [2, 16]]), ('partial-repair probe', [[1, 6, 4, 2, 2, 2, 8], 15, 0, 4, 1, 3], [[2, 8], [4, 13], [1, 8]]), ('partial-repair probe', [[8, 1, 7, 5, 5, 4, 4, 8, 7], 22, 0, 5, 1, 2], [[3, 18], [4, 21], [2, 16]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('partial-repair probe', [[3, 7, 4, 7], 24, 0, 2, 2, 4], [[3, 16], [1, 7]]), ('partial-repair probe', [[8, 2, 3, 5, 8, 1, 2], 12, 0, 4, 1, 1], [[2, 11], [2, 9], [2, 10], [1, 2]])], [('regression: initial letter consumption', [[2, 6, 7, 8, 1, 2, 5, 6, 8], 21, 2, 2, 2, 4], [[3, 16], [3, 13], [3, 21]]), ('regression: initial letter consumption', [[7, 6, 8, 6, 7, 6, 3, 5, 3, 6, 4], 13, 2, 4, 1, 1], [[1, 6], [1, 6], [1, 8], [1, 6], [1, 7], [2, 10], [2, 9], [2, 11]]), ('partial-repair probe', [[7, 4, 4, 1], 21, 0, 2, 2, 3], [[3, 17], [1, 1]]), ('partial-repair probe', [[3, 2, 8, 1, 5, 6, 1, 5, 8], 16, 0, 4, 2, 2], [[2, 6], [3, 16], [3, 14], [1, 8]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('partial-repair probe', [[7, 6, 7, 4, 5, 3, 3, 5, 3, 5], 23, 0, 3, 2, 4], [[2, 14], [4, 22], [4, 19]]), ('regression: initial letter consumption', [[5, 4, 1, 4, 5, 5, 2, 7], 21, 3, 2, 1, 2], [[4, 16], [3, 14], [1, 7]])], [('regression: initial letter consumption', [[3, 1, 5, 1, 6], 22, 2, 5, 2, 4], [[4, 12], [1, 6]]), ('regression: initial letter consumption', [[6, 6, 3, 1, 6], 19, 2, 5, 1, 3], [[2, 12], [3, 12]]), ('partial-repair probe', [[3, 5, 6, 1, 6, 8, 2, 6, 1], 15, 0, 2, 2, 3], [[2, 9], [3, 15], [2, 11], [2, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 7, 6, 1, 1, 8, 3, 4], 23, 0, 4, 1, 2], [[6, 21], [5, 23], [1, 4]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('regression: initial letter consumption', [[4, 3, 6, 1, 3, 3, 4, 6], 15, 3, 4, 1, 3], [[2, 7], [2, 8], [2, 7], [2, 11]]), ('regression: initial letter consumption', [[1, 5, 6, 6, 3, 7], 22, 2, 4, 2, 4], [[3, 13], [2, 10], [1, 7]])]]
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, cap_lines, cap_width, gap, indent = x
    lens = list(words)
    if cap_lines >= 0:
        lens[0] = lens[0] - 1
    def avail(li):
        base = width
        if li < cap_lines:
            base -= cap_width + gap
        elif cap_lines == 0 and li == 0:
            base -= indent
        return base
    lines = []
    cur = []
    used = 0
    for w in lens:
        li = len(lines)
        need = w if not cur else used + 1 + w
        if need <= avail(li) or not cur:
            cur.append(w)
            used = need
        else:
            lines.append([len(cur), used])
            cur = [w]
            used = w
    if cur:
        lines.append([len(cur), used])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('regression: initial letter consumption', [[7, 1, 4, 6, 4, 3, 7, 5], 13, 2, 5, 2, 3], [[1, 6], [2, 6], [2, 11], [2, 11], [1, 5]]), ('partial-repair probe', [[7, 1, 8, 5], 16, 0, 5, 1, 3], [[2, 9], [2, 14]]), ('partial-repair probe', [[1, 8, 8, 5, 8, 1, 2, 5], 17, 0, 2, 1, 3], [[2, 10], [2, 14], [3, 13], [1, 5]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('partial-repair probe', [[5, 2, 6, 6, 2, 6, 3, 3, 5, 3], 16, 0, 2, 1, 3], [[2, 8], [3, 16], [3, 14], [2, 9]]), ('partial-repair probe', [[6, 6, 8, 8, 8, 2, 3], 15, 0, 5, 1, 4], [[1, 6], [2, 15], [1, 8], [3, 15]]), ('partial-repair probe', [[1, 2, 6, 7, 1, 8], 20, 0, 3, 2, 2], [[3, 11], [3, 18]])], [('regression: initial letter consumption', [[8, 1, 6, 4, 1, 7, 7], 24, 2, 5, 2, 1], [[3, 16], [3, 14], [1, 7]]), ('regression: initial letter consumption', [[1, 2, 7, 6, 5, 2, 3], 17, 3, 5, 1, 3], [[3, 11], [1, 6], [2, 8], [1, 3]]), ('partial-repair probe', [[1, 8, 7, 5, 7, 8], 15, 0, 2, 2, 3], [[2, 10], [2, 13], [1, 7], [1, 8]]), ('partial-repair probe', [[2, 3, 3, 1, 7, 5, 6, 1, 3, 3, 5], 14, 0, 3, 1, 2], [[4, 12], [2, 13], [3, 12], [2, 9]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('regression: initial letter consumption', [[3, 4, 3, 1, 5, 7, 5, 6, 6, 5, 5], 19, 2, 4, 2, 2], [[4, 13], [2, 13], [3, 19], [2, 11]]), ('partial-repair probe', [[6, 8, 2, 2, 5, 4, 5, 7], 24, 0, 2, 1, 2], [[4, 21], [4, 24]])], [('regression: initial letter consumption', [[2, 6, 7, 8, 2, 8, 5, 5, 1, 1, 5], 12, 3, 2, 1, 1], [[2, 8], [1, 7], [1, 8], [2, 11], [2, 11], [3, 9]]), ('regression: initial letter consumption', [[7, 2, 3, 8, 2, 8, 7], 22, 2, 5, 1, 1], [[3, 13], [2, 11], [2, 16]]), ('partial-repair probe', [[1, 6, 4, 2, 2, 2, 8], 15, 0, 4, 1, 3], [[2, 8], [4, 13], [1, 8]]), ('partial-repair probe', [[8, 1, 7, 5, 5, 4, 4, 8, 7], 22, 0, 5, 1, 2], [[3, 18], [4, 21], [2, 16]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('partial-repair probe', [[3, 7, 4, 7], 24, 0, 2, 2, 4], [[3, 16], [1, 7]]), ('partial-repair probe', [[8, 2, 3, 5, 8, 1, 2], 12, 0, 4, 1, 1], [[2, 11], [2, 9], [2, 10], [1, 2]])], [('regression: initial letter consumption', [[2, 6, 7, 8, 1, 2, 5, 6, 8], 21, 2, 2, 2, 4], [[3, 16], [3, 13], [3, 21]]), ('regression: initial letter consumption', [[7, 6, 8, 6, 7, 6, 3, 5, 3, 6, 4], 13, 2, 4, 1, 1], [[1, 6], [1, 6], [1, 8], [1, 6], [1, 7], [2, 10], [2, 9], [2, 11]]), ('partial-repair probe', [[7, 4, 4, 1], 21, 0, 2, 2, 3], [[3, 17], [1, 1]]), ('partial-repair probe', [[3, 2, 8, 1, 5, 6, 1, 5, 8], 16, 0, 4, 2, 2], [[2, 6], [3, 16], [3, 14], [1, 8]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('partial-repair probe', [[7, 6, 7, 4, 5, 3, 3, 5, 3, 5], 23, 0, 3, 2, 4], [[2, 14], [4, 22], [4, 19]]), ('regression: initial letter consumption', [[5, 4, 1, 4, 5, 5, 2, 7], 21, 3, 2, 1, 2], [[4, 16], [3, 14], [1, 7]])], [('regression: initial letter consumption', [[3, 1, 5, 1, 6], 22, 2, 5, 2, 4], [[4, 12], [1, 6]]), ('regression: initial letter consumption', [[6, 6, 3, 1, 6], 19, 2, 5, 1, 3], [[2, 12], [3, 12]]), ('partial-repair probe', [[3, 5, 6, 1, 6, 8, 2, 6, 1], 15, 0, 2, 2, 3], [[2, 9], [3, 15], [2, 11], [2, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 7, 6, 1, 1, 8, 3, 4], 23, 0, 4, 1, 2], [[6, 21], [5, 23], [1, 4]]), ('three-line drop cap', [[5, 3, 4, 6, 2, 5, 4, 3], 14, 3, 3, 1, 2], [[2, 8], [1, 4], [2, 9], [3, 14]]), ('no cap uses indent', [[5, 3, 4, 6, 2], 12, 0, 3, 1, 3], [[2, 9], [2, 11], [1, 2]]), ('regression: initial letter consumption', [[4, 3, 6, 1, 3, 3, 4, 6], 15, 3, 4, 1, 3], [[2, 7], [2, 8], [2, 7], [2, 11]]), ('regression: initial letter consumption', [[1, 5, 6, 6, 3, 7], 22, 2, 4, 2, 4], [[3, 13], [2, 10], [1, 7]])]]
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:
The first line measures the initial letter twice.

Input [word widths, width, cap lines, cap width, gap, indent]. With a drop cap its first letter moves into the cap (first word loses one unit) and the first cap-lines lines are narrowed by cap width + gap; the first-line indent applies only without a cap. Greedy fill with unit spaces; a word too wide for an empty line is set alone. Return [[words on line, used width]].

split: open-access


prompt:
Lines that exactly fill their shaped width are broken early.

Input [word widths, width, cap lines, cap width, gap, indent]. With a drop cap its first letter moves into the cap (first word loses one unit) and the first cap-lines lines are narrowed by cap width + gap; the first-line indent applies only without a cap. Greedy fill with unit spaces; a word too wide for an empty line is set alone. Return [[words on line, used width]].

split: open-access