FAILURE MAP
← Case archive

FA-80781 / Bidirectional text layout / Open access

Isolating run sequences: eos after isolate initiator · case 01

Sequences ending in an unmatched initiator take eos from the isolate content.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The initiator check tests the wrong class.

VERIFIED REPAIR

Use the paragraph level after a trailing isolate initiator.

Unsuccessful approach: Applying the rule only to matched initiators misses unmatched ones.

Case contract

Input [classes, levels, paragraph level]. Split into maximal level runs; chain a run ending in a matched isolate initiator (LRI/RLI/FSI) with the run starting at its matching PDI (stack matching; unmatched PDI ignored). For each sequence sos = parity of max(level of first char, level of preceding char or paragraph level); eos = parity of max(level of last char, level of following char or paragraph level), using the paragraph level when the last char is an isolate initiator. Return [[indices, sos, eos]].

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):
    classes, levels, para = x
    n = len(classes)
    match = {}
    stack = []
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            stack.append(i)
        elif c == 'PDI' and stack:
            match[stack.pop()] = i
    runs = []
    for i in range(n):
        if runs and levels[i] == levels[runs[-1][-1]]:
            runs[-1].append(i)
        else:
            runs.append([i])
    start_of = {r[0]: r for r in runs}
    seqs = []
    used = set()
    for r in runs:
        if r[0] in used:
            continue
        seq = list(r)
        used.add(r[0])
        while True:
            tail = seq[-1]
            if classes[tail] not in ('LRI', 'RLI', 'FSI') or tail not in match:
                break
            nxt = start_of.get(match[tail])
            if nxt is None:
                break
            seq.extend(nxt)
            used.add(nxt[0])
        seqs.append(seq)
    out = []
    for seq in seqs:
        first, last = seq[0], seq[-1]
        lv = levels[first]
        prev = levels[first - 1] if first > 0 else para
        sos = 'R' if max(lv, prev) % 2 else 'L'
        if classes[last] == 'PDI':
            nxt_lv = para
        else:
            nxt_lv = levels[last + 1] if last + 1 < n else para
        eos = 'R' if max(levels[last], nxt_lv) % 2 else 'L'
        out.append([seq, sos, eos])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: eos after isolate initiator', [['EN', 'EN', 'LRI', 'ON', 'ON', 'ON', 'L', 'RLI', 'EN'], [2, 2, 1, 2, 2, 2, 2, 2, 3], 1], [[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['PDI', 'ON', 'PDI', 'RLI', 'ON', 'EN', 'ON', 'FSI', 'L', 'R', 'EN', 'ON'], [1, 1, 1, 1, 3, 3, 3, 3, 4, 4, 4, 4], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]), ('regression: eos after isolate initiator', [['EN', 'LRI', 'R', 'LRI', 'R'], [2, 1, 2, 2, 5], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['LRI', 'R', 'R', 'ON', 'ON', 'R', 'PDI', 'PDI', 'EN', 'EN', 'L', 'FSI', 'EN'], [0, 3, 3, 2, 2, 3, 0, 0, 0, 0, 0, 0, 2], 0], [[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]), ('control layout', [['PDI', 'R', 'LRI', 'EN', 'ON', 'R', 'R', 'EN'], [0, 0, 0, 2, 2, 3, 2, 2], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']])], [('regression: eos after isolate initiator', [['EN', 'L', 'R', 'L', 'PDI', 'R', 'PDI', 'R', 'EN', 'ON'], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0], 0], [[[0, 1], 'L', 'R'], [[2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[6, 7, 8, 9], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'FSI', 'FSI', 'L', 'PDI', 'R', 'R', 'PDI', 'EN', 'RLI', 'L', 'PDI', 'PDI'], [1, 1, 2, 4, 2, 2, 3, 1, 2, 1, 3, 1, 1], 1], [[[0, 1, 7], 'R', 'L'], [[2, 4, 5], 'L', 'R'], [[3], 'L', 'L'], [[6], 'R', 'R'], [[8], 'L', 'L'], [[9, 11, 12], 'L', 'R'], [[10], 'R', 'R']]), ('regression: eos after isolate initiator', [['EN', 'PDI', 'RLI', 'L', 'LRI', 'LRI', 'L', 'R', 'L'], [0, 0, 0, 1, 1, 2, 4, 4, 4], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'R', 'R'], [[5], 'L', 'L'], [[6, 7, 8], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'ON', 'RLI'], [1, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('control layout', [['PDI', 'L', 'PDI', 'L', 'LRI', 'ON', 'FSI', 'EN', 'R', 'PDI', 'L', 'PDI', 'EN'], [0, 0, 0, 0, 0, 2, 2, 4, 5, 2, 2, 0, 0], 0], [[[0, 1, 2, 3, 4, 11, 12], 'L', 'L'], [[5, 6, 9, 10], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R']]), ('control layout', [['L', 'ON', 'EN', 'ON', 'EN', 'EN', 'PDI', 'ON', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 0, 0], 0], [[[0, 1, 2, 3, 4, 5, 6, 7, 8], 'L', 'L']])], [('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'RLI', 'EN', 'EN', 'PDI'], [1, 2, 2, 2, 2, 3, 4, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4, 7], 'L', 'L'], [[5], 'R', 'L'], [[6], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'ON', 'ON', 'PDI', 'FSI', 'ON', 'R', 'ON', 'R'], [2, 1, 1, 1, 1, 2, 3, 2, 3], 1], [[[0], 'L', 'L'], [[1, 2, 3, 4], 'L', 'R'], [[5], 'L', 'R'], [[6], 'R', 'R'], [[7], 'R', 'R'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['ON', 'LRI', 'RLI'], [1, 1, 2], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['FSI', 'EN', 'ON', 'L', 'RLI', 'ON', 'PDI'], [0, 2, 2, 2, 2, 3, 2], 0], [[[0], 'L', 'L'], [[1, 2, 3, 4, 6], 'L', 'L'], [[5], 'R', 'R']]), ('control layout', [['LRI', 'PDI', 'ON', 'L', 'EN', 'L', 'R', 'RLI'], [1, 1, 1, 2, 1, 2, 1, 1], 1], [[[0, 1, 2], 'R', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'LRI', 'LRI', 'LRI', 'EN', 'PDI', 'R', 'FSI', 'EN', 'R', 'ON'], [2, 1, 2, 4, 6, 4, 4, 4, 6, 7, 6], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2], 'L', 'L'], [[3, 5, 6, 7], 'L', 'L'], [[4], 'L', 'L'], [[8], 'L', 'R'], [[9], 'R', 'R'], [[10], 'R', 'L']]), ('regression: eos after isolate initiator', [['R', 'R', 'ON', 'LRI', 'LRI', 'RLI', 'ON', 'L', 'R'], [1, 1, 1, 1, 2, 4, 5, 5, 5], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7, 8], 'R', 'R']]), ('regression: eos after isolate initiator', [['PDI', 'RLI', 'ON'], [0, 0, 1], 0], [[[0, 1], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['EN', 'EN', 'ON', 'PDI', 'LRI', 'PDI', 'FSI', 'L', 'R', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 2, 3, 2], 0], [[[0, 1, 2, 3, 4, 5, 6], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R'], [[9], 'R', 'L']]), ('control layout', [['EN', 'R', 'ON', 'EN'], [2, 1, 1, 1], 1], [[[0], 'L', 'L'], [[1, 2, 3], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'PDI', 'EN', 'EN', 'L', 'EN', 'PDI', 'FSI', 'ON', 'R', 'R', 'R', 'FSI'], [1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 3, 3, 2], 1], [[[0, 1], 'R', 'L'], [[2], 'L', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5, 6, 7], 'L', 'R'], [[8], 'L', 'R'], [[9, 10, 11], 'R', 'R'], [[12], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'EN', 'PDI', 'R', 'PDI'], [0, 0, 0, 1, 0], 0], [[[0, 1, 2], 'L', 'R'], [[3], 'R', 'R'], [[4], 'R', 'L']]), ('regression: eos after isolate initiator', [['ON', 'FSI', 'FSI', 'FSI', 'R', 'PDI', 'FSI', 'EN', 'L', 'ON', 'ON', 'EN', 'L', 'L'], [1, 1, 2, 4, 6, 4, 4, 6, 6, 6, 6, 6, 6, 6], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L'], [[3, 5, 6], 'L', 'L'], [[4], 'L', 'L'], [[7, 8, 9, 10, 11, 12, 13], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('control layout', [['R', 'LRI', 'LRI', 'R', 'PDI', 'ON', 'PDI'], [1, 0, 2, 5, 2, 2, 0], 0], [[[0], 'R', 'R'], [[1, 6], 'R', 'L'], [[2, 4, 5], 'L', 'L'], [[3], 'R', 'R']]), ('control layout', [['PDI', 'R', 'FSI'], [0, 0, 0], 0], [[[0, 1, 2], 'L', 'L']])]]
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 fixtureActualExpectedOutcome
regression: eos after isolate initiator[[[0, 1], 'L', 'L'], [[2], 'L', 'L'], [[3, 4, 5, 6, 7], 'L', 'R'], [[8], 'R', 'R']][[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]Failed
regression: eos after isolate initiator[[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'L'], [[4], 'L', 'L']][[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]Failed
regression: eos after isolate initiator[[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'L'], [[8, 9, 10, 11], 'L', 'L']][[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]Failed
regression: eos after isolate initiator[[[0], 'L', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'R', 'R']][[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]Failed
unmatched initiator at end[[[0], 'L', 'R'], [[1, 2], 'R', 'R']][[[0], 'L', 'R'], [[1, 2], 'R', 'R']]Passed
nested isolates[[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']][[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]Passed
control layout[[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']][[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]Passed
control layout[[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']][[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']]Passed

SHA-256 / 0f98b144098cfe524f7a6c0762ca80847cae2d2d4e09fb8bd30a8ef2734efd4b

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    n = len(classes)
    match = {}
    stack = []
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            stack.append(i)
        elif c == 'PDI' and stack:
            match[stack.pop()] = i
    runs = []
    for i in range(n):
        if runs and levels[i] == levels[runs[-1][-1]]:
            runs[-1].append(i)
        else:
            runs.append([i])
    start_of = {r[0]: r for r in runs}
    seqs = []
    used = set()
    for r in runs:
        if r[0] in used:
            continue
        seq = list(r)
        used.add(r[0])
        while True:
            tail = seq[-1]
            if classes[tail] not in ('LRI', 'RLI', 'FSI') or tail not in match:
                break
            nxt = start_of.get(match[tail])
            if nxt is None:
                break
            seq.extend(nxt)
            used.add(nxt[0])
        seqs.append(seq)
    out = []
    for seq in seqs:
        first, last = seq[0], seq[-1]
        lv = levels[first]
        prev = levels[first - 1] if first > 0 else para
        sos = 'R' if max(lv, prev) % 2 else 'L'
        if classes[last] in ('LRI', 'RLI', 'FSI') and last in match:
            nxt_lv = para
        else:
            nxt_lv = levels[last + 1] if last + 1 < n else para
        eos = 'R' if max(levels[last], nxt_lv) % 2 else 'L'
        out.append([seq, sos, eos])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: eos after isolate initiator', [['EN', 'EN', 'LRI', 'ON', 'ON', 'ON', 'L', 'RLI', 'EN'], [2, 2, 1, 2, 2, 2, 2, 2, 3], 1], [[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['PDI', 'ON', 'PDI', 'RLI', 'ON', 'EN', 'ON', 'FSI', 'L', 'R', 'EN', 'ON'], [1, 1, 1, 1, 3, 3, 3, 3, 4, 4, 4, 4], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]), ('regression: eos after isolate initiator', [['EN', 'LRI', 'R', 'LRI', 'R'], [2, 1, 2, 2, 5], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['LRI', 'R', 'R', 'ON', 'ON', 'R', 'PDI', 'PDI', 'EN', 'EN', 'L', 'FSI', 'EN'], [0, 3, 3, 2, 2, 3, 0, 0, 0, 0, 0, 0, 2], 0], [[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]), ('control layout', [['PDI', 'R', 'LRI', 'EN', 'ON', 'R', 'R', 'EN'], [0, 0, 0, 2, 2, 3, 2, 2], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']])], [('regression: eos after isolate initiator', [['EN', 'L', 'R', 'L', 'PDI', 'R', 'PDI', 'R', 'EN', 'ON'], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0], 0], [[[0, 1], 'L', 'R'], [[2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[6, 7, 8, 9], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'FSI', 'FSI', 'L', 'PDI', 'R', 'R', 'PDI', 'EN', 'RLI', 'L', 'PDI', 'PDI'], [1, 1, 2, 4, 2, 2, 3, 1, 2, 1, 3, 1, 1], 1], [[[0, 1, 7], 'R', 'L'], [[2, 4, 5], 'L', 'R'], [[3], 'L', 'L'], [[6], 'R', 'R'], [[8], 'L', 'L'], [[9, 11, 12], 'L', 'R'], [[10], 'R', 'R']]), ('regression: eos after isolate initiator', [['EN', 'PDI', 'RLI', 'L', 'LRI', 'LRI', 'L', 'R', 'L'], [0, 0, 0, 1, 1, 2, 4, 4, 4], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'R', 'R'], [[5], 'L', 'L'], [[6, 7, 8], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'ON', 'RLI'], [1, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('control layout', [['PDI', 'L', 'PDI', 'L', 'LRI', 'ON', 'FSI', 'EN', 'R', 'PDI', 'L', 'PDI', 'EN'], [0, 0, 0, 0, 0, 2, 2, 4, 5, 2, 2, 0, 0], 0], [[[0, 1, 2, 3, 4, 11, 12], 'L', 'L'], [[5, 6, 9, 10], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R']]), ('control layout', [['L', 'ON', 'EN', 'ON', 'EN', 'EN', 'PDI', 'ON', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 0, 0], 0], [[[0, 1, 2, 3, 4, 5, 6, 7, 8], 'L', 'L']])], [('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'RLI', 'EN', 'EN', 'PDI'], [1, 2, 2, 2, 2, 3, 4, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4, 7], 'L', 'L'], [[5], 'R', 'L'], [[6], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'ON', 'ON', 'PDI', 'FSI', 'ON', 'R', 'ON', 'R'], [2, 1, 1, 1, 1, 2, 3, 2, 3], 1], [[[0], 'L', 'L'], [[1, 2, 3, 4], 'L', 'R'], [[5], 'L', 'R'], [[6], 'R', 'R'], [[7], 'R', 'R'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['ON', 'LRI', 'RLI'], [1, 1, 2], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['FSI', 'EN', 'ON', 'L', 'RLI', 'ON', 'PDI'], [0, 2, 2, 2, 2, 3, 2], 0], [[[0], 'L', 'L'], [[1, 2, 3, 4, 6], 'L', 'L'], [[5], 'R', 'R']]), ('control layout', [['LRI', 'PDI', 'ON', 'L', 'EN', 'L', 'R', 'RLI'], [1, 1, 1, 2, 1, 2, 1, 1], 1], [[[0, 1, 2], 'R', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'LRI', 'LRI', 'LRI', 'EN', 'PDI', 'R', 'FSI', 'EN', 'R', 'ON'], [2, 1, 2, 4, 6, 4, 4, 4, 6, 7, 6], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2], 'L', 'L'], [[3, 5, 6, 7], 'L', 'L'], [[4], 'L', 'L'], [[8], 'L', 'R'], [[9], 'R', 'R'], [[10], 'R', 'L']]), ('regression: eos after isolate initiator', [['R', 'R', 'ON', 'LRI', 'LRI', 'RLI', 'ON', 'L', 'R'], [1, 1, 1, 1, 2, 4, 5, 5, 5], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7, 8], 'R', 'R']]), ('regression: eos after isolate initiator', [['PDI', 'RLI', 'ON'], [0, 0, 1], 0], [[[0, 1], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['EN', 'EN', 'ON', 'PDI', 'LRI', 'PDI', 'FSI', 'L', 'R', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 2, 3, 2], 0], [[[0, 1, 2, 3, 4, 5, 6], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R'], [[9], 'R', 'L']]), ('control layout', [['EN', 'R', 'ON', 'EN'], [2, 1, 1, 1], 1], [[[0], 'L', 'L'], [[1, 2, 3], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'PDI', 'EN', 'EN', 'L', 'EN', 'PDI', 'FSI', 'ON', 'R', 'R', 'R', 'FSI'], [1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 3, 3, 2], 1], [[[0, 1], 'R', 'L'], [[2], 'L', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5, 6, 7], 'L', 'R'], [[8], 'L', 'R'], [[9, 10, 11], 'R', 'R'], [[12], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'EN', 'PDI', 'R', 'PDI'], [0, 0, 0, 1, 0], 0], [[[0, 1, 2], 'L', 'R'], [[3], 'R', 'R'], [[4], 'R', 'L']]), ('regression: eos after isolate initiator', [['ON', 'FSI', 'FSI', 'FSI', 'R', 'PDI', 'FSI', 'EN', 'L', 'ON', 'ON', 'EN', 'L', 'L'], [1, 1, 2, 4, 6, 4, 4, 6, 6, 6, 6, 6, 6, 6], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L'], [[3, 5, 6], 'L', 'L'], [[4], 'L', 'L'], [[7, 8, 9, 10, 11, 12, 13], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('control layout', [['R', 'LRI', 'LRI', 'R', 'PDI', 'ON', 'PDI'], [1, 0, 2, 5, 2, 2, 0], 0], [[[0], 'R', 'R'], [[1, 6], 'R', 'L'], [[2, 4, 5], 'L', 'L'], [[3], 'R', 'R']]), ('control layout', [['PDI', 'R', 'FSI'], [0, 0, 0], 0], [[[0, 1, 2], 'L', 'L']])]]
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 fixtureActualExpectedOutcome
regression: eos after isolate initiator[[[0, 1], 'L', 'L'], [[2], 'L', 'L'], [[3, 4, 5, 6, 7], 'L', 'R'], [[8], 'R', 'R']][[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]Failed
regression: eos after isolate initiator[[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'L'], [[4], 'L', 'L']][[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]Failed
regression: eos after isolate initiator[[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'L'], [[8, 9, 10, 11], 'L', 'L']][[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]Failed
regression: eos after isolate initiator[[[0], 'L', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'R', 'R']][[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]Failed
unmatched initiator at end[[[0], 'L', 'R'], [[1, 2], 'R', 'R']][[[0], 'L', 'R'], [[1, 2], 'R', 'R']]Passed
nested isolates[[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']][[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]Passed
control layout[[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']][[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]Passed
control layout[[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']][[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']]Passed

SHA-256 / 816999e0a599a31823d105d0d6f1fa3d8bca6f0e77668f2ff35c3b072db3e336

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    n = len(classes)
    match = {}
    stack = []
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            stack.append(i)
        elif c == 'PDI' and stack:
            match[stack.pop()] = i
    runs = []
    for i in range(n):
        if runs and levels[i] == levels[runs[-1][-1]]:
            runs[-1].append(i)
        else:
            runs.append([i])
    start_of = {r[0]: r for r in runs}
    seqs = []
    used = set()
    for r in runs:
        if r[0] in used:
            continue
        seq = list(r)
        used.add(r[0])
        while True:
            tail = seq[-1]
            if classes[tail] not in ('LRI', 'RLI', 'FSI') or tail not in match:
                break
            nxt = start_of.get(match[tail])
            if nxt is None:
                break
            seq.extend(nxt)
            used.add(nxt[0])
        seqs.append(seq)
    out = []
    for seq in seqs:
        first, last = seq[0], seq[-1]
        lv = levels[first]
        prev = levels[first - 1] if first > 0 else para
        sos = 'R' if max(lv, prev) % 2 else 'L'
        if classes[last] in ('LRI', 'RLI', 'FSI'):
            nxt_lv = para
        else:
            nxt_lv = levels[last + 1] if last + 1 < n else para
        eos = 'R' if max(levels[last], nxt_lv) % 2 else 'L'
        out.append([seq, sos, eos])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: eos after isolate initiator', [['EN', 'EN', 'LRI', 'ON', 'ON', 'ON', 'L', 'RLI', 'EN'], [2, 2, 1, 2, 2, 2, 2, 2, 3], 1], [[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['PDI', 'ON', 'PDI', 'RLI', 'ON', 'EN', 'ON', 'FSI', 'L', 'R', 'EN', 'ON'], [1, 1, 1, 1, 3, 3, 3, 3, 4, 4, 4, 4], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]), ('regression: eos after isolate initiator', [['EN', 'LRI', 'R', 'LRI', 'R'], [2, 1, 2, 2, 5], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['LRI', 'R', 'R', 'ON', 'ON', 'R', 'PDI', 'PDI', 'EN', 'EN', 'L', 'FSI', 'EN'], [0, 3, 3, 2, 2, 3, 0, 0, 0, 0, 0, 0, 2], 0], [[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]), ('control layout', [['PDI', 'R', 'LRI', 'EN', 'ON', 'R', 'R', 'EN'], [0, 0, 0, 2, 2, 3, 2, 2], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']])], [('regression: eos after isolate initiator', [['EN', 'L', 'R', 'L', 'PDI', 'R', 'PDI', 'R', 'EN', 'ON'], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0], 0], [[[0, 1], 'L', 'R'], [[2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[6, 7, 8, 9], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'FSI', 'FSI', 'L', 'PDI', 'R', 'R', 'PDI', 'EN', 'RLI', 'L', 'PDI', 'PDI'], [1, 1, 2, 4, 2, 2, 3, 1, 2, 1, 3, 1, 1], 1], [[[0, 1, 7], 'R', 'L'], [[2, 4, 5], 'L', 'R'], [[3], 'L', 'L'], [[6], 'R', 'R'], [[8], 'L', 'L'], [[9, 11, 12], 'L', 'R'], [[10], 'R', 'R']]), ('regression: eos after isolate initiator', [['EN', 'PDI', 'RLI', 'L', 'LRI', 'LRI', 'L', 'R', 'L'], [0, 0, 0, 1, 1, 2, 4, 4, 4], 0], [[[0, 1, 2], 'L', 'L'], [[3, 4], 'R', 'R'], [[5], 'L', 'L'], [[6, 7, 8], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'ON', 'RLI'], [1, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('control layout', [['PDI', 'L', 'PDI', 'L', 'LRI', 'ON', 'FSI', 'EN', 'R', 'PDI', 'L', 'PDI', 'EN'], [0, 0, 0, 0, 0, 2, 2, 4, 5, 2, 2, 0, 0], 0], [[[0, 1, 2, 3, 4, 11, 12], 'L', 'L'], [[5, 6, 9, 10], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R']]), ('control layout', [['L', 'ON', 'EN', 'ON', 'EN', 'EN', 'PDI', 'ON', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 0, 0], 0], [[[0, 1, 2, 3, 4, 5, 6, 7, 8], 'L', 'L']])], [('regression: eos after isolate initiator', [['R', 'L', 'PDI', 'FSI', 'ON'], [1, 2, 1, 1, 2], 1], [[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'RLI', 'EN', 'EN', 'PDI'], [1, 2, 2, 2, 2, 3, 4, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4, 7], 'L', 'L'], [[5], 'R', 'L'], [[6], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'ON', 'ON', 'PDI', 'FSI', 'ON', 'R', 'ON', 'R'], [2, 1, 1, 1, 1, 2, 3, 2, 3], 1], [[[0], 'L', 'L'], [[1, 2, 3, 4], 'L', 'R'], [[5], 'L', 'R'], [[6], 'R', 'R'], [[7], 'R', 'R'], [[8], 'R', 'R']]), ('regression: eos after isolate initiator', [['ON', 'LRI', 'RLI'], [1, 1, 2], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['FSI', 'EN', 'ON', 'L', 'RLI', 'ON', 'PDI'], [0, 2, 2, 2, 2, 3, 2], 0], [[[0], 'L', 'L'], [[1, 2, 3, 4, 6], 'L', 'L'], [[5], 'R', 'R']]), ('control layout', [['LRI', 'PDI', 'ON', 'L', 'EN', 'L', 'R', 'RLI'], [1, 1, 1, 2, 1, 2, 1, 1], 1], [[[0, 1, 2], 'R', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('regression: eos after isolate initiator', [['L', 'LRI', 'LRI', 'LRI', 'EN', 'PDI', 'R', 'FSI', 'EN', 'R', 'ON'], [2, 1, 2, 4, 6, 4, 4, 4, 6, 7, 6], 1], [[[0], 'L', 'L'], [[1], 'L', 'R'], [[2], 'L', 'L'], [[3, 5, 6, 7], 'L', 'L'], [[4], 'L', 'L'], [[8], 'L', 'R'], [[9], 'R', 'R'], [[10], 'R', 'L']]), ('regression: eos after isolate initiator', [['R', 'R', 'ON', 'LRI', 'LRI', 'RLI', 'ON', 'L', 'R'], [1, 1, 1, 1, 2, 4, 5, 5, 5], 1], [[[0, 1, 2, 3], 'R', 'R'], [[4], 'L', 'L'], [[5], 'L', 'L'], [[6, 7, 8], 'R', 'R']]), ('regression: eos after isolate initiator', [['PDI', 'RLI', 'ON'], [0, 0, 1], 0], [[[0, 1], 'L', 'L'], [[2], 'R', 'R']]), ('unmatched initiator at end', [['L', 'R', 'RLI'], [0, 1, 1], 0], [[[0], 'L', 'R'], [[1, 2], 'R', 'R']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('control layout', [['EN', 'EN', 'ON', 'PDI', 'LRI', 'PDI', 'FSI', 'L', 'R', 'RLI'], [0, 0, 0, 0, 0, 0, 0, 2, 3, 2], 0], [[[0, 1, 2, 3, 4, 5, 6], 'L', 'L'], [[7], 'L', 'R'], [[8], 'R', 'R'], [[9], 'R', 'L']]), ('control layout', [['EN', 'R', 'ON', 'EN'], [2, 1, 1, 1], 1], [[[0], 'L', 'L'], [[1, 2, 3], 'L', 'R']])], [('regression: eos after isolate initiator', [['LRI', 'PDI', 'EN', 'EN', 'L', 'EN', 'PDI', 'FSI', 'ON', 'R', 'R', 'R', 'FSI'], [1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 3, 3, 2], 1], [[[0, 1], 'R', 'L'], [[2], 'L', 'L'], [[3], 'L', 'L'], [[4], 'L', 'L'], [[5, 6, 7], 'L', 'R'], [[8], 'L', 'R'], [[9, 10, 11], 'R', 'R'], [[12], 'R', 'L']]), ('regression: eos after isolate initiator', [['EN', 'EN', 'PDI', 'R', 'PDI'], [0, 0, 0, 1, 0], 0], [[[0, 1, 2], 'L', 'R'], [[3], 'R', 'R'], [[4], 'R', 'L']]), ('regression: eos after isolate initiator', [['ON', 'FSI', 'FSI', 'FSI', 'R', 'PDI', 'FSI', 'EN', 'L', 'ON', 'ON', 'EN', 'L', 'L'], [1, 1, 2, 4, 6, 4, 4, 6, 6, 6, 6, 6, 6, 6], 1], [[[0, 1], 'R', 'R'], [[2], 'L', 'L'], [[3, 5, 6], 'L', 'L'], [[4], 'L', 'L'], [[7, 8, 9, 10, 11, 12, 13], 'L', 'L']]), ('regression: eos after isolate initiator', [['LRI', 'L', 'ON', 'ON', 'R'], [1, 2, 2, 2, 2], 1], [[[0], 'R', 'R'], [[1, 2, 3, 4], 'L', 'L']]), ('nested isolates', [['R', 'LRI', 'L', 'RLI', 'R', 'PDI', 'PDI', 'R'], [1, 1, 2, 2, 3, 2, 1, 1], 1], [[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]), ('isolate joins outer run', [['L', 'RLI', 'R', 'PDI', 'L'], [0, 0, 1, 0, 0], 0], [[[0, 1, 3, 4], 'L', 'L'], [[2], 'R', 'R']]), ('control layout', [['R', 'LRI', 'LRI', 'R', 'PDI', 'ON', 'PDI'], [1, 0, 2, 5, 2, 2, 0], 0], [[[0], 'R', 'R'], [[1, 6], 'R', 'L'], [[2, 4, 5], 'L', 'L'], [[3], 'R', 'R']]), ('control layout', [['PDI', 'R', 'FSI'], [0, 0, 0], 0], [[[0, 1, 2], 'L', 'L']])]]
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 fixtureActualExpectedOutcome
regression: eos after isolate initiator[[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']][[[0, 1], 'L', 'L'], [[2], 'L', 'R'], [[3, 4, 5, 6, 7], 'L', 'L'], [[8], 'R', 'R']]Passed
regression: eos after isolate initiator[[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']][[[0], 'R', 'L'], [[1], 'L', 'L'], [[2, 3], 'L', 'R'], [[4], 'L', 'L']]Passed
regression: eos after isolate initiator[[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']][[[0, 1, 2, 3], 'R', 'R'], [[4, 5, 6, 7], 'R', 'R'], [[8, 9, 10, 11], 'L', 'L']]Passed
regression: eos after isolate initiator[[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']][[[0], 'L', 'L'], [[1], 'L', 'R'], [[2, 3], 'L', 'L'], [[4], 'R', 'R']]Passed
unmatched initiator at end[[[0], 'L', 'R'], [[1, 2], 'R', 'R']][[[0], 'L', 'R'], [[1, 2], 'R', 'R']]Passed
nested isolates[[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']][[[0, 1, 6, 7], 'R', 'R'], [[2, 3, 5], 'L', 'L'], [[4], 'R', 'R']]Passed
control layout[[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']][[[0, 6, 7, 8, 9, 10, 11], 'L', 'L'], [[1, 2], 'R', 'R'], [[3, 4], 'R', 'R'], [[5], 'R', 'R'], [[12], 'L', 'L']]Passed
control layout[[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']][[[0, 1, 2], 'L', 'L'], [[3, 4], 'L', 'R'], [[5], 'R', 'R'], [[6, 7], 'R', 'L']]Passed

SHA-256 / 824905a42249eecf68738aed5eb863acaeb466d74ae4cb1ca08cffa81fa05c96

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.967933+00:00.

Case digest / 1767a56669c68401f7a43f41643c6044872373291a5c0939bfd3ab798c7b3715