FA-80721 / Bidirectional text layout / Open access
Per-line visual reordering: whitespace reset level · case 01
Trailing spaces on RTL paragraphs are reset to level 0.
ROOT CAUSE
Trailing whitespace is reset to 0 instead of the paragraph level.
VERIFIED REPAIR
Reset trailing whitespace to the paragraph level.
Unsuccessful approach: Rounding each level down to even is not the paragraph level.
Case 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.
Why this case matters
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.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def reorder(lv):
vis = list(range(len(lv)))
odd = [l for l in lv if l % 2 == 1]
if not odd:
return vis
for lev in range(max(lv), min(odd) - 1, -1):
i = 0
while i < len(vis):
if lv[vis[i]] >= lev:
j = i
while j < len(vis) and lv[vis[j]] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return vis
levels, classes, para, line_lengths = x
out = []
start = 0
for ln in line_lengths:
idx = list(range(start, start + ln))
lv = [levels[i] for i in idx]
j = ln - 1
while j >= 0 and classes[idx[j]] == 'WS':
lv[j] = 0
j -= 1
local = reorder(lv)
out.append([idx[v] for v in local])
start += ln
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: whitespace reset level', [[1, 1, 1, 1, 4, 4, 4, 3, 3, 4], ['R', 'R', 'R', 'WS', 'ON', 'WS', 'R', 'R', 'R', 'WS'], 1, [3, 2, 2, 1, 2]], [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]]), ('regression: whitespace reset level', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 1, [2, 2]], [[0, 1], [3, 2]]), ('regression: whitespace reset level', [[1, 1, 2, 1, 1, 1, 3, 3, 3, 1, 3, 3, 2, 2], ['WS', 'WS', 'ON', 'R', 'R', 'R', 'WS', 'WS', 'WS', 'WS', 'L', 'R', 'WS', 'R'], 1, [2, 4, 1, 4, 2, 1]], [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]]), ('regression: whitespace reset level', [[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]]), ('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', [[3, 3, 3, 3, 3, 1, 1], ['R', 'L', 'WS', 'R', 'WS', 'R', 'WS'], 0, [4, 2, 1]], [[3, 2, 1, 0], [5, 4], [6]]), ('control layout', [[0, 0, 1, 1, 1, 2, 0], ['R', 'ON', 'R', 'R', 'R', 'WS', 'R'], 1, [3, 2, 1, 1]], [[0, 1, 2], [4, 3], [5], [6]]), ('control layout', [[1, 3, 3, 3, 3, 3, 3, 3], ['WS', 'R', 'WS', 'L', 'WS', 'R', 'L', 'WS'], 0, [4, 4]], [[3, 2, 1, 0], [6, 5, 4, 7]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 2, 2], ['L', 'R', 'L', 'L', 'WS', 'WS'], 1, [2, 3, 1]], [[0, 1], [4, 2, 3], [5]]), ('regression: whitespace reset level', [[1, 3, 3, 3, 1, 1, 2, 2, 1, 2, 2, 2], ['WS', 'ON', 'L', 'L', 'ON', 'R', 'L', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 2, 3, 1, 1, 1, 3]], [[0], [2, 1], [5, 4, 3], [6], [7], [8], [11, 9, 10]]), ('regression: whitespace reset level', [[2, 2, 2, 2, 2, 1, 1, 1, 1, 4, 2, 2], ['R', 'R', 'WS', 'L', 'R', 'WS', 'L', 'R', 'R', 'WS', 'WS', 'WS'], 1, [1, 5, 1, 2, 3]], [[0], [5, 1, 2, 3, 4], [6], [8, 7], [11, 10, 9]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 3, 3, 3, 0, 0, 0], ['L', 'WS', 'WS', 'WS', 'L', 'WS', 'WS', 'ON', 'R', 'L'], 1, [3, 4, 1, 1, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [8], [9]]), ('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', [[1, 1], ['ON', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[1, 1, 3, 3, 0, 0, 3, 3, 3, 1, 1], ['L', 'R', 'R', 'WS', 'L', 'ON', 'WS', 'R', 'WS', 'L', 'R'], 0, [1, 2, 3, 5]], [[0], [2, 1], [3, 4, 5], [10, 9, 8, 7, 6]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]])], [('regression: whitespace reset level', [[0, 0, 0, 0], ['L', 'R', 'WS', 'WS'], 1, [4]], [[0, 1, 3, 2]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('partial-repair probe', [[3, 3, 3, 4, 4, 4, 1], ['R', 'R', 'WS', 'R', 'WS', 'WS', 'R'], 0, [1, 4, 2]], [[0], [3, 2, 1, 4], [6, 5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'L', 'ON', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 1, 5, 1, 1]], [[2, 1, 0], [3], [7, 6, 5, 4, 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', [[1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0], ['L', 'WS', 'R', 'R', 'WS', 'R', 'L', 'WS', 'L', 'L', 'L', 'L', 'L', 'R'], 1, [1, 5, 2, 3, 3]], [[0], [1, 2, 3, 4, 5], [6, 7], [9, 8, 10], [11, 12, 13]]), ('control layout', [[2, 2, 2, 2, 2, 2], ['ON', 'WS', 'R', 'L', 'ON', 'WS'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('control layout', [[0, 3, 3, 3, 0, 0, 0, 0, 0, 0], ['L', 'WS', 'R', 'L', 'L', 'L', 'L', 'L', 'L', 'WS'], 1, [1, 4, 4, 1]], [[0], [3, 2, 1, 4], [5, 6, 7, 8], [9]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 1, 1, 1, 3, 3, 3, 3, 1, 2, 2], ['ON', 'R', 'WS', 'R', 'L', 'R', 'R', 'R', 'R', 'L', 'R', 'R', 'WS', 'WS'], 1, [1, 1, 2, 3, 1, 2, 1, 3]], [[0], [1], [2, 3], [6, 5, 4], [7], [9, 8], [10], [13, 12, 11]]), ('regression: whitespace reset level', [[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: whitespace reset level', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'R', 'WS', 'WS', 'WS'], 1, [5, 1]], [[4, 3, 2, 1, 0], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1], ['WS', 'R', 'WS', 'L', 'L'], 1, [3, 1, 1]], [[2, 1, 0], [3], [4]]), ('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', [[3, 3, 3, 3, 3, 3, 3, 3, 3, 0], ['WS', 'WS', 'L', 'WS', 'R', 'L', 'WS', 'WS', 'R', 'WS'], 0, [4, 2, 2, 1, 1]], [[2, 1, 0, 3], [5, 4], [6, 7], [8], [9]]), ('control layout', [[1, 1, 1, 1], ['L', 'R', 'WS', 'ON'], 0, [1, 3]], [[0], [3, 2, 1]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]])], [('regression: whitespace reset level', [[2, 2, 2, 3, 3, 3, 1, 1, 1, 1, 1, 1], ['L', 'WS', 'L', 'WS', 'ON', 'WS', 'R', 'R', 'WS', 'WS', 'R', 'R'], 1, [5, 5, 1, 1]], [[0, 1, 2, 4, 3], [9, 8, 7, 6, 5], [10], [11]]), ('regression: whitespace reset level', [[2, 4, 1, 1, 1, 3], ['ON', 'L', 'ON', 'L', 'WS', 'R'], 1, [5, 1]], [[4, 3, 2, 0, 1], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 1, 0, 0, 0, 0], ['R', 'WS', 'WS', 'WS', 'R', 'L', 'L', 'L', 'R'], 1, [3, 5, 1]], [[2, 1, 0], [4, 3, 5, 6, 7], [8]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('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', [[3, 3, 3, 3, 1, 1, 0, 0], ['WS', 'WS', 'R', 'L', 'R', 'WS', 'R', 'ON'], 1, [3, 1, 1, 3]], [[2, 1, 0], [3], [4], [5, 6, 7]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]]), ('control layout', [[2, 0, 0, 0, 1, 2, 2, 2, 0, 0, 0, 0], ['R', 'WS', 'L', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'R', 'WS', 'ON'], 1, [3, 5, 4]], [[0, 1, 2], [3, 5, 6, 7, 4], [8, 9, 10, 11]])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: whitespace reset level | [[2, 1, 0], [4, 3], [5, 6], [7], [8, 9]] | [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]] | Failed |
| regression: whitespace reset level | [[0, 1], [2, 3]] | [[0, 1], [3, 2]] | Failed |
| regression: whitespace reset level | [[0, 1], [5, 4, 3, 2], [6], [10, 9, 8, 7], [11, 12], [13]] | [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]] | Failed |
| regression: whitespace reset level | [[1, 0, 2], [3, 4, 5, 6, 7], [8, 9, 10]] | [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]] | Failed |
| RTL run split across lines | [[1, 0, 2], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Passed |
| control layout | [[3, 2, 1, 0], [5, 4], [6]] | [[3, 2, 1, 0], [5, 4], [6]] | Passed |
| control layout | [[0, 1, 2], [4, 3], [5], [6]] | [[0, 1, 2], [4, 3], [5], [6]] | Passed |
| control layout | [[3, 2, 1, 0], [6, 5, 4, 7]] | [[3, 2, 1, 0], [6, 5, 4, 7]] | Passed |
SHA-256 / 5759a7a62def1925a611603cad9c0861bfb477a06c46303e522ce8c504a13586
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def reorder(lv):
vis = list(range(len(lv)))
odd = [l for l in lv if l % 2 == 1]
if not odd:
return vis
for lev in range(max(lv), min(odd) - 1, -1):
i = 0
while i < len(vis):
if lv[vis[i]] >= lev:
j = i
while j < len(vis) and lv[vis[j]] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return vis
levels, classes, para, line_lengths = x
out = []
start = 0
for ln in line_lengths:
idx = list(range(start, start + ln))
lv = [levels[i] for i in idx]
j = ln - 1
while j >= 0 and classes[idx[j]] == 'WS':
lv[j] = lv[j] - lv[j] % 2
j -= 1
local = reorder(lv)
out.append([idx[v] for v in local])
start += ln
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: whitespace reset level', [[1, 1, 1, 1, 4, 4, 4, 3, 3, 4], ['R', 'R', 'R', 'WS', 'ON', 'WS', 'R', 'R', 'R', 'WS'], 1, [3, 2, 2, 1, 2]], [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]]), ('regression: whitespace reset level', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 1, [2, 2]], [[0, 1], [3, 2]]), ('regression: whitespace reset level', [[1, 1, 2, 1, 1, 1, 3, 3, 3, 1, 3, 3, 2, 2], ['WS', 'WS', 'ON', 'R', 'R', 'R', 'WS', 'WS', 'WS', 'WS', 'L', 'R', 'WS', 'R'], 1, [2, 4, 1, 4, 2, 1]], [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]]), ('regression: whitespace reset level', [[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]]), ('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', [[3, 3, 3, 3, 3, 1, 1], ['R', 'L', 'WS', 'R', 'WS', 'R', 'WS'], 0, [4, 2, 1]], [[3, 2, 1, 0], [5, 4], [6]]), ('control layout', [[0, 0, 1, 1, 1, 2, 0], ['R', 'ON', 'R', 'R', 'R', 'WS', 'R'], 1, [3, 2, 1, 1]], [[0, 1, 2], [4, 3], [5], [6]]), ('control layout', [[1, 3, 3, 3, 3, 3, 3, 3], ['WS', 'R', 'WS', 'L', 'WS', 'R', 'L', 'WS'], 0, [4, 4]], [[3, 2, 1, 0], [6, 5, 4, 7]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 2, 2], ['L', 'R', 'L', 'L', 'WS', 'WS'], 1, [2, 3, 1]], [[0, 1], [4, 2, 3], [5]]), ('regression: whitespace reset level', [[1, 3, 3, 3, 1, 1, 2, 2, 1, 2, 2, 2], ['WS', 'ON', 'L', 'L', 'ON', 'R', 'L', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 2, 3, 1, 1, 1, 3]], [[0], [2, 1], [5, 4, 3], [6], [7], [8], [11, 9, 10]]), ('regression: whitespace reset level', [[2, 2, 2, 2, 2, 1, 1, 1, 1, 4, 2, 2], ['R', 'R', 'WS', 'L', 'R', 'WS', 'L', 'R', 'R', 'WS', 'WS', 'WS'], 1, [1, 5, 1, 2, 3]], [[0], [5, 1, 2, 3, 4], [6], [8, 7], [11, 10, 9]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 3, 3, 3, 0, 0, 0], ['L', 'WS', 'WS', 'WS', 'L', 'WS', 'WS', 'ON', 'R', 'L'], 1, [3, 4, 1, 1, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [8], [9]]), ('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', [[1, 1], ['ON', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[1, 1, 3, 3, 0, 0, 3, 3, 3, 1, 1], ['L', 'R', 'R', 'WS', 'L', 'ON', 'WS', 'R', 'WS', 'L', 'R'], 0, [1, 2, 3, 5]], [[0], [2, 1], [3, 4, 5], [10, 9, 8, 7, 6]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]])], [('regression: whitespace reset level', [[0, 0, 0, 0], ['L', 'R', 'WS', 'WS'], 1, [4]], [[0, 1, 3, 2]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('partial-repair probe', [[3, 3, 3, 4, 4, 4, 1], ['R', 'R', 'WS', 'R', 'WS', 'WS', 'R'], 0, [1, 4, 2]], [[0], [3, 2, 1, 4], [6, 5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'L', 'ON', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 1, 5, 1, 1]], [[2, 1, 0], [3], [7, 6, 5, 4, 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', [[1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0], ['L', 'WS', 'R', 'R', 'WS', 'R', 'L', 'WS', 'L', 'L', 'L', 'L', 'L', 'R'], 1, [1, 5, 2, 3, 3]], [[0], [1, 2, 3, 4, 5], [6, 7], [9, 8, 10], [11, 12, 13]]), ('control layout', [[2, 2, 2, 2, 2, 2], ['ON', 'WS', 'R', 'L', 'ON', 'WS'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('control layout', [[0, 3, 3, 3, 0, 0, 0, 0, 0, 0], ['L', 'WS', 'R', 'L', 'L', 'L', 'L', 'L', 'L', 'WS'], 1, [1, 4, 4, 1]], [[0], [3, 2, 1, 4], [5, 6, 7, 8], [9]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 1, 1, 1, 3, 3, 3, 3, 1, 2, 2], ['ON', 'R', 'WS', 'R', 'L', 'R', 'R', 'R', 'R', 'L', 'R', 'R', 'WS', 'WS'], 1, [1, 1, 2, 3, 1, 2, 1, 3]], [[0], [1], [2, 3], [6, 5, 4], [7], [9, 8], [10], [13, 12, 11]]), ('regression: whitespace reset level', [[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: whitespace reset level', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'R', 'WS', 'WS', 'WS'], 1, [5, 1]], [[4, 3, 2, 1, 0], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1], ['WS', 'R', 'WS', 'L', 'L'], 1, [3, 1, 1]], [[2, 1, 0], [3], [4]]), ('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', [[3, 3, 3, 3, 3, 3, 3, 3, 3, 0], ['WS', 'WS', 'L', 'WS', 'R', 'L', 'WS', 'WS', 'R', 'WS'], 0, [4, 2, 2, 1, 1]], [[2, 1, 0, 3], [5, 4], [6, 7], [8], [9]]), ('control layout', [[1, 1, 1, 1], ['L', 'R', 'WS', 'ON'], 0, [1, 3]], [[0], [3, 2, 1]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]])], [('regression: whitespace reset level', [[2, 2, 2, 3, 3, 3, 1, 1, 1, 1, 1, 1], ['L', 'WS', 'L', 'WS', 'ON', 'WS', 'R', 'R', 'WS', 'WS', 'R', 'R'], 1, [5, 5, 1, 1]], [[0, 1, 2, 4, 3], [9, 8, 7, 6, 5], [10], [11]]), ('regression: whitespace reset level', [[2, 4, 1, 1, 1, 3], ['ON', 'L', 'ON', 'L', 'WS', 'R'], 1, [5, 1]], [[4, 3, 2, 0, 1], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 1, 0, 0, 0, 0], ['R', 'WS', 'WS', 'WS', 'R', 'L', 'L', 'L', 'R'], 1, [3, 5, 1]], [[2, 1, 0], [4, 3, 5, 6, 7], [8]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('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', [[3, 3, 3, 3, 1, 1, 0, 0], ['WS', 'WS', 'R', 'L', 'R', 'WS', 'R', 'ON'], 1, [3, 1, 1, 3]], [[2, 1, 0], [3], [4], [5, 6, 7]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]]), ('control layout', [[2, 0, 0, 0, 1, 2, 2, 2, 0, 0, 0, 0], ['R', 'WS', 'L', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'R', 'WS', 'ON'], 1, [3, 5, 4]], [[0, 1, 2], [3, 5, 6, 7, 4], [8, 9, 10, 11]])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: whitespace reset level | [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]] | [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]] | Passed |
| regression: whitespace reset level | [[0, 1], [2, 3]] | [[0, 1], [3, 2]] | Failed |
| regression: whitespace reset level | [[0, 1], [5, 4, 3, 2], [6], [10, 9, 8, 7], [11, 12], [13]] | [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]] | Failed |
| regression: whitespace reset level | [[1, 0, 2], [3, 4, 5, 6, 7], [8, 9, 10]] | [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]] | Failed |
| RTL run split across lines | [[1, 0, 2], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Passed |
| control layout | [[3, 2, 1, 0], [5, 4], [6]] | [[3, 2, 1, 0], [5, 4], [6]] | Passed |
| control layout | [[0, 1, 2], [4, 3], [5], [6]] | [[0, 1, 2], [4, 3], [5], [6]] | Passed |
| control layout | [[3, 2, 1, 0], [6, 5, 4, 7]] | [[3, 2, 1, 0], [6, 5, 4, 7]] | Passed |
SHA-256 / 953bc740de94812aac5ca63fe5799eda7e858ba3d90acfbcb5d987623b6727e7
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
def reorder(lv):
vis = list(range(len(lv)))
odd = [l for l in lv if l % 2 == 1]
if not odd:
return vis
for lev in range(max(lv), min(odd) - 1, -1):
i = 0
while i < len(vis):
if lv[vis[i]] >= lev:
j = i
while j < len(vis) and lv[vis[j]] >= lev:
j += 1
vis[i:j] = vis[i:j][::-1]
i = j
else:
i += 1
return vis
levels, classes, para, line_lengths = x
out = []
start = 0
for ln in line_lengths:
idx = list(range(start, start + ln))
lv = [levels[i] for i in idx]
j = ln - 1
while j >= 0 and classes[idx[j]] == 'WS':
lv[j] = para
j -= 1
local = reorder(lv)
out.append([idx[v] for v in local])
start += ln
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: whitespace reset level', [[1, 1, 1, 1, 4, 4, 4, 3, 3, 4], ['R', 'R', 'R', 'WS', 'ON', 'WS', 'R', 'R', 'R', 'WS'], 1, [3, 2, 2, 1, 2]], [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]]), ('regression: whitespace reset level', [[2, 2, 2, 2], ['R', 'R', 'R', 'WS'], 1, [2, 2]], [[0, 1], [3, 2]]), ('regression: whitespace reset level', [[1, 1, 2, 1, 1, 1, 3, 3, 3, 1, 3, 3, 2, 2], ['WS', 'WS', 'ON', 'R', 'R', 'R', 'WS', 'WS', 'WS', 'WS', 'L', 'R', 'WS', 'R'], 1, [2, 4, 1, 4, 2, 1]], [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]]), ('regression: whitespace reset level', [[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]]), ('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', [[3, 3, 3, 3, 3, 1, 1], ['R', 'L', 'WS', 'R', 'WS', 'R', 'WS'], 0, [4, 2, 1]], [[3, 2, 1, 0], [5, 4], [6]]), ('control layout', [[0, 0, 1, 1, 1, 2, 0], ['R', 'ON', 'R', 'R', 'R', 'WS', 'R'], 1, [3, 2, 1, 1]], [[0, 1, 2], [4, 3], [5], [6]]), ('control layout', [[1, 3, 3, 3, 3, 3, 3, 3], ['WS', 'R', 'WS', 'L', 'WS', 'R', 'L', 'WS'], 0, [4, 4]], [[3, 2, 1, 0], [6, 5, 4, 7]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 2, 2], ['L', 'R', 'L', 'L', 'WS', 'WS'], 1, [2, 3, 1]], [[0, 1], [4, 2, 3], [5]]), ('regression: whitespace reset level', [[1, 3, 3, 3, 1, 1, 2, 2, 1, 2, 2, 2], ['WS', 'ON', 'L', 'L', 'ON', 'R', 'L', 'L', 'R', 'WS', 'L', 'WS'], 1, [1, 2, 3, 1, 1, 1, 3]], [[0], [2, 1], [5, 4, 3], [6], [7], [8], [11, 9, 10]]), ('regression: whitespace reset level', [[2, 2, 2, 2, 2, 1, 1, 1, 1, 4, 2, 2], ['R', 'R', 'WS', 'L', 'R', 'WS', 'L', 'R', 'R', 'WS', 'WS', 'WS'], 1, [1, 5, 1, 2, 3]], [[0], [5, 1, 2, 3, 4], [6], [8, 7], [11, 10, 9]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 3, 3, 3, 0, 0, 0], ['L', 'WS', 'WS', 'WS', 'L', 'WS', 'WS', 'ON', 'R', 'L'], 1, [3, 4, 1, 1, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [8], [9]]), ('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', [[1, 1], ['ON', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[1, 1, 3, 3, 0, 0, 3, 3, 3, 1, 1], ['L', 'R', 'R', 'WS', 'L', 'ON', 'WS', 'R', 'WS', 'L', 'R'], 0, [1, 2, 3, 5]], [[0], [2, 1], [3, 4, 5], [10, 9, 8, 7, 6]]), ('control layout', [[0, 0, 0, 0, 0, 0], ['WS', 'R', 'L', 'WS', 'L', 'ON'], 0, [4, 1, 1]], [[0, 1, 2, 3], [4], [5]])], [('regression: whitespace reset level', [[0, 0, 0, 0], ['L', 'R', 'WS', 'WS'], 1, [4]], [[0, 1, 3, 2]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('partial-repair probe', [[3, 3, 3, 4, 4, 4, 1], ['R', 'R', 'WS', 'R', 'WS', 'WS', 'R'], 0, [1, 4, 2]], [[0], [3, 2, 1, 4], [6, 5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'L', 'ON', 'WS', 'WS', 'L', 'R', 'L'], 1, [3, 1, 5, 1, 1]], [[2, 1, 0], [3], [7, 6, 5, 4, 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', [[1, 2, 2, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0], ['L', 'WS', 'R', 'R', 'WS', 'R', 'L', 'WS', 'L', 'L', 'L', 'L', 'L', 'R'], 1, [1, 5, 2, 3, 3]], [[0], [1, 2, 3, 4, 5], [6, 7], [9, 8, 10], [11, 12, 13]]), ('control layout', [[2, 2, 2, 2, 2, 2], ['ON', 'WS', 'R', 'L', 'ON', 'WS'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('control layout', [[0, 3, 3, 3, 0, 0, 0, 0, 0, 0], ['L', 'WS', 'R', 'L', 'L', 'L', 'L', 'L', 'L', 'WS'], 1, [1, 4, 4, 1]], [[0], [3, 2, 1, 4], [5, 6, 7, 8], [9]])], [('regression: whitespace reset level', [[2, 2, 2, 2, 1, 1, 1, 3, 3, 3, 3, 1, 2, 2], ['ON', 'R', 'WS', 'R', 'L', 'R', 'R', 'R', 'R', 'L', 'R', 'R', 'WS', 'WS'], 1, [1, 1, 2, 3, 1, 2, 1, 3]], [[0], [1], [2, 3], [6, 5, 4], [7], [9, 8], [10], [13, 12, 11]]), ('regression: whitespace reset level', [[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: whitespace reset level', [[1, 1, 1, 1, 1, 1], ['R', 'R', 'R', 'WS', 'WS', 'WS'], 1, [5, 1]], [[4, 3, 2, 1, 0], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 1, 1], ['WS', 'R', 'WS', 'L', 'L'], 1, [3, 1, 1]], [[2, 1, 0], [3], [4]]), ('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', [[3, 3, 3, 3, 3, 3, 3, 3, 3, 0], ['WS', 'WS', 'L', 'WS', 'R', 'L', 'WS', 'WS', 'R', 'WS'], 0, [4, 2, 2, 1, 1]], [[2, 1, 0, 3], [5, 4], [6, 7], [8], [9]]), ('control layout', [[1, 1, 1, 1], ['L', 'R', 'WS', 'ON'], 0, [1, 3]], [[0], [3, 2, 1]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]])], [('regression: whitespace reset level', [[2, 2, 2, 3, 3, 3, 1, 1, 1, 1, 1, 1], ['L', 'WS', 'L', 'WS', 'ON', 'WS', 'R', 'R', 'WS', 'WS', 'R', 'R'], 1, [5, 5, 1, 1]], [[0, 1, 2, 4, 3], [9, 8, 7, 6, 5], [10], [11]]), ('regression: whitespace reset level', [[2, 4, 1, 1, 1, 3], ['ON', 'L', 'ON', 'L', 'WS', 'R'], 1, [5, 1]], [[4, 3, 2, 0, 1], [5]]), ('regression: whitespace reset level', [[1, 1, 1, 3, 1, 0, 0, 0, 0], ['R', 'WS', 'WS', 'WS', 'R', 'L', 'L', 'L', 'R'], 1, [3, 5, 1]], [[2, 1, 0], [4, 3, 5, 6, 7], [8]]), ('regression: whitespace reset level', [[1, 1], ['WS', 'WS'], 1, [2]], [[1, 0]]), ('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', [[3, 3, 3, 3, 1, 1, 0, 0], ['WS', 'WS', 'R', 'L', 'R', 'WS', 'R', 'ON'], 1, [3, 1, 1, 3]], [[2, 1, 0], [3], [4], [5, 6, 7]]), ('control layout', [[0, 0, 0, 0, 0], ['R', 'L', 'L', 'WS', 'WS'], 0, [4, 1]], [[0, 1, 2, 3], [4]]), ('control layout', [[2, 0, 0, 0, 1, 2, 2, 2, 0, 0, 0, 0], ['R', 'WS', 'L', 'WS', 'WS', 'L', 'WS', 'L', 'WS', 'R', 'WS', 'ON'], 1, [3, 5, 4]], [[0, 1, 2], [3, 5, 6, 7, 4], [8, 9, 10, 11]])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: whitespace reset level | [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]] | [[2, 1, 0], [4, 3], [5, 6], [7], [9, 8]] | Passed |
| regression: whitespace reset level | [[0, 1], [3, 2]] | [[0, 1], [3, 2]] | Passed |
| regression: whitespace reset level | [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]] | [[1, 0], [5, 4, 3, 2], [6], [10, 9, 8, 7], [12, 11], [13]] | Passed |
| regression: whitespace reset level | [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]] | [[2, 1, 0], [3, 4, 7, 6, 5], [8, 9, 10]] | Passed |
| RTL run split across lines | [[1, 0, 2], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Passed |
| control layout | [[3, 2, 1, 0], [5, 4], [6]] | [[3, 2, 1, 0], [5, 4], [6]] | Passed |
| control layout | [[0, 1, 2], [4, 3], [5], [6]] | [[0, 1, 2], [4, 3], [5], [6]] | Passed |
| control layout | [[3, 2, 1, 0], [6, 5, 4, 7]] | [[3, 2, 1, 0], [6, 5, 4, 7]] | Passed |
SHA-256 / b7c5febce56366d8a29eac7aba7184cbb87f6fbbf9e0b78957cd1a84f7235f47
Verification & scope
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.
Observations recorded using Python 3.12.14 at 2026-09-29T14:49:56.457431+00:00.
Case digest / 786e88aaeb005831d25e915ab523b1e260a800a39a0e520c38fd3aeb948f76b4