FA-80716 / Bidirectional text layout / Open access
Per-line visual reordering: trailing whitespace per line · case 01
Spaces at the end of wrapped lines jump to the far side.
ROOT CAUSE
Trailing whitespace is reset only on the final line of the paragraph.
VERIFIED REPAIR
Reset trailing whitespace on every line.
Unsuccessful approach: Also resetting trailing neutrals changes punctuation placement.
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' and start + ln == len(levels):
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 = [[('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: trailing whitespace per line', [[2, 1, 2, 2, 2, 2], ['ON', 'WS', 'ON', 'WS', 'WS', 'R'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('regression: trailing whitespace per line', [[4, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 1, 3], ['WS', 'R', 'L', 'ON', 'WS', 'WS', 'WS', 'L', 'ON', 'R', 'WS', 'L', 'R'], 1, [2, 5, 3, 1, 1, 1]], [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]]), ('regression: trailing whitespace per line', [[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]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'WS', 'ON', 'R', 'WS', 'WS'], 0, [4, 1, 4]], [[0, 1, 2, 3], [4], [5, 6, 7, 8]]), ('control layout', [[3, 0], ['ON', 'WS'], 1, [1, 1]], [[0], [1]]), ('control layout', [[0, 3, 3], ['L', 'L', 'WS'], 0, [1, 2]], [[0], [1, 2]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2], ['L', 'R', 'L', 'WS', 'R', 'R', 'R'], 1, [2, 5]], [[0, 1], [2, 3, 4, 5, 6]])], [('regression: trailing whitespace per line', [[2, 3, 0, 0, 3, 2, 2, 2, 1, 1, 1], ['L', 'WS', 'WS', 'WS', 'WS', 'ON', 'R', 'L', 'L', 'R', 'R'], 1, [4, 5, 1, 1]], [[3, 2, 1, 0], [8, 4, 5, 6, 7], [9], [10]]), ('regression: trailing whitespace per line', [[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]]), ('partial-repair probe', [[0, 0, 0, 0, 1, 1, 3, 2, 2, 2, 2, 0, 0], ['WS', 'WS', 'R', 'R', 'R', 'R', 'L', 'WS', 'ON', 'L', 'R', 'WS', 'R'], 0, [5, 4, 4]], [[0, 1, 2, 3, 4], [6, 7, 8, 5], [9, 10, 11, 12]]), ('partial-repair probe', [[2, 2, 1, 1, 1, 1, 2, 2], ['WS', 'L', 'R', 'WS', 'ON', 'L', 'WS', 'L'], 0, [5, 1, 2]], [[4, 3, 2, 0, 1], [5], [6, 7]]), ('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, 1, 2, 3, 3, 3, 2], ['L', 'ON', 'R', 'R', 'L', 'L', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 0, 1, 2], [7, 6, 5], [8]]), ('control layout', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'R', 'R', 'R', 'R', 'L', 'L', 'R', 'WS', 'WS', 'WS', 'WS', 'ON'], 1, [4, 2, 3, 1, 1, 1, 1]], [[3, 0, 1, 2], [5, 4], [8, 7, 6], [9], [10], [11], [12]]), ('control layout', [[1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 1], ['L', 'L', 'ON', 'L', 'WS', 'L', 'WS', 'L', 'R', 'WS', 'WS', 'R'], 0, [4, 1, 5, 2]], [[1, 2, 3, 0], [4], [5, 6, 7, 8, 9], [11, 10]])], [('regression: trailing whitespace per line', [[4, 4, 4, 4, 3, 2, 2, 1], ['L', 'WS', 'R', 'L', 'WS', 'WS', 'WS', 'R'], 1, [3, 4, 1]], [[0, 1, 2], [6, 5, 4, 3], [7]]), ('regression: trailing whitespace per line', [[2, 2, 2, 2, 4, 4, 4, 3, 2, 2], ['WS', 'WS', 'WS', 'WS', 'L', 'WS', 'L', 'R', 'R', 'WS'], 1, [2, 2, 3, 2, 1]], [[1, 0], [3, 2], [4, 5, 6], [7, 8], [9]]), ('partial-repair probe', [[1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1], ['L', 'WS', 'ON', 'ON', 'WS', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [3, 4, 1, 2, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [9, 8], [10]]), ('partial-repair probe', [[2, 2, 2, 2], ['L', 'R', 'ON', 'ON'], 1, [4]], [[0, 1, 2, 3]]), ('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, 1, 1, 2], ['R', 'L', 'R', 'L', 'ON'], 1, [2, 1, 2]], [[1, 0], [2], [4, 3]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2, 2, 2], ['L', 'WS', 'R', 'R', 'L', 'ON', 'R', 'R', 'R'], 1, [4, 4, 1]], [[0, 1, 2, 3], [4, 5, 6, 7], [8]]), ('control layout', [[4, 4, 4, 4, 4, 1, 1], ['L', 'ON', 'WS', 'L', 'WS', 'WS', 'WS'], 0, [5, 2]], [[0, 1, 2, 3, 4], [5, 6]])], [('regression: trailing whitespace per line', [[2, 2, 2, 2, 2, 2, 2, 2, 2], ['R', 'R', 'L', 'L', 'L', 'WS', 'WS', 'R', 'L'], 1, [3, 3, 1, 1, 1]], [[0, 1, 2], [5, 3, 4], [6], [7], [8]]), ('regression: trailing whitespace per line', [[4, 4, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['R', 'WS', 'L', 'WS', 'WS', 'WS', 'L', 'WS', 'R', 'R', 'L', 'R'], 0, [4, 5, 2, 1]], [[2, 0, 1, 3], [8, 7, 6, 4, 5], [10, 9], [11]]), ('regression: trailing whitespace per line', [[1, 1, 1, 1, 3, 3, 3, 3], ['L', 'WS', 'ON', 'WS', 'WS', 'L', 'ON', 'R'], 0, [5, 3]], [[2, 1, 0, 3, 4], [7, 6, 5]]), ('partial-repair probe', [[3, 3, 1, 1, 1, 1, 4, 3, 1, 1, 4, 4, 4], ['WS', 'R', 'WS', 'WS', 'R', 'R', 'WS', 'L', 'WS', 'R', 'L', 'ON', 'WS'], 0, [5, 3, 5]], [[4, 3, 2, 1, 0], [7, 6, 5], [10, 11, 9, 8, 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', [[3, 3, 3, 3], ['L', 'ON', 'R', 'R'], 1, [3, 1]], [[2, 1, 0], [3]]), ('control layout', [[4, 1, 1, 3, 3, 2, 4, 2, 4, 4], ['R', 'R', 'WS', 'WS', 'L', 'WS', 'ON', 'L', 'L', 'L'], 1, [5, 3, 2]], [[4, 3, 2, 1, 0], [5, 6, 7], [8, 9]]), ('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]])], [('regression: trailing whitespace per line', [[1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0], ['L', 'R', 'L', 'L', 'WS', 'L', 'R', 'ON', 'R', 'L', 'R', 'WS', 'L'], 1, [4, 4, 4, 1]], [[3, 2, 1, 0], [4, 5, 6, 7], [11, 10, 9, 8], [12]]), ('regression: trailing whitespace per line', [[1, 1, 4], ['R', 'WS', 'L'], 0, [2, 1]], [[0, 1], [2]]), ('regression: trailing whitespace per line', [[1, 1, 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 2, 2], ['WS', 'ON', 'WS', 'L', 'L', 'R', 'L', 'R', 'R', 'WS', 'L', 'ON', 'R', 'WS'], 0, [3, 3, 1, 4, 3]], [[1, 0, 2], [3, 4, 5], [6], [7, 8, 9, 10], [11, 12, 13]]), ('partial-repair probe', [[1, 1, 1, 1, 4, 2, 2, 1, 2, 4, 4, 4], ['WS', 'L', 'R', 'WS', 'R', 'R', 'R', 'R', 'WS', 'WS', 'L', 'ON'], 1, [3, 5, 1, 3]], [[2, 1, 0], [7, 4, 5, 6, 3], [8], [9, 10, 11]]), ('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], ['R', 'L'], 1, [1, 1]], [[0], [1]]), ('control layout', [[1, 1], ['L', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[2, 2, 2, 2], ['R', 'L', 'WS', 'R'], 0, [2, 2]], [[0, 1], [2, 3]])]]
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 |
|---|---|---|---|
| RTL run split across lines | [[2, 1, 0], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Failed |
| regression: trailing whitespace per line | [[1, 0], [2, 3], [4], [5]] | [[0, 1], [2, 3], [4], [5]] | Failed |
| regression: trailing whitespace per line | [[0, 1], [2, 3, 4, 5, 6], [7, 8, 9], [10], [11], [12]] | [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]] | Failed |
| regression: trailing whitespace per line | [[0, 1, 2, 3], [4, 5], [6]] | [[3, 2, 1, 0], [4, 5], [6]] | Failed |
| control layout | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | Passed |
| control layout | [[0], [1]] | [[0], [1]] | Passed |
| control layout | [[0], [1, 2]] | [[0], [1, 2]] | Passed |
| control layout | [[0, 1], [2, 3, 4, 5, 6]] | [[0, 1], [2, 3, 4, 5, 6]] | Passed |
SHA-256 / 9701b8d1c2dfc6681b0a45cb34713efbd5cfae8b6ac5d26ed2fe9fbdd90b4653
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]] in ('WS', 'ON'):
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 = [[('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: trailing whitespace per line', [[2, 1, 2, 2, 2, 2], ['ON', 'WS', 'ON', 'WS', 'WS', 'R'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('regression: trailing whitespace per line', [[4, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 1, 3], ['WS', 'R', 'L', 'ON', 'WS', 'WS', 'WS', 'L', 'ON', 'R', 'WS', 'L', 'R'], 1, [2, 5, 3, 1, 1, 1]], [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]]), ('regression: trailing whitespace per line', [[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]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'WS', 'ON', 'R', 'WS', 'WS'], 0, [4, 1, 4]], [[0, 1, 2, 3], [4], [5, 6, 7, 8]]), ('control layout', [[3, 0], ['ON', 'WS'], 1, [1, 1]], [[0], [1]]), ('control layout', [[0, 3, 3], ['L', 'L', 'WS'], 0, [1, 2]], [[0], [1, 2]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2], ['L', 'R', 'L', 'WS', 'R', 'R', 'R'], 1, [2, 5]], [[0, 1], [2, 3, 4, 5, 6]])], [('regression: trailing whitespace per line', [[2, 3, 0, 0, 3, 2, 2, 2, 1, 1, 1], ['L', 'WS', 'WS', 'WS', 'WS', 'ON', 'R', 'L', 'L', 'R', 'R'], 1, [4, 5, 1, 1]], [[3, 2, 1, 0], [8, 4, 5, 6, 7], [9], [10]]), ('regression: trailing whitespace per line', [[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]]), ('partial-repair probe', [[0, 0, 0, 0, 1, 1, 3, 2, 2, 2, 2, 0, 0], ['WS', 'WS', 'R', 'R', 'R', 'R', 'L', 'WS', 'ON', 'L', 'R', 'WS', 'R'], 0, [5, 4, 4]], [[0, 1, 2, 3, 4], [6, 7, 8, 5], [9, 10, 11, 12]]), ('partial-repair probe', [[2, 2, 1, 1, 1, 1, 2, 2], ['WS', 'L', 'R', 'WS', 'ON', 'L', 'WS', 'L'], 0, [5, 1, 2]], [[4, 3, 2, 0, 1], [5], [6, 7]]), ('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, 1, 2, 3, 3, 3, 2], ['L', 'ON', 'R', 'R', 'L', 'L', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 0, 1, 2], [7, 6, 5], [8]]), ('control layout', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'R', 'R', 'R', 'R', 'L', 'L', 'R', 'WS', 'WS', 'WS', 'WS', 'ON'], 1, [4, 2, 3, 1, 1, 1, 1]], [[3, 0, 1, 2], [5, 4], [8, 7, 6], [9], [10], [11], [12]]), ('control layout', [[1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 1], ['L', 'L', 'ON', 'L', 'WS', 'L', 'WS', 'L', 'R', 'WS', 'WS', 'R'], 0, [4, 1, 5, 2]], [[1, 2, 3, 0], [4], [5, 6, 7, 8, 9], [11, 10]])], [('regression: trailing whitespace per line', [[4, 4, 4, 4, 3, 2, 2, 1], ['L', 'WS', 'R', 'L', 'WS', 'WS', 'WS', 'R'], 1, [3, 4, 1]], [[0, 1, 2], [6, 5, 4, 3], [7]]), ('regression: trailing whitespace per line', [[2, 2, 2, 2, 4, 4, 4, 3, 2, 2], ['WS', 'WS', 'WS', 'WS', 'L', 'WS', 'L', 'R', 'R', 'WS'], 1, [2, 2, 3, 2, 1]], [[1, 0], [3, 2], [4, 5, 6], [7, 8], [9]]), ('partial-repair probe', [[1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1], ['L', 'WS', 'ON', 'ON', 'WS', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [3, 4, 1, 2, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [9, 8], [10]]), ('partial-repair probe', [[2, 2, 2, 2], ['L', 'R', 'ON', 'ON'], 1, [4]], [[0, 1, 2, 3]]), ('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, 1, 1, 2], ['R', 'L', 'R', 'L', 'ON'], 1, [2, 1, 2]], [[1, 0], [2], [4, 3]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2, 2, 2], ['L', 'WS', 'R', 'R', 'L', 'ON', 'R', 'R', 'R'], 1, [4, 4, 1]], [[0, 1, 2, 3], [4, 5, 6, 7], [8]]), ('control layout', [[4, 4, 4, 4, 4, 1, 1], ['L', 'ON', 'WS', 'L', 'WS', 'WS', 'WS'], 0, [5, 2]], [[0, 1, 2, 3, 4], [5, 6]])], [('regression: trailing whitespace per line', [[2, 2, 2, 2, 2, 2, 2, 2, 2], ['R', 'R', 'L', 'L', 'L', 'WS', 'WS', 'R', 'L'], 1, [3, 3, 1, 1, 1]], [[0, 1, 2], [5, 3, 4], [6], [7], [8]]), ('regression: trailing whitespace per line', [[4, 4, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['R', 'WS', 'L', 'WS', 'WS', 'WS', 'L', 'WS', 'R', 'R', 'L', 'R'], 0, [4, 5, 2, 1]], [[2, 0, 1, 3], [8, 7, 6, 4, 5], [10, 9], [11]]), ('regression: trailing whitespace per line', [[1, 1, 1, 1, 3, 3, 3, 3], ['L', 'WS', 'ON', 'WS', 'WS', 'L', 'ON', 'R'], 0, [5, 3]], [[2, 1, 0, 3, 4], [7, 6, 5]]), ('partial-repair probe', [[3, 3, 1, 1, 1, 1, 4, 3, 1, 1, 4, 4, 4], ['WS', 'R', 'WS', 'WS', 'R', 'R', 'WS', 'L', 'WS', 'R', 'L', 'ON', 'WS'], 0, [5, 3, 5]], [[4, 3, 2, 1, 0], [7, 6, 5], [10, 11, 9, 8, 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', [[3, 3, 3, 3], ['L', 'ON', 'R', 'R'], 1, [3, 1]], [[2, 1, 0], [3]]), ('control layout', [[4, 1, 1, 3, 3, 2, 4, 2, 4, 4], ['R', 'R', 'WS', 'WS', 'L', 'WS', 'ON', 'L', 'L', 'L'], 1, [5, 3, 2]], [[4, 3, 2, 1, 0], [5, 6, 7], [8, 9]]), ('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]])], [('regression: trailing whitespace per line', [[1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0], ['L', 'R', 'L', 'L', 'WS', 'L', 'R', 'ON', 'R', 'L', 'R', 'WS', 'L'], 1, [4, 4, 4, 1]], [[3, 2, 1, 0], [4, 5, 6, 7], [11, 10, 9, 8], [12]]), ('regression: trailing whitespace per line', [[1, 1, 4], ['R', 'WS', 'L'], 0, [2, 1]], [[0, 1], [2]]), ('regression: trailing whitespace per line', [[1, 1, 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 2, 2], ['WS', 'ON', 'WS', 'L', 'L', 'R', 'L', 'R', 'R', 'WS', 'L', 'ON', 'R', 'WS'], 0, [3, 3, 1, 4, 3]], [[1, 0, 2], [3, 4, 5], [6], [7, 8, 9, 10], [11, 12, 13]]), ('partial-repair probe', [[1, 1, 1, 1, 4, 2, 2, 1, 2, 4, 4, 4], ['WS', 'L', 'R', 'WS', 'R', 'R', 'R', 'R', 'WS', 'WS', 'L', 'ON'], 1, [3, 5, 1, 3]], [[2, 1, 0], [7, 4, 5, 6, 3], [8], [9, 10, 11]]), ('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], ['R', 'L'], 1, [1, 1]], [[0], [1]]), ('control layout', [[1, 1], ['L', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[2, 2, 2, 2], ['R', 'L', 'WS', 'R'], 0, [2, 2]], [[0, 1], [2, 3]])]]
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 |
|---|---|---|---|
| RTL run split across lines | [[1, 0, 2], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Passed |
| regression: trailing whitespace per line | [[0, 1], [2, 3], [4], [5]] | [[0, 1], [2, 3], [4], [5]] | Passed |
| regression: trailing whitespace per line | [[0, 1], [6, 5, 4, 3, 2], [7, 8, 9], [10], [11], [12]] | [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]] | Failed |
| regression: trailing whitespace per line | [[3, 2, 1, 0], [5, 4], [6]] | [[3, 2, 1, 0], [4, 5], [6]] | Failed |
| control layout | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | Passed |
| control layout | [[0], [1]] | [[0], [1]] | Passed |
| control layout | [[0], [1, 2]] | [[0], [1, 2]] | Passed |
| control layout | [[0, 1], [2, 3, 4, 5, 6]] | [[0, 1], [2, 3, 4, 5, 6]] | Passed |
SHA-256 / c631682a1649296bb4fced42c1128d3434b4aa905f35d2f96af558d671797d40
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 = [[('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: trailing whitespace per line', [[2, 1, 2, 2, 2, 2], ['ON', 'WS', 'ON', 'WS', 'WS', 'R'], 0, [2, 2, 1, 1]], [[0, 1], [2, 3], [4], [5]]), ('regression: trailing whitespace per line', [[4, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 1, 3], ['WS', 'R', 'L', 'ON', 'WS', 'WS', 'WS', 'L', 'ON', 'R', 'WS', 'L', 'R'], 1, [2, 5, 3, 1, 1, 1]], [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]]), ('regression: trailing whitespace per line', [[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]]), ('control layout', [[1, 0, 0, 0, 0, 0, 0, 0, 0], ['R', 'R', 'WS', 'WS', 'WS', 'ON', 'R', 'WS', 'WS'], 0, [4, 1, 4]], [[0, 1, 2, 3], [4], [5, 6, 7, 8]]), ('control layout', [[3, 0], ['ON', 'WS'], 1, [1, 1]], [[0], [1]]), ('control layout', [[0, 3, 3], ['L', 'L', 'WS'], 0, [1, 2]], [[0], [1, 2]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2], ['L', 'R', 'L', 'WS', 'R', 'R', 'R'], 1, [2, 5]], [[0, 1], [2, 3, 4, 5, 6]])], [('regression: trailing whitespace per line', [[2, 3, 0, 0, 3, 2, 2, 2, 1, 1, 1], ['L', 'WS', 'WS', 'WS', 'WS', 'ON', 'R', 'L', 'L', 'R', 'R'], 1, [4, 5, 1, 1]], [[3, 2, 1, 0], [8, 4, 5, 6, 7], [9], [10]]), ('regression: trailing whitespace per line', [[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]]), ('partial-repair probe', [[0, 0, 0, 0, 1, 1, 3, 2, 2, 2, 2, 0, 0], ['WS', 'WS', 'R', 'R', 'R', 'R', 'L', 'WS', 'ON', 'L', 'R', 'WS', 'R'], 0, [5, 4, 4]], [[0, 1, 2, 3, 4], [6, 7, 8, 5], [9, 10, 11, 12]]), ('partial-repair probe', [[2, 2, 1, 1, 1, 1, 2, 2], ['WS', 'L', 'R', 'WS', 'ON', 'L', 'WS', 'L'], 0, [5, 1, 2]], [[4, 3, 2, 0, 1], [5], [6, 7]]), ('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, 1, 2, 3, 3, 3, 2], ['L', 'ON', 'R', 'R', 'L', 'L', 'R', 'L', 'L'], 0, [5, 3, 1]], [[4, 3, 0, 1, 2], [7, 6, 5], [8]]), ('control layout', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ['WS', 'R', 'R', 'R', 'R', 'L', 'L', 'R', 'WS', 'WS', 'WS', 'WS', 'ON'], 1, [4, 2, 3, 1, 1, 1, 1]], [[3, 0, 1, 2], [5, 4], [8, 7, 6], [9], [10], [11], [12]]), ('control layout', [[1, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 1], ['L', 'L', 'ON', 'L', 'WS', 'L', 'WS', 'L', 'R', 'WS', 'WS', 'R'], 0, [4, 1, 5, 2]], [[1, 2, 3, 0], [4], [5, 6, 7, 8, 9], [11, 10]])], [('regression: trailing whitespace per line', [[4, 4, 4, 4, 3, 2, 2, 1], ['L', 'WS', 'R', 'L', 'WS', 'WS', 'WS', 'R'], 1, [3, 4, 1]], [[0, 1, 2], [6, 5, 4, 3], [7]]), ('regression: trailing whitespace per line', [[2, 2, 2, 2, 4, 4, 4, 3, 2, 2], ['WS', 'WS', 'WS', 'WS', 'L', 'WS', 'L', 'R', 'R', 'WS'], 1, [2, 2, 3, 2, 1]], [[1, 0], [3, 2], [4, 5, 6], [7, 8], [9]]), ('partial-repair probe', [[1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1], ['L', 'WS', 'ON', 'ON', 'WS', 'R', 'L', 'R', 'WS', 'L', 'WS'], 0, [3, 4, 1, 2, 1]], [[2, 1, 0], [6, 5, 4, 3], [7], [9, 8], [10]]), ('partial-repair probe', [[2, 2, 2, 2], ['L', 'R', 'ON', 'ON'], 1, [4]], [[0, 1, 2, 3]]), ('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, 1, 1, 2], ['R', 'L', 'R', 'L', 'ON'], 1, [2, 1, 2]], [[1, 0], [2], [4, 3]]), ('control layout', [[4, 4, 4, 4, 2, 2, 2, 2, 2], ['L', 'WS', 'R', 'R', 'L', 'ON', 'R', 'R', 'R'], 1, [4, 4, 1]], [[0, 1, 2, 3], [4, 5, 6, 7], [8]]), ('control layout', [[4, 4, 4, 4, 4, 1, 1], ['L', 'ON', 'WS', 'L', 'WS', 'WS', 'WS'], 0, [5, 2]], [[0, 1, 2, 3, 4], [5, 6]])], [('regression: trailing whitespace per line', [[2, 2, 2, 2, 2, 2, 2, 2, 2], ['R', 'R', 'L', 'L', 'L', 'WS', 'WS', 'R', 'L'], 1, [3, 3, 1, 1, 1]], [[0, 1, 2], [5, 3, 4], [6], [7], [8]]), ('regression: trailing whitespace per line', [[4, 4, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1], ['R', 'WS', 'L', 'WS', 'WS', 'WS', 'L', 'WS', 'R', 'R', 'L', 'R'], 0, [4, 5, 2, 1]], [[2, 0, 1, 3], [8, 7, 6, 4, 5], [10, 9], [11]]), ('regression: trailing whitespace per line', [[1, 1, 1, 1, 3, 3, 3, 3], ['L', 'WS', 'ON', 'WS', 'WS', 'L', 'ON', 'R'], 0, [5, 3]], [[2, 1, 0, 3, 4], [7, 6, 5]]), ('partial-repair probe', [[3, 3, 1, 1, 1, 1, 4, 3, 1, 1, 4, 4, 4], ['WS', 'R', 'WS', 'WS', 'R', 'R', 'WS', 'L', 'WS', 'R', 'L', 'ON', 'WS'], 0, [5, 3, 5]], [[4, 3, 2, 1, 0], [7, 6, 5], [10, 11, 9, 8, 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', [[3, 3, 3, 3], ['L', 'ON', 'R', 'R'], 1, [3, 1]], [[2, 1, 0], [3]]), ('control layout', [[4, 1, 1, 3, 3, 2, 4, 2, 4, 4], ['R', 'R', 'WS', 'WS', 'L', 'WS', 'ON', 'L', 'L', 'L'], 1, [5, 3, 2]], [[4, 3, 2, 1, 0], [5, 6, 7], [8, 9]]), ('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]])], [('regression: trailing whitespace per line', [[1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0], ['L', 'R', 'L', 'L', 'WS', 'L', 'R', 'ON', 'R', 'L', 'R', 'WS', 'L'], 1, [4, 4, 4, 1]], [[3, 2, 1, 0], [4, 5, 6, 7], [11, 10, 9, 8], [12]]), ('regression: trailing whitespace per line', [[1, 1, 4], ['R', 'WS', 'L'], 0, [2, 1]], [[0, 1], [2]]), ('regression: trailing whitespace per line', [[1, 1, 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 2, 2], ['WS', 'ON', 'WS', 'L', 'L', 'R', 'L', 'R', 'R', 'WS', 'L', 'ON', 'R', 'WS'], 0, [3, 3, 1, 4, 3]], [[1, 0, 2], [3, 4, 5], [6], [7, 8, 9, 10], [11, 12, 13]]), ('partial-repair probe', [[1, 1, 1, 1, 4, 2, 2, 1, 2, 4, 4, 4], ['WS', 'L', 'R', 'WS', 'R', 'R', 'R', 'R', 'WS', 'WS', 'L', 'ON'], 1, [3, 5, 1, 3]], [[2, 1, 0], [7, 4, 5, 6, 3], [8], [9, 10, 11]]), ('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], ['R', 'L'], 1, [1, 1]], [[0], [1]]), ('control layout', [[1, 1], ['L', 'WS'], 0, [2]], [[0, 1]]), ('control layout', [[2, 2, 2, 2], ['R', 'L', 'WS', 'R'], 0, [2, 2]], [[0, 1], [2, 3]])]]
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 |
|---|---|---|---|
| RTL run split across lines | [[1, 0, 2], [5, 4, 3]] | [[1, 0, 2], [5, 4, 3]] | Passed |
| regression: trailing whitespace per line | [[0, 1], [2, 3], [4], [5]] | [[0, 1], [2, 3], [4], [5]] | Passed |
| regression: trailing whitespace per line | [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]] | [[0, 1], [6, 5, 4, 2, 3], [7, 8, 9], [10], [11], [12]] | Passed |
| regression: trailing whitespace per line | [[3, 2, 1, 0], [4, 5], [6]] | [[3, 2, 1, 0], [4, 5], [6]] | Passed |
| control layout | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | [[0, 1, 2, 3], [4], [5, 6, 7, 8]] | Passed |
| control layout | [[0], [1]] | [[0], [1]] | Passed |
| control layout | [[0], [1, 2]] | [[0], [1, 2]] | Passed |
| control layout | [[0, 1], [2, 3, 4, 5, 6]] | [[0, 1], [2, 3, 4, 5, 6]] | Passed |
SHA-256 / b27b35944c999a98342c25d49d42f3d2ac5ad2791e1bdf30114823eb3c98280f
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.357564+00:00.
Case digest / 86caec0d0f1ed98e929e7f52fe6c366a9738efb14a0f772da76395979943f65e