{"abstract":"Lines show characters from other lines after wrapping RTL text.","category":"Bidirectional text layout","checks":8,"contract":"Input [paragraph levels, classes, paragraph level, line lengths]. For each logical line: reset trailing WS to the paragraph level, then reorder that line alone by level reversal (lowest odd level of the line). Return per line the paragraph indices in visual order.","evaluation_group":"w2-bidirectional-text-layout-per-line-reordering","failed_approach":"Sorting each line by paragraph-wide visual position skips the per-line whitespace reset.","family":"w2-bidirectional-text-layout-per-line-reordering-paragraph-wide-reordering","id":"FA-80711","implementations":{"attempt":{"sha256":"1a19049f081d539e4fe25e9d711f0759424f93fc4f66e51f1b3c019898e88f4d","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, classes, para, line_lengths = x\n    out = []\n    start = 0\n    glob = reorder(levels)\n    gpos = {i: v for v, i in enumerate(glob)}\n    for ln in line_lengths:\n        idx = list(range(start, start + ln))\n        lv = [levels[i] for i in idx]\n        j = ln - 1\n        while j >= 0 and classes[idx[j]] == 'WS':\n            lv[j] = para\n            j -= 1\n        local = reorder(lv)\n        out.append(sorted(idx, key=lambda i: gpos[i]))\n        start += ln\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]\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":"f777832387f700e5339dc366d9957bac4003a3736ed2d21bd7a6d3113893662d","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, classes, para, line_lengths = x\n    out = []\n    start = 0\n    glob = reorder(levels)\n    for ln in line_lengths:\n        idx = list(range(start, start + ln))\n        lv = [levels[i] for i in idx]\n        j = ln - 1\n        while j >= 0 and classes[idx[j]] == 'WS':\n            lv[j] = para\n            j -= 1\n        local = reorder(lv)\n        out.append(glob[start:start + ln])\n        start += ln\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]\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"},"fixed":{"sha256":"72a2c5670b84b717f573f9509e3f1960e3c76e2c5743ca7337cafdf3f4a9ee44","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    def reorder(lv):\n        vis = list(range(len(lv)))\n        odd = [l for l in lv if l % 2 == 1]\n        if not odd:\n            return vis\n        for lev in range(max(lv), min(odd) - 1, -1):\n            i = 0\n            while i < len(vis):\n                if lv[vis[i]] >= lev:\n                    j = i\n                    while j < len(vis) and lv[vis[j]] >= lev:\n                        j += 1\n                    vis[i:j] = vis[i:j][::-1]\n                    i = j\n                else:\n                    i += 1\n        return vis\n    \n    levels, classes, para, line_lengths = x\n    out = []\n    start = 0\n    for ln in line_lengths:\n        idx = list(range(start, start + ln))\n        lv = [levels[i] for i in idx]\n        j = ln - 1\n        while j >= 0 and classes[idx[j]] == 'WS':\n            lv[j] = para\n            j -= 1\n        local = reorder(lv)\n        out.append([idx[v] for v in local])\n        start += ln\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 0, 0, 0], ['L', 'L', 'L', 'WS', 'L', 'WS', 'R', 'R', 'ON', 'WS', 'R', 'WS', 'R', 'WS'], 0, [1, 4, 2, 3, 4]], [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('regression: paragraph-wide reordering', [[1, 0, 0, 0, 0, 0], ['R', 'L', 'WS', 'WS', 'WS', 'WS'], 1, [3, 2, 1]], [[0, 1, 2], [4, 3], [5]]), ('control layout', [[2, 2, 2, 0], ['WS', 'ON', 'WS', 'L'], 0, [1, 2, 1]], [[0], [1, 2], [3]]), ('control layout', [[2, 2, 2, 0, 0, 1], ['R', 'R', 'R', 'L', 'R', 'R'], 0, [3, 2, 1]], [[0, 1, 2], [3, 4], [5]]), ('control layout', [[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], ['WS', 'L', 'R', 'L', 'R', 'L', 'WS', 'R', 'WS', 'ON', 'WS', 'L', 'R', 'WS'], 0, [5, 5, 2, 2]], [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]]), ('control layout', [[1, 1, 0, 0, 0], ['WS', 'WS', 'ON', 'R', 'R'], 0, [4, 1]], [[1, 0, 2, 3], [4]])], [('regression: paragraph-wide reordering', [[4, 4, 2, 2, 2, 1, 3], ['R', 'L', 'L', 'R', 'L', 'R', 'ON'], 0, [3, 2, 2]], [[0, 1, 2], [3, 4], [6, 5]]), ('regression: paragraph-wide reordering', [[0, 0, 3, 3, 3, 1, 1, 2, 0, 0], ['ON', 'R', 'L', 'ON', 'R', 'R', 'WS', 'L', 'R', 'WS'], 0, [5, 5]], [[0, 1, 4, 3, 2], [7, 6, 5, 8, 9]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 2, 2, 2, 1], ['R', 'WS', 'WS', 'WS', 'WS', 'ON', 'L'], 1, [4, 2, 1]], [[3, 2, 1, 0], [4, 5], [6]]), ('regression: paragraph-wide reordering', [[1, 1, 4, 1, 1, 2, 4, 4, 4, 3, 3], ['R', 'L', 'ON', 'WS', 'R', 'L', 'R', 'R', 'WS', 'R', 'WS'], 0, [4, 3, 2, 1, 1]], [[2, 1, 0, 3], [5, 6, 4], [7, 8], [9], [10]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]]), ('control layout', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[1, 1, 1], ['WS', 'WS', 'R'], 1, [3]], [[2, 1, 0]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 1, 1, 1, 1, 3], ['WS', 'R', 'WS', 'WS', 'R', 'WS', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 2, 1, 0], [7, 6, 5], [8]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'L', 'ON', 'L', 'WS', 'WS', 'WS'], 1, [2, 5, 1]], [[1, 0], [6, 5, 4, 3, 2], [7]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2], ['R', 'R', 'WS', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 5, 3]], [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]]), ('regression: paragraph-wide reordering', [[0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 1], ['WS', 'WS', 'L', 'R', 'R', 'R', 'L', 'WS', 'WS', 'WS', 'R', 'WS', 'L', 'ON'], 1, [1, 3, 1, 2, 5, 1, 1]], [[0], [1, 2, 3], [4], [6, 5], [7, 11, 8, 9, 10], [12], [13]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'WS', 'R'], 1, [3]], [[0, 1, 2]]), ('control layout', [[0, 0, 3, 0, 0, 0, 0, 0], ['WS', 'R', 'WS', 'WS', 'ON', 'WS', 'R', 'L'], 0, [2, 5, 1]], [[0, 1], [2, 3, 4, 5, 6], [7]]), ('control layout', [[3, 2], ['WS', 'ON'], 0, [2]], [[0, 1]])], [('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 3, 2, 1, 1, 2, 2], ['ON', 'L', 'L', 'R', 'ON', 'WS', 'WS', 'R', 'L', 'R', 'L'], 1, [1, 3, 2, 4, 1]], [[0], [3, 2, 1], [5, 4], [9, 8, 7, 6], [10]]), ('regression: paragraph-wide reordering', [[3, 2, 2, 2, 2, 1, 1, 1, 4, 4], ['R', 'WS', 'R', 'R', 'WS', 'WS', 'L', 'R', 'ON', 'L'], 1, [2, 3, 2, 2, 1]], [[1, 0], [4, 2, 3], [6, 5], [8, 7], [9]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 2, 3, 3, 1], ['R', 'L', 'WS', 'WS', 'R', 'WS', 'WS'], 1, [4, 3]], [[3, 2, 0, 1], [6, 5, 4]]), ('regression: paragraph-wide reordering', [[2, 4, 4, 3, 3, 3, 3], ['WS', 'ON', 'R', 'ON', 'WS', 'R', 'WS'], 1, [5, 2]], [[4, 0, 3, 1, 2], [6, 5]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[0, 0, 0, 0, 0, 0, 2], ['L', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [1, 3, 1, 2]], [[0], [1, 2, 3], [4], [5, 6]]), ('control layout', [[2, 2, 2, 2], ['L', 'L', 'ON', 'R'], 0, [2, 2]], [[0, 1], [2, 3]]), ('control layout', [[2, 0, 0, 0, 0, 1], ['L', 'ON', 'WS', 'R', 'L', 'R'], 1, [5, 1]], [[0, 1, 2, 3, 4], [5]])], [('regression: paragraph-wide reordering', [[3, 3, 3, 3, 2, 2, 2, 0, 2, 2, 2, 2, 1, 1], ['WS', 'L', 'R', 'ON', 'L', 'R', 'WS', 'R', 'WS', 'R', 'WS', 'R', 'R', 'L'], 1, [3, 5, 5, 1]], [[2, 1, 0], [3, 4, 5, 6, 7], [12, 8, 9, 10, 11], [13]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 1, 3, 0, 1], ['R', 'L', 'R', 'R', 'WS', 'L', 'R'], 0, [4, 1, 1, 1]], [[3, 2, 1, 0], [4], [5], [6]]), ('regression: paragraph-wide reordering', [[2, 2, 2, 1, 2, 4, 4, 4, 1, 1, 1, 1, 2, 2], ['R', 'L', 'R', 'WS', 'R', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'WS', 'ON', 'L'], 0, [2, 3, 2, 4, 3]], [[0, 1], [4, 3, 2], [5, 6], [9, 8, 7, 10], [12, 13, 11]]), ('regression: paragraph-wide reordering', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['WS', 'L', 'R', 'L', 'WS', 'ON', 'WS', 'R', 'L', 'L', 'WS', 'L', 'WS'], 0, [4, 3, 4, 2]], [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]]), ('RTL run split across lines', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'WS', 'R', 'R', 'R'], 0, [3, 3]], [[1, 0, 2], [5, 4, 3]]), ('control layout', [[2, 2, 2], ['WS', 'L', 'ON'], 1, [3]], [[0, 1, 2]]), ('control layout', [[1, 1, 1], ['ON', 'R', 'R'], 0, [3]], [[2, 1, 0]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 3], ['ON', 'WS', 'WS', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 1, 2, 2, 1, 1]], [[0], [1], [2, 3], [4, 5], [6], [7]])]]\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 bidi model over stipulated class labels and integer levels; it is inspired by, but does not claim conformance to, any published algorithm. 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-bidirectional-text-layout-per-line-reordering-paragraph-wide-reordering","generated_at":"2026-09-29T14:49:56.327682+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Mixed right-to-left and left-to-right text must resolve levels and visual order exactly, or words, numbers and carets land in the wrong place.","repair":"Break lines in logical order and reorder each line separately.","root_cause":"The whole paragraph is reordered first and then cut into lines visually.","sha256":"1d415205b529b50aad9579e67e4765c8df2a43e3358c97be5bb3fd1aeb38b1d0","title":"Per-line visual reordering: paragraph-wide reordering · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":38.916,"exit_code":1,"observations":[{"actual":[[2,1,0],[5,4,3]],"check":"RTL run split across lines","expected":[[1,0,2],[5,4,3]],"passed":false},{"actual":[[0],[4,3,2,1],[6,5],[9,8,7],[10,11,12,13]],"check":"regression: paragraph-wide reordering","expected":[[0],[4,3,2,1],[6,5],[8,7,9],[10,11,12,13]],"passed":false},{"actual":[[3,2,1,0],[4,5,6],[10,9,8,7],[12,11]],"check":"regression: paragraph-wide reordering","expected":[[3,2,1,0],[4,5,6],[9,8,7,10],[11,12]],"passed":false},{"actual":[[0,1,2],[3,4],[5]],"check":"regression: paragraph-wide reordering","expected":[[0,1,2],[4,3],[5]],"passed":false},{"actual":[[0],[1,2],[3]],"check":"control layout","expected":[[0],[1,2],[3]],"passed":true},{"actual":[[0,1,2],[3,4],[5]],"check":"control layout","expected":[[0,1,2],[3,4],[5]],"passed":true},{"actual":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"check":"control layout","expected":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"passed":true},{"actual":[[1,0,2,3],[4]],"check":"control layout","expected":[[1,0,2,3],[4]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"RTL run split across lines\", \"actual\": [[2, 1, 0], [5, 4, 3]], \"expected\": [[1, 0, 2], [5, 4, 3]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[0], [4, 3, 2, 1], [6, 5], [9, 8, 7], [10, 11, 12, 13]], \"expected\": [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[3, 2, 1, 0], [4, 5, 6], [10, 9, 8, 7], [12, 11]], \"expected\": [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[0, 1, 2], [3, 4], [5]], \"expected\": [[0, 1, 2], [4, 3], [5]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [[0], [1, 2], [3]], \"expected\": [[0], [1, 2], [3]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2], [3, 4], [5]], \"expected\": [[0, 1, 2], [3, 4], [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"expected\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[1, 0, 2, 3], [4]], \"expected\": [[1, 0, 2, 3], [4]], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":39.309,"exit_code":1,"observations":[{"actual":[[5,4,3],[2,1,0]],"check":"RTL run split across lines","expected":[[1,0,2],[5,4,3]],"passed":false},{"actual":[[10],[9,8,7,6],[5,4],[3,2,1],[0,11,12,13]],"check":"regression: paragraph-wide reordering","expected":[[0],[4,3,2,1],[6,5],[8,7,9],[10,11,12,13]],"passed":false},{"actual":[[12,11,10,9],[8,7,3],[4,5,6,2],[1,0]],"check":"regression: paragraph-wide reordering","expected":[[3,2,1,0],[4,5,6],[9,8,7,10],[11,12]],"passed":false},{"actual":[[0,1,2],[3,4],[5]],"check":"regression: paragraph-wide reordering","expected":[[0,1,2],[4,3],[5]],"passed":false},{"actual":[[0],[1,2],[3]],"check":"control layout","expected":[[0],[1,2],[3]],"passed":true},{"actual":[[0,1,2],[3,4],[5]],"check":"control layout","expected":[[0,1,2],[3,4],[5]],"passed":true},{"actual":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"check":"control layout","expected":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"passed":true},{"actual":[[1,0,2,3],[4]],"check":"control layout","expected":[[1,0,2,3],[4]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"RTL run split across lines\", \"actual\": [[5, 4, 3], [2, 1, 0]], \"expected\": [[1, 0, 2], [5, 4, 3]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[10], [9, 8, 7, 6], [5, 4], [3, 2, 1], [0, 11, 12, 13]], \"expected\": [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[12, 11, 10, 9], [8, 7, 3], [4, 5, 6, 2], [1, 0]], \"expected\": [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]], \"passed\": false}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[0, 1, 2], [3, 4], [5]], \"expected\": [[0, 1, 2], [4, 3], [5]], \"passed\": false}, {\"check\": \"control layout\", \"actual\": [[0], [1, 2], [3]], \"expected\": [[0], [1, 2], [3]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2], [3, 4], [5]], \"expected\": [[0, 1, 2], [3, 4], [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"expected\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[1, 0, 2, 3], [4]], \"expected\": [[1, 0, 2, 3], [4]], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":42.631,"exit_code":0,"observations":[{"actual":[[1,0,2],[5,4,3]],"check":"RTL run split across lines","expected":[[1,0,2],[5,4,3]],"passed":true},{"actual":[[0],[4,3,2,1],[6,5],[8,7,9],[10,11,12,13]],"check":"regression: paragraph-wide reordering","expected":[[0],[4,3,2,1],[6,5],[8,7,9],[10,11,12,13]],"passed":true},{"actual":[[3,2,1,0],[4,5,6],[9,8,7,10],[11,12]],"check":"regression: paragraph-wide reordering","expected":[[3,2,1,0],[4,5,6],[9,8,7,10],[11,12]],"passed":true},{"actual":[[0,1,2],[4,3],[5]],"check":"regression: paragraph-wide reordering","expected":[[0,1,2],[4,3],[5]],"passed":true},{"actual":[[0],[1,2],[3]],"check":"control layout","expected":[[0],[1,2],[3]],"passed":true},{"actual":[[0,1,2],[3,4],[5]],"check":"control layout","expected":[[0,1,2],[3,4],[5]],"passed":true},{"actual":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"check":"control layout","expected":[[0,1,2,3,4],[5,6,7,8,9],[10,11],[12,13]],"passed":true},{"actual":[[1,0,2,3],[4]],"check":"control layout","expected":[[1,0,2,3],[4]],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"RTL run split across lines\", \"actual\": [[1, 0, 2], [5, 4, 3]], \"expected\": [[1, 0, 2], [5, 4, 3]], \"passed\": true}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]], \"expected\": [[0], [4, 3, 2, 1], [6, 5], [8, 7, 9], [10, 11, 12, 13]], \"passed\": true}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]], \"expected\": [[3, 2, 1, 0], [4, 5, 6], [9, 8, 7, 10], [11, 12]], \"passed\": true}, {\"check\": \"regression: paragraph-wide reordering\", \"actual\": [[0, 1, 2], [4, 3], [5]], \"expected\": [[0, 1, 2], [4, 3], [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0], [1, 2], [3]], \"expected\": [[0], [1, 2], [3]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2], [3, 4], [5]], \"expected\": [[0, 1, 2], [3, 4], [5]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"expected\": [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11], [12, 13]], \"passed\": true}, {\"check\": \"control layout\", \"actual\": [[1, 0, 2, 3], [4]], \"expected\": [[1, 0, 2, 3], [4]], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}