{"abstract":"Every line measures one space too wide and breaks too early.","category":"Typography line breaking","checks":8,"contract":"Input [word widths, [space, stretch, shrink] per gap, line width, line penalty]. A line i..j has gaps=j-i-1. The last line has zero badness when not overfull. Other lines use ratio shortfall/(stretch*gaps) or /(shrink*gaps); zero stretch with slack or compression past shrink is infeasible; badness=min(10000, floor(100|r|^3+1/2)) and must be <=1000. Fitness 0 tight (r<-1/2), 1 decent (r<=1/2), 2 loose (r<=1), 3 very loose; last line decent. Demerits (lp+b)^2 plus 3000 when adjacent fitness classes differ by more than 1, starting from decent. Return [min total demerits, break list] (ties: first found) or [\"infeasible\"].","contract_signature":"x","evaluation_group":"w2-typography-line-breaking-total-fit-demerits","failed_approach":"Reserving a trailing space unit on non-final lines still narrows every line.","family":"w2-typography-line-breaking-total-fit-demerits-interword-gap-count","id":"FA-79891","implementations":{"attempt":{"sha256":"85f48fab426641b474822ea2288b99d21e9156c125791249374529165522a91d","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * gaps + (1 if j < n else 0)\n        short = width - nat\n        if j == n and short >= 0:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if abs(fit - pfit) > 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: interword gap count', [[4, 1, 7, 4, 5, 5, 4], [3, 3, 1], 23, 50], [8900, [4, 7]]), ('regression: interword gap count', [[2, 1, 3, 5, 5], [3, 1, 0], 20, 50], [5000, [4, 5]]), ('regression: interword gap count', [[1, 3, 1, 2, 2], [3, 2, 1], 10, 10], [629, [3, 5]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[7, 6, 5, 6, 3, 1, 3], [1, 3, 2], 9, 10], ['infeasible']), ('control layout', [[7, 7, 3, 4, 5, 3, 6], [2, 1, 1], 9, 10], ['infeasible'])], [('regression: interword gap count', [[1, 7, 5, 5, 2], [2, 2, 0], 17, 10], [200, [3, 5]]), ('regression: interword gap count', [[4, 3, 1, 4, 3, 5], [2, 1, 2], 24, 10], [244, [5, 6]]), ('regression: interword gap count', [[2, 4, 1, 6, 1, 2, 3, 1], [2, 1, 0], 10, 50], [753000, [2, 4, 7, 8]]), ('regression: interword gap count', [[2, 5, 3, 6, 5], [2, 1, 1], 12, 50], [45000, [3, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[6, 5, 3, 7, 5, 2], [3, 3, 0], 11, 10], ['infeasible']), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]])], [('regression: interword gap count', [[6, 5, 7, 7, 4, 7], [3, 1, 1], 23, 50], [7938, [3, 6]]), ('regression: interword gap count', [[2, 5, 7, 6, 7, 6, 6], [1, 3, 0], 15, 10], ['infeasible']), ('regression: interword gap count', [[3, 5, 7, 2, 2, 1], [2, 3, 1], 11, 1], [27, [2, 4, 6]]), ('regression: interword gap count', [[2, 5, 4, 7, 4, 1, 3], [1, 2, 1], 18, 10], [12200, [4, 7]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[5, 4, 4], [2, 1, 2], 20, 50], [2500, [3]]), ('control layout', [[2, 7, 6, 5, 5], [3, 3, 1], 12, 50], ['infeasible'])], [('regression: interword gap count', [[1, 7, 4, 1, 6, 5, 2, 4], [2, 3, 0], 23, 50], [5981, [4, 8]]), ('regression: interword gap count', [[4, 1, 4, 3, 5, 3, 6], [3, 3, 0], 23, 1], [5, [4, 7]]), ('regression: interword gap count', [[5, 4, 5, 2], [3, 2, 0], 16, 10], [662200, [2, 4]]), ('regression: interword gap count', [[5, 2, 3, 6, 7], [2, 2, 1], 24, 1], [26, [4, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[6, 7, 3, 4, 3, 5], [3, 1, 1], 9, 10], ['infeasible']), ('control layout', [[7, 1, 2], [1, 1, 0], 22, 50], [2500, [3]])], [('regression: interword gap count', [[2, 5, 4, 7, 4, 1, 3], [1, 2, 1], 18, 10], [12200, [4, 7]]), ('regression: interword gap count', [[7, 3, 1, 4, 5, 7, 2, 1], [1, 1, 2], 12, 50], [27500, [2, 5, 8]]), ('regression: interword gap count', [[7, 1, 4, 6, 6, 2, 3], [3, 2, 1], 12, 50], [32938, [2, 4, 6, 7]]), ('regression: interword gap count', [[7, 3, 7, 4, 7, 3, 1, 5], [3, 1, 2], 19, 10], [12344, [3, 6, 8]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[7, 4, 7, 2, 4, 2, 1], [2, 1, 0], 17, 10], ['infeasible']), ('control layout', [[4, 1, 1], [1, 3, 2], 15, 50], [2500, [3]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"a722d9eca1393e7980b32fae6ca1cd6718a5bfbfdc4c54daa09eb8111158b38f","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport math\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    words, glue, width, lp = x\n    sp, st, sh = glue\n    n = len(words)\n    def rate(i, j):\n        gaps = j - i - 1\n        nat = sum(words[i:j]) + sp * (j - i)\n        short = width - nat\n        if j == n and short >= 0:\n            return 0, 1\n        if short > 0:\n            if st * gaps == 0:\n                return None\n            r = Fraction(short, st * gaps)\n        elif short < 0:\n            if -short > sh * gaps:\n                return None\n            r = Fraction(short, sh * gaps)\n        else:\n            r = Fraction(0)\n        b = min(10000, math.floor(100 * abs(r) ** 3 + Fraction(1, 2)))\n        if b > 1000:\n            return None\n        fit = 0 if r < Fraction(-1, 2) else 1 if r <= Fraction(1, 2) else 2 if r <= 1 else 3\n        return b, fit\n    best = {(0, 1): (0, [])}\n    for j in range(1, n + 1):\n        for i in range(j):\n            rated = rate(i, j)\n            if rated is None:\n                continue\n            b, fit = rated\n            for (pos, pfit), (dem, brk) in sorted(best.items()):\n                if pos != i:\n                    continue\n                d = dem + (lp + b) ** 2\n                if abs(fit - pfit) > 1:\n                    d += 3000\n                key = (j, fit)\n                if key not in best or d < best[key][0]:\n                    best[key] = (d, brk + [j])\n    finals = [v for (pos, f), v in best.items() if pos == n]\n    if not finals:\n        return ['infeasible']\n    d, brk = min(finals)\n    return [d, brk]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('regression: interword gap count', [[4, 1, 7, 4, 5, 5, 4], [3, 3, 1], 23, 50], [8900, [4, 7]]), ('regression: interword gap count', [[2, 1, 3, 5, 5], [3, 1, 0], 20, 50], [5000, [4, 5]]), ('regression: interword gap count', [[1, 3, 1, 2, 2], [3, 2, 1], 10, 10], [629, [3, 5]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[7, 6, 5, 6, 3, 1, 3], [1, 3, 2], 9, 10], ['infeasible']), ('control layout', [[7, 7, 3, 4, 5, 3, 6], [2, 1, 1], 9, 10], ['infeasible'])], [('regression: interword gap count', [[1, 7, 5, 5, 2], [2, 2, 0], 17, 10], [200, [3, 5]]), ('regression: interword gap count', [[4, 3, 1, 4, 3, 5], [2, 1, 2], 24, 10], [244, [5, 6]]), ('regression: interword gap count', [[2, 4, 1, 6, 1, 2, 3, 1], [2, 1, 0], 10, 50], [753000, [2, 4, 7, 8]]), ('regression: interword gap count', [[2, 5, 3, 6, 5], [2, 1, 1], 12, 50], [45000, [3, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('tight then loose lines', [[3, 3, 3, 3, 3, 3, 3], [2, 2, 1], 11, 1], [20403, [3, 6, 7]]), ('control layout', [[6, 5, 3, 7, 5, 2], [3, 3, 0], 11, 10], ['infeasible']), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]])], [('regression: interword gap count', [[6, 5, 7, 7, 4, 7], [3, 1, 1], 23, 50], [7938, [3, 6]]), ('regression: interword gap count', [[2, 5, 7, 6, 7, 6, 6], [1, 3, 0], 15, 10], ['infeasible']), ('regression: interword gap count', [[3, 5, 7, 2, 2, 1], [2, 3, 1], 11, 1], [27, [2, 4, 6]]), ('regression: interword gap count', [[2, 5, 4, 7, 4, 1, 3], [1, 2, 1], 18, 10], [12200, [4, 7]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('control layout', [[5, 4, 4], [2, 1, 2], 20, 50], [2500, [3]]), ('control layout', [[2, 7, 6, 5, 5], [3, 3, 1], 12, 50], ['infeasible'])], [('regression: interword gap count', [[1, 7, 4, 1, 6, 5, 2, 4], [2, 3, 0], 23, 50], [5981, [4, 8]]), ('regression: interword gap count', [[4, 1, 4, 3, 5, 3, 6], [3, 3, 0], 23, 1], [5, [4, 7]]), ('regression: interword gap count', [[5, 4, 5, 2], [3, 2, 0], 16, 10], [662200, [2, 4]]), ('regression: interword gap count', [[5, 2, 3, 6, 7], [2, 2, 1], 24, 1], [26, [4, 5]]), ('last line overfull', [[5, 5, 5], [1, 1, 0], 9, 10], ['infeasible']), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('control layout', [[6, 7, 3, 4, 3, 5], [3, 1, 1], 9, 10], ['infeasible']), ('control layout', [[7, 1, 2], [1, 1, 0], 22, 50], [2500, [3]])], [('regression: interword gap count', [[2, 5, 4, 7, 4, 1, 3], [1, 2, 1], 18, 10], [12200, [4, 7]]), ('regression: interword gap count', [[7, 3, 1, 4, 5, 7, 2, 1], [1, 1, 2], 12, 50], [27500, [2, 5, 8]]), ('regression: interword gap count', [[7, 1, 4, 6, 6, 2, 3], [3, 2, 1], 12, 50], [32938, [2, 4, 6, 7]]), ('regression: interword gap count', [[7, 3, 7, 4, 7, 3, 1, 5], [3, 1, 2], 19, 10], [12344, [3, 6, 8]]), ('two-line paragraph with loose first line', [[4, 5, 3, 6], [2, 2, 1], 14, 10], [12200, [3, 4]]), ('single word paragraph', [[7], [2, 2, 1], 10, 10], [100, [1]]), ('control layout', [[7, 4, 7, 2, 4, 2, 1], [2, 1, 0], 17, 10], ['infeasible']), ('control layout', [[4, 1, 1], [1, 3, 2], 15, 50], [2500, [3]])]]\nfor label, args, expected in fixtures[N - 1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"A deterministic toy typesetting model with integer widths and a stipulated rule set; it does not claim conformance to any engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-typography-line-breaking-total-fit-demerits-interword-gap-count","generated_at":"2026-09-29T14:49:48.851254+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Line breaking decides where paragraphs wrap on screen and in print; a wrong decision point shifts every following line.","root_cause":"Natural width counts one space per word instead of one per gap.","sha256":"91ae4c87ef3e3912842ce4e9c8f051847e1c6a861e05bd0e88c6bdb39f88ed51","title":"Total-fit paragraph demerits: interword gap count · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":43.487,"exit_code":1,"observations":[{"actual":[12200,[2,4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":false},{"actual":[11816,[3,6,7]],"check":"regression: interword gap count","expected":[8900,[4,7]],"passed":false},{"actual":["infeasible"],"check":"regression: interword gap count","expected":[5000,[4,5]],"passed":false},{"actual":[12200,[3,5]],"check":"regression: interword gap count","expected":[629,[3,5]],"passed":false},{"actual":[100,[1]],"check":"single word paragraph","expected":[100,[1]],"passed":true},{"actual":[30604,[2,4,6,7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":false},{"actual":["infeasible"],"check":"control layout","expected":["infeasible"],"passed":true},{"actual":["infeasible"],"check":"control layout","expected":["infeasible"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [12200, [2, 4]], \"expected\": [12200, [3, 4]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [11816, [3, 6, 7]], \"expected\": [8900, [4, 7]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [\"infeasible\"], \"expected\": [5000, [4, 5]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [12200, [3, 5]], \"expected\": [629, [3, 5]], \"passed\": false}, {\"check\": \"single word paragraph\", \"actual\": [100, [1]], \"expected\": [100, [1]], \"passed\": true}, {\"check\": \"tight then loose lines\", \"actual\": [30604, [2, 4, 6, 7]], \"expected\": [20403, [3, 6, 7]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":46.108,"exit_code":1,"observations":[{"actual":[629,[2,4]],"check":"two-line paragraph with loose first line","expected":[12200,[3,4]],"passed":false},{"actual":[7916,[3,6,7]],"check":"regression: interword gap count","expected":[8900,[4,7]],"passed":false},{"actual":["infeasible"],"check":"regression: interword gap count","expected":[5000,[4,5]],"passed":false},{"actual":[729,[2,4,5]],"check":"regression: interword gap count","expected":[629,[3,5]],"passed":false},{"actual":[100,[1]],"check":"single word paragraph","expected":[100,[1]],"passed":true},{"actual":[589,[2,4,6,7]],"check":"tight then loose lines","expected":[20403,[3,6,7]],"passed":false},{"actual":["infeasible"],"check":"control layout","expected":["infeasible"],"passed":true},{"actual":["infeasible"],"check":"control layout","expected":["infeasible"],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"two-line paragraph with loose first line\", \"actual\": [629, [2, 4]], \"expected\": [12200, [3, 4]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [7916, [3, 6, 7]], \"expected\": [8900, [4, 7]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [\"infeasible\"], \"expected\": [5000, [4, 5]], \"passed\": false}, {\"check\": \"regression: interword gap count\", \"actual\": [729, [2, 4, 5]], \"expected\": [629, [3, 5]], \"passed\": false}, {\"check\": \"single word paragraph\", \"actual\": [100, [1]], \"expected\": [100, [1]], \"passed\": true}, {\"check\": \"tight then loose lines\", \"actual\": [589, [2, 4, 6, 7]], \"expected\": [20403, [3, 6, 7]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [\"infeasible\"], \"expected\": [\"infeasible\"], \"passed\": true}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}