broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'B', 'S')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            while j < n and t[j] in NI:
                j += 1
            before = sos if i == 0 else strong(t[i - 1])
            after = sos if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: end-of-sequence context', [['ON', 'L', 'S', 'L', 'R', 'L', 'R', 'EN', 'R', 'R', 'B'], 'L', 'R', 2], ['L', 'L', 'L', 'L', 'R', 'L', 'R', 'EN', 'R', 'R', 'R']), ('regression: end-of-sequence context', [['ON', 'R', 'AN', 'L', 'EN', 'ON'], 'R', 'L', 2], ['R', 'R', 'AN', 'L', 'EN', 'L']), ('partial-repair probe', [['R', 'S', 'WS', 'L', 'ON', 'AN', 'B', 'R', 'ON'], 'R', 'R', 2], ['R', 'L', 'L', 'L', 'L', 'AN', 'R', 'R', 'R']), ('partial-repair probe', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['ON', 'AN', 'R', 'R'], 'L', 'L', 2], ['L', 'AN', 'R', 'R']), ('control layout', [['ON', 'WS', 'EN', 'WS', 'EN', 'R', 'R', 'L', 'L', 'EN'], 'R', 'L', 3], ['R', 'R', 'EN', 'R', 'EN', 'R', 'R', 'L', 'L', 'EN'])], [('regression: end-of-sequence context', [['AN', 'AN', 'EN', 'ON', 'WS', 'WS'], 'R', 'L', 2], ['AN', 'AN', 'EN', 'L', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'L', 'R', 'B', 'WS', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['WS', 'S', 'WS', 'R', 'AN', 'WS', 'L', 'ON'], 'L', 'L', 1], ['R', 'R', 'R', 'R', 'AN', 'R', 'L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['EN', 'L', 'ON', 'WS', 'ON', 'AN', 'R', 'EN', 'AN'], 'R', 'L', 2], ['EN', 'L', 'L', 'L', 'L', 'AN', 'R', 'EN', 'AN']), ('control layout', [['S', 'L', 'ON', 'ON'], 'L', 'R', 0], ['L', 'L', 'L', 'L'])], [('regression: end-of-sequence context', [['R', 'B', 'WS', 'R', 'R', 'AN', 'L', 'R', 'B', 'L', 'ON'], 'R', 'L', 1], ['R', 'R', 'R', 'R', 'R', 'AN', 'L', 'R', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'R', 'AN', 'L', 'EN', 'ON'], 'R', 'L', 2], ['R', 'R', 'AN', 'L', 'EN', 'L']), ('partial-repair probe', [['WS', 'S', 'WS', 'R', 'AN', 'WS', 'L', 'ON'], 'L', 'L', 1], ['R', 'R', 'R', 'R', 'AN', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['ON', 'WS', 'WS', 'AN', 'B', 'ON', 'WS', 'R', 'EN'], 'L', 'L', 1], ['R', 'R', 'R', 'AN', 'R', 'R', 'R', 'R', 'EN']), ('control layout', [['AN', 'S', 'L', 'ON', 'B', 'R', 'S', 'AN', 'R', 'L'], 'R', 'L', 1], ['AN', 'R', 'L', 'R', 'R', 'R', 'R', 'AN', 'R', 'L'])], [('regression: end-of-sequence context', [['AN', 'AN', 'EN', 'ON', 'WS', 'WS'], 'R', 'L', 2], ['AN', 'AN', 'EN', 'L', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'AN', 'WS', 'L', 'ON'], 'L', 'R', 1], ['R', 'AN', 'R', 'L', 'R']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['S', 'B', 'B'], 'R', 'R', 2], ['R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['WS', 'EN', 'L', 'WS', 'EN', 'B', 'R'], 'R', 'R', 0], ['R', 'EN', 'L', 'L', 'EN', 'R', 'R']), ('control layout', [['L', 'B', 'R', 'S', 'AN', 'L', 'AN', 'L', 'WS', 'ON', 'R'], 'L', 'L', 0], ['L', 'L', 'R', 'R', 'AN', 'L', 'AN', 'L', 'L', 'L', 'R'])], [('regression: end-of-sequence context', [['B', 'B', 'ON', 'L', 'L', 'S'], 'L', 'R', 3], ['L', 'L', 'L', 'L', 'L', 'R']), ('regression: end-of-sequence context', [['B', 'S', 'B', 'AN', 'R', 'AN', 'S', 'ON', 'EN', 'ON'], 'R', 'L', 0], ['R', 'R', 'R', 'AN', 'R', 'AN', 'R', 'R', 'EN', 'L']), ('partial-repair probe', [['EN', 'R', 'EN', 'ON', 'L', 'WS', 'ON', 'WS', 'WS'], 'L', 'L', 3], ['EN', 'R', 'EN', 'R', 'L', 'L', 'L', 'L', 'L']), ('partial-repair probe', [['R', 'R', 'S'], 'R', 'R', 0], ['R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['AN', 'L', 'R', 'R', 'EN', 'ON', 'R'], 'L', 'R', 1], ['AN', 'L', 'R', 'R', 'EN', 'R', 'R']), ('control layout', [['R', 'WS', 'L', 'EN', 'ON', 'WS'], 'L', 'R', 1], ['R', 'R', 'L', 'EN', 'R', 'R'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'B', 'S')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            while j < n and t[j] in NI:
                j += 1
            before = sos if i == 0 else strong(t[i - 1])
            after = e if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: end-of-sequence context', [['ON', 'L', 'S', 'L', 'R', 'L', 'R', 'EN', 'R', 'R', 'B'], 'L', 'R', 2], ['L', 'L', 'L', 'L', 'R', 'L', 'R', 'EN', 'R', 'R', 'R']), ('regression: end-of-sequence context', [['ON', 'R', 'AN', 'L', 'EN', 'ON'], 'R', 'L', 2], ['R', 'R', 'AN', 'L', 'EN', 'L']), ('partial-repair probe', [['R', 'S', 'WS', 'L', 'ON', 'AN', 'B', 'R', 'ON'], 'R', 'R', 2], ['R', 'L', 'L', 'L', 'L', 'AN', 'R', 'R', 'R']), ('partial-repair probe', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['ON', 'AN', 'R', 'R'], 'L', 'L', 2], ['L', 'AN', 'R', 'R']), ('control layout', [['ON', 'WS', 'EN', 'WS', 'EN', 'R', 'R', 'L', 'L', 'EN'], 'R', 'L', 3], ['R', 'R', 'EN', 'R', 'EN', 'R', 'R', 'L', 'L', 'EN'])], [('regression: end-of-sequence context', [['AN', 'AN', 'EN', 'ON', 'WS', 'WS'], 'R', 'L', 2], ['AN', 'AN', 'EN', 'L', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'L', 'R', 'B', 'WS', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['WS', 'S', 'WS', 'R', 'AN', 'WS', 'L', 'ON'], 'L', 'L', 1], ['R', 'R', 'R', 'R', 'AN', 'R', 'L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['EN', 'L', 'ON', 'WS', 'ON', 'AN', 'R', 'EN', 'AN'], 'R', 'L', 2], ['EN', 'L', 'L', 'L', 'L', 'AN', 'R', 'EN', 'AN']), ('control layout', [['S', 'L', 'ON', 'ON'], 'L', 'R', 0], ['L', 'L', 'L', 'L'])], [('regression: end-of-sequence context', [['R', 'B', 'WS', 'R', 'R', 'AN', 'L', 'R', 'B', 'L', 'ON'], 'R', 'L', 1], ['R', 'R', 'R', 'R', 'R', 'AN', 'L', 'R', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'R', 'AN', 'L', 'EN', 'ON'], 'R', 'L', 2], ['R', 'R', 'AN', 'L', 'EN', 'L']), ('partial-repair probe', [['WS', 'S', 'WS', 'R', 'AN', 'WS', 'L', 'ON'], 'L', 'L', 1], ['R', 'R', 'R', 'R', 'AN', 'R', 'L', 'L']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['ON', 'WS', 'WS', 'AN', 'B', 'ON', 'WS', 'R', 'EN'], 'L', 'L', 1], ['R', 'R', 'R', 'AN', 'R', 'R', 'R', 'R', 'EN']), ('control layout', [['AN', 'S', 'L', 'ON', 'B', 'R', 'S', 'AN', 'R', 'L'], 'R', 'L', 1], ['AN', 'R', 'L', 'R', 'R', 'R', 'R', 'AN', 'R', 'L'])], [('regression: end-of-sequence context', [['AN', 'AN', 'EN', 'ON', 'WS', 'WS'], 'R', 'L', 2], ['AN', 'AN', 'EN', 'L', 'L', 'L']), ('regression: end-of-sequence context', [['ON', 'AN', 'WS', 'L', 'ON'], 'L', 'R', 1], ['R', 'AN', 'R', 'L', 'R']), ('regression: end-of-sequence context', [['S', 'B', 'L', 'EN', 'EN', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'R', 'L', 'EN', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['S', 'B', 'B'], 'R', 'R', 2], ['R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['WS', 'EN', 'L', 'WS', 'EN', 'B', 'R'], 'R', 'R', 0], ['R', 'EN', 'L', 'L', 'EN', 'R', 'R']), ('control layout', [['L', 'B', 'R', 'S', 'AN', 'L', 'AN', 'L', 'WS', 'ON', 'R'], 'L', 'L', 0], ['L', 'L', 'R', 'R', 'AN', 'L', 'AN', 'L', 'L', 'L', 'R'])], [('regression: end-of-sequence context', [['B', 'B', 'ON', 'L', 'L', 'S'], 'L', 'R', 3], ['L', 'L', 'L', 'L', 'L', 'R']), ('regression: end-of-sequence context', [['B', 'S', 'B', 'AN', 'R', 'AN', 'S', 'ON', 'EN', 'ON'], 'R', 'L', 0], ['R', 'R', 'R', 'AN', 'R', 'AN', 'R', 'R', 'EN', 'L']), ('partial-repair probe', [['EN', 'R', 'EN', 'ON', 'L', 'WS', 'ON', 'WS', 'WS'], 'L', 'L', 3], ['EN', 'R', 'EN', 'R', 'L', 'L', 'L', 'L', 'L']), ('partial-repair probe', [['R', 'R', 'S'], 'R', 'R', 0], ['R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['AN', 'L', 'R', 'R', 'EN', 'ON', 'R'], 'L', 'R', 1], ['AN', 'L', 'R', 'R', 'EN', 'R', 'R']), ('control layout', [['R', 'WS', 'L', 'EN', 'ON', 'WS'], 'L', 'R', 1], ['R', 'R', 'L', 'EN', 'R', 'R'])]]
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)

prompt:
Trailing neutrals resolve against the wrong edge.

Input [resolved weak classes, sos, eos, embedding level]. A maximal run of neutrals (ON, WS, B, S) takes the direction of its surrounding strong types when both sides agree (EN and AN count as R; sos/eos at the edges); otherwise the embedding direction (L for even level, R for odd). Return classes.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'B', 'S')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            j = i + 1
            before = sos if i == 0 else strong(t[i - 1])
            after = eos if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['EN', 'AN', 'L', 'EN', 'AN', 'AN', 'L', 'WS', 'ON', 'ON'], 'L', 'L', 3], ['EN', 'AN', 'L', 'EN', 'AN', 'AN', 'L', 'L', 'L', 'L']), ('regression: neutral run grouping', [['WS', 'ON', 'WS', 'S', 'WS', 'EN', 'R'], 'R', 'R', 2], ['R', 'R', 'R', 'R', 'R', 'EN', 'R']), ('regression: neutral run grouping', [['B', 'R', 'R', 'EN', 'WS', 'B', 'AN', 'AN'], 'L', 'L', 0], ['L', 'R', 'R', 'EN', 'R', 'R', 'AN', 'AN']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['WS', 'L', 'L', 'S', 'ON', 'R', 'R', 'L', 'L'], 'R', 'L', 3], ['R', 'L', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('control layout', [['R', 'R', 'L', 'AN', 'ON', 'L', 'L', 'AN'], 'L', 'R', 3], ['R', 'R', 'L', 'AN', 'R', 'L', 'L', 'AN'])], [('regression: neutral run grouping', [['WS', 'L', 'ON', 'B', 'L', 'ON', 'WS', 'WS'], 'R', 'R', 3], ['R', 'L', 'L', 'L', 'L', 'R', 'R', 'R']), ('regression: neutral run grouping', [['WS', 'WS', 'ON', 'AN', 'WS', 'L', 'AN', 'B', 'ON', 'B', 'B'], 'R', 'R', 0], ['R', 'R', 'R', 'AN', 'L', 'L', 'AN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'ON', 'AN', 'ON', 'S', 'AN', 'WS', 'L', 'AN'], 'R', 'L', 2], ['R', 'R', 'AN', 'R', 'R', 'AN', 'L', 'L', 'AN']), ('regression: neutral run grouping', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['EN', 'EN', 'WS', 'ON', 'R', 'L', 'ON', 'R', 'R', 'L', 'ON'], 'R', 'R', 1], ['EN', 'EN', 'R', 'R', 'R', 'L', 'R', 'R', 'R', 'L', 'R']), ('control layout', [['L', 'WS', 'B', 'B', 'B', 'L', 'L'], 'R', 'R', 0], ['L', 'L', 'L', 'L', 'L', 'L', 'L'])], [('regression: neutral run grouping', [['B', 'L', 'L', 'EN', 'WS', 'ON', 'R', 'R', 'R'], 'L', 'R', 2], ['L', 'L', 'L', 'EN', 'R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['WS', 'L', 'AN', 'B', 'R', 'ON', 'ON', 'WS'], 'L', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'EN', 'B', 'WS', 'WS', 'S'], 'R', 'R', 2], ['R', 'EN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['ON', 'R', 'R', 'R', 'L', 'R', 'AN', 'WS', 'ON', 'B', 'AN'], 'L', 'R', 2], ['L', 'R', 'R', 'R', 'L', 'R', 'AN', 'R', 'R', 'R', 'AN']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['AN', 'L', 'AN', 'L', 'ON', 'R', 'AN', 'AN', 'B', 'L'], 'L', 'L', 3], ['AN', 'L', 'AN', 'L', 'R', 'R', 'AN', 'AN', 'R', 'L']), ('control layout', [['L', 'S', 'EN', 'AN', 'L', 'ON'], 'L', 'L', 2], ['L', 'L', 'EN', 'AN', 'L', 'L'])], [('regression: neutral run grouping', [['R', 'AN', 'B', 'ON', 'WS', 'WS', 'AN', 'WS'], 'L', 'L', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'AN', 'L']), ('regression: neutral run grouping', [['S', 'B', 'B'], 'R', 'R', 2], ['R', 'R', 'R']), ('regression: neutral run grouping', [['AN', 'WS', 'ON', 'R', 'ON', 'EN', 'ON', 'L', 'S', 'R', 'AN'], 'L', 'L', 0], ['AN', 'R', 'R', 'R', 'R', 'EN', 'L', 'L', 'L', 'R', 'AN']), ('regression: neutral run grouping', [['B', 'WS', 'R', 'S', 'R'], 'R', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['R', 'ON', 'ON', 'R', 'EN'], 'L', 'R', 3], ['R', 'R', 'R', 'R', 'EN']), ('control layout', [['L', 'WS', 'WS', 'AN'], 'R', 'L', 2], ['L', 'L', 'L', 'AN'])], [('regression: neutral run grouping', [['WS', 'L', 'ON', 'L', 'R', 'S', 'S'], 'L', 'R', 0], ['L', 'L', 'L', 'L', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'R', 'R', 'ON', 'B', 'AN', 'AN', 'ON', 'L'], 'R', 'L', 0], ['R', 'R', 'R', 'R', 'R', 'AN', 'AN', 'L', 'L']), ('regression: neutral run grouping', [['WS', 'L', 'WS', 'AN', 'WS', 'S', 'S', 'S'], 'L', 'R', 0], ['L', 'L', 'L', 'AN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'AN', 'B', 'ON', 'WS', 'WS', 'AN', 'WS'], 'L', 'L', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'AN', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['ON', 'L', 'R', 'B', 'WS', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('control layout', [['ON', 'EN', 'ON', 'R', 'B', 'ON'], 'R', 'L', 1], ['R', 'EN', 'R', 'R', 'R', 'R'])]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'B', 'S')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            while j < n and t[j] in NI and t[j] == t[i]:
                j += 1
            before = sos if i == 0 else strong(t[i - 1])
            after = eos if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['EN', 'AN', 'L', 'EN', 'AN', 'AN', 'L', 'WS', 'ON', 'ON'], 'L', 'L', 3], ['EN', 'AN', 'L', 'EN', 'AN', 'AN', 'L', 'L', 'L', 'L']), ('regression: neutral run grouping', [['WS', 'ON', 'WS', 'S', 'WS', 'EN', 'R'], 'R', 'R', 2], ['R', 'R', 'R', 'R', 'R', 'EN', 'R']), ('regression: neutral run grouping', [['B', 'R', 'R', 'EN', 'WS', 'B', 'AN', 'AN'], 'L', 'L', 0], ['L', 'R', 'R', 'EN', 'R', 'R', 'AN', 'AN']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['WS', 'L', 'L', 'S', 'ON', 'R', 'R', 'L', 'L'], 'R', 'L', 3], ['R', 'L', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('control layout', [['R', 'R', 'L', 'AN', 'ON', 'L', 'L', 'AN'], 'L', 'R', 3], ['R', 'R', 'L', 'AN', 'R', 'L', 'L', 'AN'])], [('regression: neutral run grouping', [['WS', 'L', 'ON', 'B', 'L', 'ON', 'WS', 'WS'], 'R', 'R', 3], ['R', 'L', 'L', 'L', 'L', 'R', 'R', 'R']), ('regression: neutral run grouping', [['WS', 'WS', 'ON', 'AN', 'WS', 'L', 'AN', 'B', 'ON', 'B', 'B'], 'R', 'R', 0], ['R', 'R', 'R', 'AN', 'L', 'L', 'AN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'ON', 'AN', 'ON', 'S', 'AN', 'WS', 'L', 'AN'], 'R', 'L', 2], ['R', 'R', 'AN', 'R', 'R', 'AN', 'L', 'L', 'AN']), ('regression: neutral run grouping', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['EN', 'EN', 'WS', 'ON', 'R', 'L', 'ON', 'R', 'R', 'L', 'ON'], 'R', 'R', 1], ['EN', 'EN', 'R', 'R', 'R', 'L', 'R', 'R', 'R', 'L', 'R']), ('control layout', [['L', 'WS', 'B', 'B', 'B', 'L', 'L'], 'R', 'R', 0], ['L', 'L', 'L', 'L', 'L', 'L', 'L'])], [('regression: neutral run grouping', [['B', 'L', 'L', 'EN', 'WS', 'ON', 'R', 'R', 'R'], 'L', 'R', 2], ['L', 'L', 'L', 'EN', 'R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['WS', 'L', 'AN', 'B', 'R', 'ON', 'ON', 'WS'], 'L', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'EN', 'B', 'WS', 'WS', 'S'], 'R', 'R', 2], ['R', 'EN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['ON', 'R', 'R', 'R', 'L', 'R', 'AN', 'WS', 'ON', 'B', 'AN'], 'L', 'R', 2], ['L', 'R', 'R', 'R', 'L', 'R', 'AN', 'R', 'R', 'R', 'AN']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['AN', 'L', 'AN', 'L', 'ON', 'R', 'AN', 'AN', 'B', 'L'], 'L', 'L', 3], ['AN', 'L', 'AN', 'L', 'R', 'R', 'AN', 'AN', 'R', 'L']), ('control layout', [['L', 'S', 'EN', 'AN', 'L', 'ON'], 'L', 'L', 2], ['L', 'L', 'EN', 'AN', 'L', 'L'])], [('regression: neutral run grouping', [['R', 'AN', 'B', 'ON', 'WS', 'WS', 'AN', 'WS'], 'L', 'L', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'AN', 'L']), ('regression: neutral run grouping', [['S', 'B', 'B'], 'R', 'R', 2], ['R', 'R', 'R']), ('regression: neutral run grouping', [['AN', 'WS', 'ON', 'R', 'ON', 'EN', 'ON', 'L', 'S', 'R', 'AN'], 'L', 'L', 0], ['AN', 'R', 'R', 'R', 'R', 'EN', 'L', 'L', 'L', 'R', 'AN']), ('regression: neutral run grouping', [['B', 'WS', 'R', 'S', 'R'], 'R', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['R', 'ON', 'ON', 'R', 'EN'], 'L', 'R', 3], ['R', 'R', 'R', 'R', 'EN']), ('control layout', [['L', 'WS', 'WS', 'AN'], 'R', 'L', 2], ['L', 'L', 'L', 'AN'])], [('regression: neutral run grouping', [['WS', 'L', 'ON', 'L', 'R', 'S', 'S'], 'L', 'R', 0], ['L', 'L', 'L', 'L', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'R', 'R', 'ON', 'B', 'AN', 'AN', 'ON', 'L'], 'R', 'L', 0], ['R', 'R', 'R', 'R', 'R', 'AN', 'AN', 'L', 'L']), ('regression: neutral run grouping', [['WS', 'L', 'WS', 'AN', 'WS', 'S', 'S', 'S'], 'L', 'R', 0], ['L', 'L', 'L', 'AN', 'R', 'R', 'R', 'R']), ('regression: neutral run grouping', [['R', 'AN', 'B', 'ON', 'WS', 'WS', 'AN', 'WS'], 'L', 'L', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'AN', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['ON', 'L', 'R', 'B', 'WS', 'R', 'L', 'WS'], 'R', 'L', 1], ['R', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('control layout', [['ON', 'EN', 'ON', 'R', 'B', 'ON'], 'R', 'L', 1], ['R', 'EN', 'R', 'R', 'R', 'R'])]]
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)

prompt:
Neutral runs resolve piecemeal with inconsistent directions.

Input [resolved weak classes, sos, eos, embedding level]. A maximal run of neutrals (ON, WS, B, S) takes the direction of its surrounding strong types when both sides agree (EN and AN count as R; sos/eos at the edges); otherwise the embedding direction (L for even level, R for odd). Return classes.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'B')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            while j < n and t[j] in NI:
                j += 1
            before = sos if i == 0 else strong(t[i - 1])
            after = eos if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('regression: segment separator neutrality', [['WS', 'EN', 'S', 'R', 'R', 'L', 'R', 'ON'], 'R', 'L', 3], ['R', 'EN', 'R', 'R', 'R', 'L', 'R', 'R']), ('partial-repair probe', [['R', 'WS', 'B', 'AN', 'L', 'L', 'EN', 'L'], 'R', 'R', 1], ['R', 'R', 'R', 'AN', 'L', 'L', 'EN', 'L']), ('regression: segment separator neutrality', [['ON', 'AN', 'EN', 'S', 'B', 'EN', 'WS', 'L'], 'L', 'R', 3], ['R', 'AN', 'EN', 'R', 'R', 'EN', 'R', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['WS', 'R', 'R', 'EN', 'R'], 'R', 'R', 1], ['R', 'R', 'R', 'EN', 'R']), ('control layout', [['L', 'AN'], 'L', 'R', 0], ['L', 'AN'])], [('regression: segment separator neutrality', [['EN', 'R', 'EN', 'R', 'WS', 'S', 'EN'], 'R', 'L', 1], ['EN', 'R', 'EN', 'R', 'R', 'R', 'EN']), ('regression: segment separator neutrality', [['ON', 'WS', 'R', 'ON', 'EN', 'R', 'WS', 'S'], 'R', 'L', 2], ['R', 'R', 'R', 'R', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['L', 'WS', 'B', 'B', 'B', 'L', 'L'], 'R', 'R', 0], ['L', 'L', 'L', 'L', 'L', 'L', 'L']), ('partial-repair probe', [['L', 'L', 'R', 'R', 'B', 'EN', 'R'], 'L', 'R', 0], ['L', 'L', 'R', 'R', 'R', 'EN', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('control layout', [['AN', 'WS', 'EN', 'L'], 'R', 'L', 0], ['AN', 'R', 'EN', 'L']), ('control layout', [['AN', 'AN', 'ON', 'R'], 'L', 'L', 1], ['AN', 'AN', 'R', 'R'])], [('regression: segment separator neutrality', [['S', 'L', 'ON', 'ON'], 'L', 'R', 0], ['L', 'L', 'L', 'L']), ('regression: segment separator neutrality', [['AN', 'WS', 'S', 'ON', 'B', 'WS', 'EN'], 'L', 'R', 1], ['AN', 'R', 'R', 'R', 'R', 'R', 'EN']), ('partial-repair probe', [['ON', 'R', 'B', 'WS', 'WS', 'R', 'L', 'R', 'L', 'R'], 'R', 'L', 3], ['R', 'R', 'R', 'R', 'R', 'R', 'L', 'R', 'L', 'R']), ('regression: segment separator neutrality', [['R', 'EN', 'B', 'WS', 'WS', 'S'], 'R', 'R', 2], ['R', 'EN', 'R', 'R', 'R', 'R']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['L', 'WS', 'EN'], 'R', 'R', 0], ['L', 'L', 'EN']), ('control layout', [['WS', 'ON', 'WS', 'WS', 'WS', 'L', 'AN', 'R'], 'L', 'L', 1], ['L', 'L', 'L', 'L', 'L', 'L', 'AN', 'R'])], [('regression: segment separator neutrality', [['R', 'ON', 'AN', 'ON', 'S', 'AN', 'WS', 'L', 'AN'], 'R', 'L', 2], ['R', 'R', 'AN', 'R', 'R', 'AN', 'L', 'L', 'AN']), ('regression: segment separator neutrality', [['R', 'R', 'ON', 'EN', 'AN', 'R', 'S', 'WS'], 'L', 'L', 1], ['R', 'R', 'R', 'EN', 'AN', 'R', 'R', 'R']), ('regression: segment separator neutrality', [['R', 'R', 'S', 'WS', 'L', 'B', 'B', 'WS', 'R', 'EN', 'L'], 'R', 'R', 1], ['R', 'R', 'R', 'R', 'L', 'R', 'R', 'R', 'R', 'EN', 'L']), ('partial-repair probe', [['AN', 'L', 'AN', 'L', 'ON', 'R', 'AN', 'AN', 'B', 'L'], 'L', 'L', 3], ['AN', 'L', 'AN', 'L', 'R', 'R', 'AN', 'AN', 'R', 'L']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('control layout', [['WS', 'AN'], 'L', 'R', 3], ['R', 'AN']), ('control layout', [['L', 'L'], 'R', 'L', 0], ['L', 'L'])], [('regression: segment separator neutrality', [['WS', 'L', 'L', 'S', 'ON', 'R', 'R', 'L', 'L'], 'R', 'L', 3], ['R', 'L', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('regression: segment separator neutrality', [['L', 'R', 'R', 'ON', 'R', 'S', 'R', 'R', 'AN', 'R', 'AN'], 'L', 'R', 3], ['L', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'AN', 'R', 'AN']), ('regression: segment separator neutrality', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('partial-repair probe', [['WS', 'AN', 'B', 'B', 'WS', 'ON', 'R', 'AN'], 'R', 'R', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'R', 'AN']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['R', 'L', 'R', 'AN', 'WS', 'WS', 'ON', 'L', 'AN', 'AN', 'EN'], 'L', 'R', 0], ['R', 'L', 'R', 'AN', 'L', 'L', 'L', 'L', 'AN', 'AN', 'EN']), ('control layout', [['L', 'EN', 'L', 'WS', 'R', 'AN', 'L', 'AN', 'WS', 'ON'], 'R', 'L', 3], ['L', 'EN', 'L', 'R', 'R', 'AN', 'L', 'AN', 'R', 'R'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    types, sos, eos, level = x
    t = list(types)
    n = len(t)
    NI = ('ON', 'WS', 'S')
    e = 'L' if level % 2 == 0 else 'R'
    def strong(c):
        return 'R' if c in ('R', 'EN', 'AN') else c
    i = 0
    while i < n:
        if t[i] in NI:
            j = i
            while j < n and t[j] in NI:
                j += 1
            before = sos if i == 0 else strong(t[i - 1])
            after = eos if j == n else strong(t[j])
            fill = before if before == after else e
            for k in range(i, j):
                t[k] = fill
            i = j
        else:
            i += 1
    return t
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('regression: segment separator neutrality', [['WS', 'EN', 'S', 'R', 'R', 'L', 'R', 'ON'], 'R', 'L', 3], ['R', 'EN', 'R', 'R', 'R', 'L', 'R', 'R']), ('partial-repair probe', [['R', 'WS', 'B', 'AN', 'L', 'L', 'EN', 'L'], 'R', 'R', 1], ['R', 'R', 'R', 'AN', 'L', 'L', 'EN', 'L']), ('regression: segment separator neutrality', [['ON', 'AN', 'EN', 'S', 'B', 'EN', 'WS', 'L'], 'L', 'R', 3], ['R', 'AN', 'EN', 'R', 'R', 'EN', 'R', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('neutral between numbers and R', [['R', 'ON', 'EN'], 'L', 'L', 0], ['R', 'R', 'EN']), ('control layout', [['WS', 'R', 'R', 'EN', 'R'], 'R', 'R', 1], ['R', 'R', 'R', 'EN', 'R']), ('control layout', [['L', 'AN'], 'L', 'R', 0], ['L', 'AN'])], [('regression: segment separator neutrality', [['EN', 'R', 'EN', 'R', 'WS', 'S', 'EN'], 'R', 'L', 1], ['EN', 'R', 'EN', 'R', 'R', 'R', 'EN']), ('regression: segment separator neutrality', [['ON', 'WS', 'R', 'ON', 'EN', 'R', 'WS', 'S'], 'R', 'L', 2], ['R', 'R', 'R', 'R', 'EN', 'R', 'L', 'L']), ('partial-repair probe', [['L', 'WS', 'B', 'B', 'B', 'L', 'L'], 'R', 'R', 0], ['L', 'L', 'L', 'L', 'L', 'L', 'L']), ('partial-repair probe', [['L', 'L', 'R', 'R', 'B', 'EN', 'R'], 'L', 'R', 0], ['L', 'L', 'R', 'R', 'R', 'EN', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('control layout', [['AN', 'WS', 'EN', 'L'], 'R', 'L', 0], ['AN', 'R', 'EN', 'L']), ('control layout', [['AN', 'AN', 'ON', 'R'], 'L', 'L', 1], ['AN', 'AN', 'R', 'R'])], [('regression: segment separator neutrality', [['S', 'L', 'ON', 'ON'], 'L', 'R', 0], ['L', 'L', 'L', 'L']), ('regression: segment separator neutrality', [['AN', 'WS', 'S', 'ON', 'B', 'WS', 'EN'], 'L', 'R', 1], ['AN', 'R', 'R', 'R', 'R', 'R', 'EN']), ('partial-repair probe', [['ON', 'R', 'B', 'WS', 'WS', 'R', 'L', 'R', 'L', 'R'], 'R', 'L', 3], ['R', 'R', 'R', 'R', 'R', 'R', 'L', 'R', 'L', 'R']), ('regression: segment separator neutrality', [['R', 'EN', 'B', 'WS', 'WS', 'S'], 'R', 'R', 2], ['R', 'EN', 'R', 'R', 'R', 'R']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('control layout', [['L', 'WS', 'EN'], 'R', 'R', 0], ['L', 'L', 'EN']), ('control layout', [['WS', 'ON', 'WS', 'WS', 'WS', 'L', 'AN', 'R'], 'L', 'L', 1], ['L', 'L', 'L', 'L', 'L', 'L', 'AN', 'R'])], [('regression: segment separator neutrality', [['R', 'ON', 'AN', 'ON', 'S', 'AN', 'WS', 'L', 'AN'], 'R', 'L', 2], ['R', 'R', 'AN', 'R', 'R', 'AN', 'L', 'L', 'AN']), ('regression: segment separator neutrality', [['R', 'R', 'ON', 'EN', 'AN', 'R', 'S', 'WS'], 'L', 'L', 1], ['R', 'R', 'R', 'EN', 'AN', 'R', 'R', 'R']), ('regression: segment separator neutrality', [['R', 'R', 'S', 'WS', 'L', 'B', 'B', 'WS', 'R', 'EN', 'L'], 'R', 'R', 1], ['R', 'R', 'R', 'R', 'L', 'R', 'R', 'R', 'R', 'EN', 'L']), ('partial-repair probe', [['AN', 'L', 'AN', 'L', 'ON', 'R', 'AN', 'AN', 'B', 'L'], 'L', 'L', 3], ['AN', 'L', 'AN', 'L', 'R', 'R', 'AN', 'AN', 'R', 'L']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('mixed neutral run', [['R', 'WS', 'ON', 'S', 'R'], 'L', 'L', 0], ['R', 'R', 'R', 'R', 'R']), ('control layout', [['WS', 'AN'], 'L', 'R', 3], ['R', 'AN']), ('control layout', [['L', 'L'], 'R', 'L', 0], ['L', 'L'])], [('regression: segment separator neutrality', [['WS', 'L', 'L', 'S', 'ON', 'R', 'R', 'L', 'L'], 'R', 'L', 3], ['R', 'L', 'L', 'R', 'R', 'R', 'R', 'L', 'L']), ('regression: segment separator neutrality', [['L', 'R', 'R', 'ON', 'R', 'S', 'R', 'R', 'AN', 'R', 'AN'], 'L', 'R', 3], ['L', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'AN', 'R', 'AN']), ('regression: segment separator neutrality', [['S', 'L', 'AN', 'WS', 'B', 'B', 'ON', 'ON', 'B', 'R', 'WS'], 'R', 'R', 2], ['L', 'L', 'AN', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R']), ('partial-repair probe', [['WS', 'AN', 'B', 'B', 'WS', 'ON', 'R', 'AN'], 'R', 'R', 2], ['R', 'AN', 'R', 'R', 'R', 'R', 'R', 'AN']), ('trailing neutral uses eos', [['L', 'WS'], 'L', 'L', 1], ['L', 'L']), ('leading neutral uses sos', [['WS', 'R'], 'R', 'L', 0], ['R', 'R']), ('control layout', [['R', 'L', 'R', 'AN', 'WS', 'WS', 'ON', 'L', 'AN', 'AN', 'EN'], 'L', 'R', 0], ['R', 'L', 'R', 'AN', 'L', 'L', 'L', 'L', 'AN', 'AN', 'EN']), ('control layout', [['L', 'EN', 'L', 'WS', 'R', 'AN', 'L', 'AN', 'WS', 'ON'], 'R', 'L', 3], ['L', 'EN', 'L', 'R', 'R', 'AN', 'L', 'AN', 'R', 'R'])]]
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)

prompt:
Tabs split neutral runs and keep a separator class.

Input [resolved weak classes, sos, eos, embedding level]. A maximal run of neutrals (ON, WS, B, S) takes the direction of its surrounding strong types when both sides agree (EN and AN count as R; sos/eos at the edges); otherwise the embedding direction (L for even level, R for odd). Return classes.

split: open-access


prompt:
Numbers in LTR text collapse into the surrounding RTL run.

Input [resolved classes L/R/EN/AN, embedding levels]. At even levels R goes up one and AN/EN up two; at odd levels L, EN and AN go up one. Return level runs [start, end exclusive, level] of equal final levels.

split: open-access


prompt:
Numbers inside RTL text read right-to-left digit by digit.

Input [resolved classes L/R/EN/AN, embedding levels]. At even levels R goes up one and AN/EN up two; at odd levels L, EN and AN go up one. Return level runs [start, end exclusive, level] of equal final levels.

split: open-access


prompt:
Deep even embeddings are treated like odd ones.

Input [resolved classes L/R/EN/AN, embedding levels]. At even levels R goes up one and AN/EN up two; at odd levels L, EN and AN go up one. Return level runs [start, end exclusive, level] of equal final levels.

split: open-access


prompt:
Level runs report ends one short.

Input [resolved classes L/R/EN/AN, embedding levels]. At even levels R goes up one and AN/EN up two; at odd levels L, EN and AN go up one. Return level runs [start, end exclusive, level] of equal final levels.

split: open-access


prompt:
Runs at levels 1 and 3 are merged.

Input [resolved classes L/R/EN/AN, embedding levels]. At even levels R goes up one and AN/EN up two; at odd levels L, EN and AN go up one. Return level runs [start, end exclusive, level] of equal final levels.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(odd)
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: highest level start', [1, 1, 2, 2, 2, 2, 2], [2, 3, 4, 5, 6, 1, 0]), ('partial-repair probe', [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0], [0, 1, 2, 3, 4, 5, 6, 8, 7, 9, 10]), ('regression: highest level start', [3, 3, 4, 4, 4, 2, 2, 2, 2, 4], [2, 3, 4, 1, 0, 5, 6, 7, 8, 9]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2, 2, 2], [0, 1, 2, 3])], [('regression: highest level start', [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [9, 10, 11, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: highest level start', [1, 1, 1, 1, 2, 2, 1, 0], [6, 4, 5, 3, 2, 1, 0, 7]), ('partial-repair probe', [1, 1, 1, 1, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 3, 2, 1, 0]), ('partial-repair probe', [1, 1], [1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 2, 1, 1, 1, 1], [0, 1, 6, 5, 4, 3, 2]), ('control layout', [1, 3, 2, 2, 2], [1, 2, 3, 4, 0])], [('regression: highest level start', [2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4], [8, 9, 10, 7, 6, 5, 4, 3, 0, 1, 2]), ('regression: highest level start', [4, 4, 1, 1, 1, 2, 2, 3, 3], [5, 6, 8, 7, 4, 3, 2, 0, 1]), ('regression: highest level start', [2, 2, 2, 1, 1, 0, 0, 1, 1, 1, 1, 1], [4, 3, 0, 1, 2, 5, 6, 11, 10, 9, 8, 7]), ('regression: highest level start', [4, 4, 4, 4, 2, 1], [5, 0, 1, 2, 3, 4]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [4, 4, 4, 4, 4], [0, 1, 2, 3, 4]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: highest level start', [2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2], [8, 9, 10, 11, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: highest level start', [2, 2, 1, 1, 1, 1, 4, 4, 2, 2, 2], [6, 7, 8, 9, 10, 5, 4, 3, 2, 0, 1]), ('partial-repair probe', [3, 3, 2], [1, 0, 2]), ('regression: highest level start', [2, 2, 2, 2, 2, 1, 1, 1], [7, 6, 5, 0, 1, 2, 3, 4]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5]), ('control layout', [3, 1, 1], [2, 1, 0])], [('regression: highest level start', [4, 4, 2, 3, 1, 2, 2, 2, 2, 1, 1, 1], [11, 10, 9, 5, 6, 7, 8, 4, 0, 1, 2, 3]), ('regression: highest level start', [1, 2, 2, 4, 4, 2], [1, 2, 3, 4, 5, 0]), ('partial-repair probe', [3, 3, 3, 3, 3, 0, 3, 3, 3], [4, 3, 2, 1, 0, 5, 8, 7, 6]), ('partial-repair probe', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [3], [0]), ('control layout', [2, 2, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(levels) - 1
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: highest level start', [1, 1, 2, 2, 2, 2, 2], [2, 3, 4, 5, 6, 1, 0]), ('partial-repair probe', [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0], [0, 1, 2, 3, 4, 5, 6, 8, 7, 9, 10]), ('regression: highest level start', [3, 3, 4, 4, 4, 2, 2, 2, 2, 4], [2, 3, 4, 1, 0, 5, 6, 7, 8, 9]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2, 2, 2], [0, 1, 2, 3])], [('regression: highest level start', [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [9, 10, 11, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: highest level start', [1, 1, 1, 1, 2, 2, 1, 0], [6, 4, 5, 3, 2, 1, 0, 7]), ('partial-repair probe', [1, 1, 1, 1, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 3, 2, 1, 0]), ('partial-repair probe', [1, 1], [1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 2, 1, 1, 1, 1], [0, 1, 6, 5, 4, 3, 2]), ('control layout', [1, 3, 2, 2, 2], [1, 2, 3, 4, 0])], [('regression: highest level start', [2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4], [8, 9, 10, 7, 6, 5, 4, 3, 0, 1, 2]), ('regression: highest level start', [4, 4, 1, 1, 1, 2, 2, 3, 3], [5, 6, 8, 7, 4, 3, 2, 0, 1]), ('regression: highest level start', [2, 2, 2, 1, 1, 0, 0, 1, 1, 1, 1, 1], [4, 3, 0, 1, 2, 5, 6, 11, 10, 9, 8, 7]), ('regression: highest level start', [4, 4, 4, 4, 2, 1], [5, 0, 1, 2, 3, 4]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [4, 4, 4, 4, 4], [0, 1, 2, 3, 4]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: highest level start', [2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2], [8, 9, 10, 11, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: highest level start', [2, 2, 1, 1, 1, 1, 4, 4, 2, 2, 2], [6, 7, 8, 9, 10, 5, 4, 3, 2, 0, 1]), ('partial-repair probe', [3, 3, 2], [1, 0, 2]), ('regression: highest level start', [2, 2, 2, 2, 2, 1, 1, 1], [7, 6, 5, 0, 1, 2, 3, 4]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5]), ('control layout', [3, 1, 1], [2, 1, 0])], [('regression: highest level start', [4, 4, 2, 3, 1, 2, 2, 2, 2, 1, 1, 1], [11, 10, 9, 5, 6, 7, 8, 4, 0, 1, 2, 3]), ('regression: highest level start', [1, 2, 2, 4, 4, 2], [1, 2, 3, 4, 5, 0]), ('partial-repair probe', [3, 3, 3, 3, 3, 0, 3, 3, 3], [4, 3, 2, 1, 0, 5, 8, 7, 6]), ('partial-repair probe', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [3], [0]), ('control layout', [2, 2, 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)

prompt:
Numbers embedded at an even level inside RTL text read backwards.

Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(levels)
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 3, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 0, 0, 0, 2, 2, 2, 2], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [1, 1, 2, 2, 3, 3, 2, 2], [2, 3, 5, 4, 6, 7, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [2], [0])], [('regression: reversal loop bound', [1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [3, 0, 3, 3, 3, 3], [0, 1, 5, 4, 3, 2]), ('regression: reversal loop bound', [2, 2, 1, 1, 1], [4, 3, 2, 0, 1]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2], [0, 1])], [('regression: reversal loop bound', [1, 0, 0, 0, 2, 2, 2, 0, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8]), ('regression: reversal loop bound', [2, 2, 2, 0, 0, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 9, 8, 7, 6, 5]), ('regression: reversal loop bound', [4, 4, 4, 1, 1, 1, 2], [6, 5, 4, 3, 0, 1, 2]), ('regression: reversal loop bound', [3, 3, 2, 2, 2, 2, 1, 1, 1], [8, 7, 6, 1, 0, 2, 3, 4, 5]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2], [0, 1]), ('control layout', [4, 4], [0, 1])], [('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [0, 0, 0, 2, 0, 3, 3], [0, 1, 2, 3, 4, 6, 5]), ('regression: reversal loop bound', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1], [0]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: reversal loop bound', [3, 1, 1, 2, 2], [3, 4, 2, 1, 0]), ('regression: reversal loop bound', [2, 2, 2, 2, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: reversal loop bound', [1, 1, 1, 3, 3, 3], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 1], [11, 7, 8, 9, 10, 6, 5, 4, 0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(levels)
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi - 1, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 3, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 3, 3, 0, 0, 0, 2, 2, 2, 2], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [1, 1, 2, 2, 3, 3, 2, 2], [2, 3, 5, 4, 6, 7, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('control layout', [2], [0])], [('regression: reversal loop bound', [1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [3, 0, 3, 3, 3, 3], [0, 1, 5, 4, 3, 2]), ('regression: reversal loop bound', [2, 2, 1, 1, 1], [4, 3, 2, 0, 1]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [2, 2, 2], [0, 1, 2]), ('control layout', [2, 2], [0, 1])], [('regression: reversal loop bound', [1, 0, 0, 0, 2, 2, 2, 0, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8]), ('regression: reversal loop bound', [2, 2, 2, 0, 0, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 9, 8, 7, 6, 5]), ('regression: reversal loop bound', [4, 4, 4, 1, 1, 1, 2], [6, 5, 4, 3, 0, 1, 2]), ('regression: reversal loop bound', [3, 3, 2, 2, 2, 2, 1, 1, 1], [8, 7, 6, 1, 0, 2, 3, 4, 5]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2], [0, 1]), ('control layout', [4, 4], [0, 1])], [('regression: reversal loop bound', [1, 1, 1], [2, 1, 0]), ('regression: reversal loop bound', [1, 1, 1, 0, 0, 0, 0, 0, 0, 1], [2, 1, 0, 3, 4, 5, 6, 7, 8, 9]), ('regression: reversal loop bound', [0, 0, 0, 2, 0, 3, 3], [0, 1, 2, 3, 4, 6, 5]), ('regression: reversal loop bound', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1], [0]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: reversal loop bound', [3, 1, 1, 2, 2], [3, 4, 2, 1, 0]), ('regression: reversal loop bound', [2, 2, 2, 2, 1, 1, 1, 1, 1], [8, 7, 6, 5, 4, 0, 1, 2, 3]), ('regression: reversal loop bound', [1, 1, 1, 3, 3, 3], [5, 4, 3, 2, 1, 0]), ('regression: reversal loop bound', [3, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 1], [11, 7, 8, 9, 10, 6, 5, 4, 0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]]
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)

prompt:
Runs at the lowest odd level stay in logical order.

Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).

split: open-access


prompt:
Levels of one parity are never reversed as their own pass.

Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    hi = max(levels)
    lo = min(odd) if odd else 0
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0, 0, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('control layout', [0], [0])], [('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('control layout', [1, 1, 1, 2, 2, 2, 2], [3, 4, 5, 6, 2, 1, 0])], [('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [2, 4, 4, 4, 4, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [0, 0, 0], [0, 1, 2]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3], [1, 0]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: no odd level shortcut', [0, 0, 0, 0, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [4, 4, 4], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('control layout', [0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 5, 4])], [('regression: no odd level shortcut', [2, 2, 2], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0], [0, 1]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 11, 10]), ('control layout', [2, 2, 1, 1, 1, 1, 3], [6, 5, 4, 3, 2, 0, 1])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    hi = max(levels)
    lo = min(odd) if odd else hi
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0, 0, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('control layout', [0], [0])], [('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 1], [10, 9, 8, 4, 3, 5, 7, 6, 2, 1, 0]), ('control layout', [1, 1, 1, 2, 2, 2, 2], [3, 4, 5, 6, 2, 1, 0])], [('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [2, 4, 4, 4, 4, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('regression: no odd level shortcut', [0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('regression: no odd level shortcut', [0, 0, 0], [0, 1, 2]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3], [1, 0]), ('control layout', [2, 0, 0, 0, 1], [0, 1, 2, 3, 4])], [('regression: no odd level shortcut', [0, 0, 0, 0, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [4, 4, 4], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2], [0, 1, 2, 3, 4]), ('regression: no odd level shortcut', [2, 2], [0, 1]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 1], [6, 5, 4, 3, 2, 1, 0, 7, 8, 9, 10]), ('control layout', [0, 0, 0, 0, 1, 1], [0, 1, 2, 3, 5, 4])], [('regression: no odd level shortcut', [2, 2, 2], [0, 1, 2]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7]), ('regression: no odd level shortcut', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5]), ('regression: no odd level shortcut', [0, 0], [0, 1]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [3, 2, 1, 0, 4, 5, 6, 7, 8, 9, 11, 10]), ('control layout', [2, 2, 1, 1, 1, 1, 3], [6, 5, 4, 3, 2, 0, 1])]]
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)

prompt:
Pure LTR lines with embedded even levels are reversed.

Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(levels)
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    pos = [0] * len(vis)
    for v, p in enumerate(vis):
        pos[p[1]] = v
    return pos
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2], [3, 4, 5, 6, 9, 8, 7, 10, 11, 2, 1, 0]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('partial-repair probe', [1, 1, 1, 4], [3, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8])], [('regression: visual map direction', [4, 4, 4, 4, 1, 1, 1, 4], [7, 6, 5, 4, 0, 1, 2, 3]), ('regression: visual map direction', [3, 3, 4, 4], [2, 3, 1, 0]), ('regression: visual map direction', [2, 2, 2, 2, 2, 2, 2, 1, 1, 1], [9, 8, 7, 0, 1, 2, 3, 4, 5, 6]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('control layout', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5])], [('regression: visual map direction', [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4], [6, 7, 8, 9, 10, 11, 5, 4, 3, 2, 1, 0]), ('regression: visual map direction', [2, 2, 3, 3, 3, 1, 1, 4, 4, 4], [7, 8, 9, 6, 5, 0, 1, 4, 3, 2]), ('partial-repair probe', [1, 0, 0], [0, 1, 2]), ('regression: visual map direction', [2, 2, 2, 2, 1, 1], [5, 4, 0, 1, 2, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [4, 4, 4, 2], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: visual map direction', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('regression: visual map direction', [4, 4, 4, 3, 3, 3, 3], [6, 5, 4, 3, 0, 1, 2]), ('partial-repair probe', [3, 3], [1, 0]), ('regression: visual map direction', [0, 0, 0, 2, 1, 1, 1, 2, 2, 2, 2, 1], [0, 1, 2, 11, 7, 8, 9, 10, 6, 5, 4, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0], [0, 1, 2]), ('control layout', [1], [0])], [('regression: visual map direction', [2, 2, 2, 1, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 0, 1, 2]), ('regression: visual map direction', [2, 2, 2, 2, 2, 1, 1, 1], [7, 6, 5, 0, 1, 2, 3, 4]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2, 2, 2, 2, 2], [3, 4, 5, 6, 7, 8, 9, 2, 1, 0]), ('regression: visual map direction', [3, 1, 1, 1, 1, 2, 2], [5, 6, 4, 3, 2, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4]), ('control layout', [2, 2, 4], [0, 1, 2])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    levels = x
    order = list(range(len(levels)))
    odd = [l for l in levels if l % 2 == 1]
    if not odd:
        return order
    hi = max(levels)
    lo = min(odd)
    vis = [[lv, i] for i, lv in enumerate(levels)]
    for lev in range(hi, lo - 1, -1):
        i = 0
        while i < len(vis):
            if vis[i][0] >= lev:
                j = i
                while j < len(vis) and vis[j][0] >= lev:
                    j += 1
                vis[i:j] = vis[i:j][::-1]
                i = j
            else:
                i += 1
    return [len(vis) - 1 - p[1] for p in vis]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 2, 2], [3, 4, 5, 6, 9, 8, 7, 10, 11, 2, 1, 0]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2], [3, 4, 5, 2, 1, 0]), ('partial-repair probe', [1, 1, 1, 4], [3, 2, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('control layout', [2], [0]), ('control layout', [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8])], [('regression: visual map direction', [4, 4, 4, 4, 1, 1, 1, 4], [7, 6, 5, 4, 0, 1, 2, 3]), ('regression: visual map direction', [3, 3, 4, 4], [2, 3, 1, 0]), ('regression: visual map direction', [2, 2, 2, 2, 2, 2, 2, 1, 1, 1], [9, 8, 7, 0, 1, 2, 3, 4, 5, 6]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ('control layout', [2, 2, 2, 2, 2, 2], [0, 1, 2, 3, 4, 5])], [('regression: visual map direction', [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4], [6, 7, 8, 9, 10, 11, 5, 4, 3, 2, 1, 0]), ('regression: visual map direction', [2, 2, 3, 3, 3, 1, 1, 4, 4, 4], [7, 8, 9, 6, 5, 0, 1, 4, 3, 2]), ('partial-repair probe', [1, 0, 0], [0, 1, 2]), ('regression: visual map direction', [2, 2, 2, 2, 1, 1], [5, 4, 0, 1, 2, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('number inside RTL', [1, 1, 2, 2, 1], [4, 2, 3, 1, 0]), ('control layout', [4, 4, 4, 2], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4])], [('regression: visual map direction', [2, 2, 1, 1, 1, 1, 1, 1, 0, 0], [7, 6, 5, 4, 3, 2, 0, 1, 8, 9]), ('regression: visual map direction', [4, 4, 4, 3, 3, 3, 3], [6, 5, 4, 3, 0, 1, 2]), ('partial-repair probe', [3, 3], [1, 0]), ('regression: visual map direction', [0, 0, 0, 2, 1, 1, 1, 2, 2, 2, 2, 1], [0, 1, 2, 11, 7, 8, 9, 10, 6, 5, 4, 3]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0], [0, 1, 2]), ('control layout', [1], [0])], [('regression: visual map direction', [2, 2, 2, 1, 1, 1, 1, 3, 3, 3], [9, 8, 7, 6, 5, 4, 3, 0, 1, 2]), ('regression: visual map direction', [2, 2, 2, 2, 2, 1, 1, 1], [7, 6, 5, 0, 1, 2, 3, 4]), ('regression: visual map direction', [1, 1, 1, 2, 2, 2, 2, 2, 2, 2], [3, 4, 5, 6, 7, 8, 9, 2, 1, 0]), ('regression: visual map direction', [3, 1, 1, 1, 1, 2, 2], [5, 6, 4, 3, 2, 1, 0]), ('lowest odd is three', [2, 3, 3, 2], [0, 2, 1, 3]), ('all even levels', [0, 2, 2, 0], [0, 1, 2, 3]), ('control layout', [0, 0, 0, 0, 0], [0, 1, 2, 3, 4]), ('control layout', [2, 2, 4], [0, 1, 2])]]
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)

prompt:
Callers receive a logical-to-visual map instead of visual order.

Input resolved levels of one line. From the highest level down to the lowest odd level on the line, reverse every maximal visual run of characters at that level or higher. Return logical indices in visual order (identity when no odd level).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS',)
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('regression: isolate controls in reset runs', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['S', 'WS', 'WS', 'FSI', 'B', 'ON', 'S', 'R'], [1, 1, 1, 1, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 1, 0, 1]), ('regression: isolate controls in reset runs', [['PDI', 'WS', 'WS', 'LRI', 'RLI', 'WS'], [1, 1, 1, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['PDI', 'LRI', 'L', 'L', 'WS', 'ON'], [0, 0, 1, 1, 1, 1], 0], [0, 0, 1, 1, 1, 1]), ('control layout', [['WS', 'L', 'R', 'FSI', 'L'], [2, 2, 2, 2, 2], 1], [2, 2, 2, 2, 2])], [('regression: isolate controls in reset runs', [['RLI', 'R', 'LRI', 'FSI', 'WS'], [1, 2, 4, 4, 4], 0], [1, 2, 0, 0, 0]), ('regression: isolate controls in reset runs', [['ON', 'ON', 'WS', 'R', 'RLI', 'LRI'], [4, 4, 4, 4, 3, 4], 1], [4, 4, 4, 4, 1, 1]), ('regression: isolate controls in reset runs', [['ON', 'WS', 'R', 'ON', 'WS', 'R', 'WS', 'FSI', 'PDI'], [4, 4, 4, 4, 2, 2, 3, 4, 1], 0], [4, 4, 4, 4, 2, 2, 0, 0, 0]), ('regression: isolate controls in reset runs', [['S', 'WS', 'L', 'WS', 'R', 'L', 'RLI', 'PDI'], [4, 4, 2, 2, 2, 2, 3, 2], 0], [0, 4, 2, 2, 2, 2, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['B', 'S', 'WS', 'ON', 'L', 'FSI', 'WS', 'L', 'RLI', 'WS', 'L', 'B'], [1, 1, 1, 1, 3, 3, 3, 3, 0, 0, 0, 0], 1], [1, 1, 1, 1, 3, 3, 3, 3, 0, 0, 0, 1]), ('control layout', [['R'], [2], 1], [2])], [('regression: isolate controls in reset runs', [['L', 'L', 'WS', 'PDI'], [2, 2, 2, 2], 0], [2, 2, 0, 0]), ('regression: isolate controls in reset runs', [['ON', 'R', 'PDI', 'B', 'WS', 'RLI', 'FSI', 'B', 'WS'], [0, 0, 0, 0, 1, 1, 1, 3, 3], 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['B', 'WS', 'R', 'L', 'B', 'R', 'WS', 'FSI', 'ON', 'FSI'], [3, 3, 3, 3, 4, 4, 2, 2, 2, 4], 1], [1, 3, 3, 3, 1, 4, 2, 2, 2, 1]), ('regression: isolate controls in reset runs', [['LRI', 'R', 'EN', 'S', 'L', 'L', 'LRI', 'FSI', 'WS'], [3, 3, 3, 3, 3, 3, 3, 3, 4], 1], [3, 3, 3, 1, 3, 3, 1, 1, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'L', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'WS', 'PDI', 'R'], [2, 2, 4, 4, 4, 1, 2, 2, 2, 2, 2], 0], [2, 2, 4, 4, 4, 1, 2, 2, 2, 2, 2]), ('control layout', [['LRI', 'R', 'ON', 'ON', 'PDI', 'PDI'], [1, 1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 1])], [('regression: isolate controls in reset runs', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['L', 'WS', 'R', 'EN', 'WS', 'B', 'B', 'R', 'B', 'WS', 'L', 'LRI'], [2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4], 1], [2, 2, 2, 1, 1, 1, 1, 4, 1, 4, 4, 1]), ('regression: isolate controls in reset runs', [['WS', 'PDI', 'RLI'], [3, 1, 1], 0], [0, 0, 0]), ('regression: isolate controls in reset runs', [['PDI', 'FSI'], [0, 0], 1], [1, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['B', 'L', 'EN'], [3, 3, 1], 1], [1, 3, 1]), ('control layout', [['WS', 'R', 'L'], [1, 1, 1], 0], [1, 1, 1])], [('regression: isolate controls in reset runs', [['WS', 'FSI', 'ON', 'RLI', 'PDI', 'RLI', 'FSI'], [0, 0, 0, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['L', 'WS', 'R', 'L', 'S', 'WS', 'L', 'LRI'], [2, 2, 2, 2, 4, 4, 4, 4], 1], [2, 2, 2, 2, 1, 4, 4, 1]), ('regression: isolate controls in reset runs', [['LRI', 'R', 'EN', 'S', 'L', 'L', 'LRI', 'FSI', 'WS'], [3, 3, 3, 3, 3, 3, 3, 3, 4], 1], [3, 3, 3, 1, 3, 3, 1, 1, 1]), ('regression: isolate controls in reset runs', [['EN', 'WS', 'L', 'WS', 'R', 'PDI', 'WS', 'R', 'R', 'S', 'RLI'], [1, 1, 1, 1, 0, 0, 2, 3, 3, 3, 3], 0], [1, 1, 1, 1, 0, 0, 2, 3, 3, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['R', 'RLI', 'EN', 'R', 'R', 'R', 'L'], [1, 1, 1, 0, 0, 0, 0], 1], [1, 1, 1, 0, 0, 0, 0]), ('control layout', [['L', 'ON', 'L', 'WS', 'S', 'PDI', 'WS', 'R', 'R', 'PDI', 'EN'], [3, 1, 1, 0, 0, 2, 3, 3, 3, 0, 0], 1], [3, 1, 1, 1, 1, 2, 3, 3, 3, 0, 0])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B'):
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('regression: isolate controls in reset runs', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['S', 'WS', 'WS', 'FSI', 'B', 'ON', 'S', 'R'], [1, 1, 1, 1, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 1, 0, 1]), ('regression: isolate controls in reset runs', [['PDI', 'WS', 'WS', 'LRI', 'RLI', 'WS'], [1, 1, 1, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('control layout', [['PDI', 'LRI', 'L', 'L', 'WS', 'ON'], [0, 0, 1, 1, 1, 1], 0], [0, 0, 1, 1, 1, 1]), ('control layout', [['WS', 'L', 'R', 'FSI', 'L'], [2, 2, 2, 2, 2], 1], [2, 2, 2, 2, 2])], [('regression: isolate controls in reset runs', [['RLI', 'R', 'LRI', 'FSI', 'WS'], [1, 2, 4, 4, 4], 0], [1, 2, 0, 0, 0]), ('regression: isolate controls in reset runs', [['ON', 'ON', 'WS', 'R', 'RLI', 'LRI'], [4, 4, 4, 4, 3, 4], 1], [4, 4, 4, 4, 1, 1]), ('regression: isolate controls in reset runs', [['ON', 'WS', 'R', 'ON', 'WS', 'R', 'WS', 'FSI', 'PDI'], [4, 4, 4, 4, 2, 2, 3, 4, 1], 0], [4, 4, 4, 4, 2, 2, 0, 0, 0]), ('regression: isolate controls in reset runs', [['S', 'WS', 'L', 'WS', 'R', 'L', 'RLI', 'PDI'], [4, 4, 2, 2, 2, 2, 3, 2], 0], [0, 4, 2, 2, 2, 2, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['B', 'S', 'WS', 'ON', 'L', 'FSI', 'WS', 'L', 'RLI', 'WS', 'L', 'B'], [1, 1, 1, 1, 3, 3, 3, 3, 0, 0, 0, 0], 1], [1, 1, 1, 1, 3, 3, 3, 3, 0, 0, 0, 1]), ('control layout', [['R'], [2], 1], [2])], [('regression: isolate controls in reset runs', [['L', 'L', 'WS', 'PDI'], [2, 2, 2, 2], 0], [2, 2, 0, 0]), ('regression: isolate controls in reset runs', [['ON', 'R', 'PDI', 'B', 'WS', 'RLI', 'FSI', 'B', 'WS'], [0, 0, 0, 0, 1, 1, 1, 3, 3], 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['B', 'WS', 'R', 'L', 'B', 'R', 'WS', 'FSI', 'ON', 'FSI'], [3, 3, 3, 3, 4, 4, 2, 2, 2, 4], 1], [1, 3, 3, 3, 1, 4, 2, 2, 2, 1]), ('regression: isolate controls in reset runs', [['LRI', 'R', 'EN', 'S', 'L', 'L', 'LRI', 'FSI', 'WS'], [3, 3, 3, 3, 3, 3, 3, 3, 4], 1], [3, 3, 3, 1, 3, 3, 1, 1, 1]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'L', 'R', 'ON', 'WS', 'WS', 'WS', 'L', 'WS', 'PDI', 'R'], [2, 2, 4, 4, 4, 1, 2, 2, 2, 2, 2], 0], [2, 2, 4, 4, 4, 1, 2, 2, 2, 2, 2]), ('control layout', [['LRI', 'R', 'ON', 'ON', 'PDI', 'PDI'], [1, 1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1, 1])], [('regression: isolate controls in reset runs', [['FSI', 'LRI', 'FSI', 'WS', 'B', 'RLI', 'WS', 'WS'], [1, 1, 3, 3, 2, 2, 2, 2], 0], [0, 0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['L', 'WS', 'R', 'EN', 'WS', 'B', 'B', 'R', 'B', 'WS', 'L', 'LRI'], [2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4], 1], [2, 2, 2, 1, 1, 1, 1, 4, 1, 4, 4, 1]), ('regression: isolate controls in reset runs', [['WS', 'PDI', 'RLI'], [3, 1, 1], 0], [0, 0, 0]), ('regression: isolate controls in reset runs', [['PDI', 'FSI'], [0, 0], 1], [1, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['B', 'L', 'EN'], [3, 3, 1], 1], [1, 3, 1]), ('control layout', [['WS', 'R', 'L'], [1, 1, 1], 0], [1, 1, 1])], [('regression: isolate controls in reset runs', [['WS', 'FSI', 'ON', 'RLI', 'PDI', 'RLI', 'FSI'], [0, 0, 0, 1, 1, 1, 1], 0], [0, 0, 0, 0, 0, 0, 0]), ('regression: isolate controls in reset runs', [['L', 'WS', 'R', 'L', 'S', 'WS', 'L', 'LRI'], [2, 2, 2, 2, 4, 4, 4, 4], 1], [2, 2, 2, 2, 1, 4, 4, 1]), ('regression: isolate controls in reset runs', [['LRI', 'R', 'EN', 'S', 'L', 'L', 'LRI', 'FSI', 'WS'], [3, 3, 3, 3, 3, 3, 3, 3, 4], 1], [3, 3, 3, 1, 3, 3, 1, 1, 1]), ('regression: isolate controls in reset runs', [['EN', 'WS', 'L', 'WS', 'R', 'PDI', 'WS', 'R', 'R', 'S', 'RLI'], [1, 1, 1, 1, 0, 0, 2, 3, 3, 3, 3], 0], [1, 1, 1, 1, 0, 0, 2, 3, 3, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['R', 'RLI', 'EN', 'R', 'R', 'R', 'L'], [1, 1, 1, 0, 0, 0, 0], 1], [1, 1, 1, 0, 0, 0, 0]), ('control layout', [['L', 'ON', 'L', 'WS', 'S', 'PDI', 'WS', 'R', 'R', 'PDI', 'EN'], [3, 1, 1, 0, 0, 2, 3, 3, 3, 0, 0], 1], [3, 1, 1, 1, 1, 2, 3, 3, 3, 0, 0])]]
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)

prompt:
Isolate controls at the line end keep embedded levels.

Input [original classes, resolved levels, paragraph level]. Reset to the paragraph level: every S and B; any run of WS and isolate formatting characters (FSI LRI RLI PDI) immediately before an S or B; and such a run at the end of the line. Return levels.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c == 'B':
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('regression: segment separator reset', [['S', 'R', 'WS', 'ON', 'S'], [0, 0, 0, 0, 3], 1], [1, 0, 0, 0, 1]), ('partial-repair probe', [['WS', 'ON'], [3, 3], 0], [3, 3]), ('partial-repair probe', [['L', 'PDI', 'WS', 'ON', 'ON', 'PDI'], [3, 1, 1, 1, 1, 1], 0], [3, 1, 1, 1, 1, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['ON', 'LRI', 'EN', 'ON'], [1, 2, 2, 2], 0], [1, 2, 2, 2]), ('control layout', [['R', 'FSI', 'L'], [1, 3, 3], 0], [1, 3, 3])], [('regression: segment separator reset', [['R', 'LRI', 'L', 'S', 'R', 'ON', 'R', 'L'], [1, 3, 3, 3, 0, 2, 2, 2], 0], [1, 3, 3, 0, 0, 2, 2, 2]), ('regression: segment separator reset', [['S', 'S', 'PDI', 'WS', 'R', 'ON', 'LRI', 'WS', 'ON', 'R', 'WS', 'ON'], [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], 1], [1, 1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]), ('partial-repair probe', [['FSI', 'L', 'L', 'LRI', 'WS', 'ON', 'WS', 'RLI', 'WS', 'B', 'PDI', 'L'], [2, 2, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1], 0], [2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 1, 1]), ('regression: segment separator reset', [['EN', 'S', 'RLI', 'EN', 'R', 'WS', 'R', 'FSI', 'ON', 'WS', 'WS', 'FSI'], [4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 1], 0], [4, 0, 4, 4, 4, 4, 4, 3, 3, 0, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['R', 'L', 'R', 'WS'], [1, 1, 1, 1], 0], [1, 1, 1, 0]), ('control layout', [['L', 'RLI', 'ON', 'RLI'], [4, 4, 4, 4], 0], [4, 4, 4, 0])], [('regression: segment separator reset', [['WS', 'EN', 'RLI', 'WS', 'PDI', 'R', 'EN', 'WS', 'S'], [2, 2, 2, 2, 3, 3, 3, 0, 0], 1], [2, 2, 2, 2, 3, 3, 3, 1, 1]), ('regression: segment separator reset', [['L', 'WS', 'B', 'ON', 'WS', 'R', 'S', 'WS', 'WS', 'L', 'PDI', 'S'], [1, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4], 0], [1, 0, 0, 2, 2, 2, 0, 2, 2, 4, 0, 0]), ('partial-repair probe', [['EN', 'R', 'B', 'WS', 'R', 'L', 'L', 'ON', 'LRI', 'ON', 'EN'], [2, 2, 4, 4, 4, 1, 1, 1, 4, 1, 3], 1], [2, 2, 1, 4, 4, 1, 1, 1, 4, 1, 3]), ('partial-repair probe', [['L', 'WS', 'B', 'WS', 'ON'], [0, 0, 0, 2, 2], 1], [0, 1, 1, 2, 2]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['ON', 'WS'], [2, 2], 1], [2, 1]), ('control layout', [['RLI', 'ON'], [2, 2], 1], [2, 2])], [('regression: segment separator reset', [['LRI', 'EN', 'WS', 'WS', 'R', 'RLI', 'S', 'WS', 'ON', 'L', 'EN', 'PDI'], [2, 2, 1, 2, 2, 2, 1, 1, 3, 3, 1, 3], 0], [2, 2, 1, 2, 2, 0, 0, 1, 3, 3, 1, 0]), ('regression: segment separator reset', [['PDI', 'S', 'R', 'ON', 'LRI'], [1, 4, 4, 4, 4], 1], [1, 1, 4, 4, 1]), ('partial-repair probe', [['WS', 'R', 'LRI'], [0, 0, 1], 1], [0, 0, 1]), ('partial-repair probe', [['L', 'B', 'WS', 'PDI', 'L', 'B', 'L', 'L', 'RLI'], [2, 2, 2, 2, 3, 3, 3, 2, 2], 1], [2, 1, 2, 2, 3, 1, 3, 2, 1]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'FSI'], [1, 4], 0], [1, 0]), ('control layout', [['WS', 'L', 'EN', 'R', 'R'], [1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1])], [('regression: segment separator reset', [['S', 'RLI', 'B', 'L', 'WS', 'L', 'WS'], [1, 1, 1, 2, 2, 2, 0], 0], [0, 0, 0, 2, 2, 2, 0]), ('regression: segment separator reset', [['EN', 'LRI', 'LRI', 'S', 'B', 'FSI', 'R', 'ON', 'PDI', 'B'], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3], 1], [2, 1, 1, 1, 1, 2, 2, 2, 1, 1]), ('partial-repair probe', [['WS', 'PDI', 'L', 'L'], [1, 1, 1, 1], 0], [1, 1, 1, 1]), ('partial-repair probe', [['R', 'ON', 'LRI', 'L', 'WS', 'WS', 'PDI', 'ON'], [1, 3, 3, 3, 2, 4, 4, 4], 0], [1, 3, 3, 3, 2, 4, 4, 4]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['EN', 'R', 'ON', 'R', 'WS'], [1, 1, 1, 1, 3], 0], [1, 1, 1, 1, 0]), ('control layout', [['FSI', 'RLI', 'B', 'R', 'ON', 'RLI', 'LRI', 'ON', 'WS'], [2, 2, 2, 2, 2, 1, 2, 0, 0], 1], [1, 1, 1, 2, 2, 1, 2, 0, 1])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, levels, para = x
    out = list(levels)
    n = len(classes)
    RESETTABLE = ('WS', 'FSI', 'LRI', 'RLI', 'PDI')
    j = n - 1
    while j >= 0 and classes[j] in RESETTABLE:
        out[j] = para
        j -= 1
    for i, c in enumerate(classes):
        if c in ('S', 'B', 'WS'):
            out[i] = para
            k = i - 1
            while k >= 0 and classes[k] in RESETTABLE:
                out[k] = para
                k -= 1
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('regression: segment separator reset', [['S', 'R', 'WS', 'ON', 'S'], [0, 0, 0, 0, 3], 1], [1, 0, 0, 0, 1]), ('partial-repair probe', [['WS', 'ON'], [3, 3], 0], [3, 3]), ('partial-repair probe', [['L', 'PDI', 'WS', 'ON', 'ON', 'PDI'], [3, 1, 1, 1, 1, 1], 0], [3, 1, 1, 1, 1, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['ON', 'LRI', 'EN', 'ON'], [1, 2, 2, 2], 0], [1, 2, 2, 2]), ('control layout', [['R', 'FSI', 'L'], [1, 3, 3], 0], [1, 3, 3])], [('regression: segment separator reset', [['R', 'LRI', 'L', 'S', 'R', 'ON', 'R', 'L'], [1, 3, 3, 3, 0, 2, 2, 2], 0], [1, 3, 3, 0, 0, 2, 2, 2]), ('regression: segment separator reset', [['S', 'S', 'PDI', 'WS', 'R', 'ON', 'LRI', 'WS', 'ON', 'R', 'WS', 'ON'], [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], 1], [1, 1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]), ('partial-repair probe', [['FSI', 'L', 'L', 'LRI', 'WS', 'ON', 'WS', 'RLI', 'WS', 'B', 'PDI', 'L'], [2, 2, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1], 0], [2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 1, 1]), ('regression: segment separator reset', [['EN', 'S', 'RLI', 'EN', 'R', 'WS', 'R', 'FSI', 'ON', 'WS', 'WS', 'FSI'], [4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 1], 0], [4, 0, 4, 4, 4, 4, 4, 3, 3, 0, 0, 0]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['R', 'L', 'R', 'WS'], [1, 1, 1, 1], 0], [1, 1, 1, 0]), ('control layout', [['L', 'RLI', 'ON', 'RLI'], [4, 4, 4, 4], 0], [4, 4, 4, 0])], [('regression: segment separator reset', [['WS', 'EN', 'RLI', 'WS', 'PDI', 'R', 'EN', 'WS', 'S'], [2, 2, 2, 2, 3, 3, 3, 0, 0], 1], [2, 2, 2, 2, 3, 3, 3, 1, 1]), ('regression: segment separator reset', [['L', 'WS', 'B', 'ON', 'WS', 'R', 'S', 'WS', 'WS', 'L', 'PDI', 'S'], [1, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4], 0], [1, 0, 0, 2, 2, 2, 0, 2, 2, 4, 0, 0]), ('partial-repair probe', [['EN', 'R', 'B', 'WS', 'R', 'L', 'L', 'ON', 'LRI', 'ON', 'EN'], [2, 2, 4, 4, 4, 1, 1, 1, 4, 1, 3], 1], [2, 2, 1, 4, 4, 1, 1, 1, 4, 1, 3]), ('partial-repair probe', [['L', 'WS', 'B', 'WS', 'ON'], [0, 0, 0, 2, 2], 1], [0, 1, 1, 2, 2]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['ON', 'WS'], [2, 2], 1], [2, 1]), ('control layout', [['RLI', 'ON'], [2, 2], 1], [2, 2])], [('regression: segment separator reset', [['LRI', 'EN', 'WS', 'WS', 'R', 'RLI', 'S', 'WS', 'ON', 'L', 'EN', 'PDI'], [2, 2, 1, 2, 2, 2, 1, 1, 3, 3, 1, 3], 0], [2, 2, 1, 2, 2, 0, 0, 1, 3, 3, 1, 0]), ('regression: segment separator reset', [['PDI', 'S', 'R', 'ON', 'LRI'], [1, 4, 4, 4, 4], 1], [1, 1, 4, 4, 1]), ('partial-repair probe', [['WS', 'R', 'LRI'], [0, 0, 1], 1], [0, 0, 1]), ('partial-repair probe', [['L', 'B', 'WS', 'PDI', 'L', 'B', 'L', 'L', 'RLI'], [2, 2, 2, 2, 3, 3, 3, 2, 2], 1], [2, 1, 2, 2, 3, 1, 3, 2, 1]), ('space before tab', [['R', 'WS', 'S', 'R'], [1, 1, 1, 1], 0], [1, 0, 0, 1]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('control layout', [['L', 'FSI'], [1, 4], 0], [1, 0]), ('control layout', [['WS', 'L', 'EN', 'R', 'R'], [1, 1, 1, 1, 1], 1], [1, 1, 1, 1, 1])], [('regression: segment separator reset', [['S', 'RLI', 'B', 'L', 'WS', 'L', 'WS'], [1, 1, 1, 2, 2, 2, 0], 0], [0, 0, 0, 2, 2, 2, 0]), ('regression: segment separator reset', [['EN', 'LRI', 'LRI', 'S', 'B', 'FSI', 'R', 'ON', 'PDI', 'B'], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3], 1], [2, 1, 1, 1, 1, 2, 2, 2, 1, 1]), ('partial-repair probe', [['WS', 'PDI', 'L', 'L'], [1, 1, 1, 1], 0], [1, 1, 1, 1]), ('partial-repair probe', [['R', 'ON', 'LRI', 'L', 'WS', 'WS', 'PDI', 'ON'], [1, 3, 3, 3, 2, 4, 4, 4], 0], [1, 3, 3, 3, 2, 4, 4, 4]), ('trailing isolate and space', [['R', 'R', 'PDI', 'WS'], [1, 1, 1, 1], 0], [1, 1, 0, 0]), ('all whitespace line', [['WS', 'WS'], [1, 1], 0], [0, 0]), ('control layout', [['EN', 'R', 'ON', 'R', 'WS'], [1, 1, 1, 1, 3], 0], [1, 1, 1, 1, 0]), ('control layout', [['FSI', 'RLI', 'B', 'R', 'ON', 'RLI', 'LRI', 'ON', 'WS'], [2, 2, 2, 2, 2, 1, 2, 0, 0], 1], [1, 1, 1, 2, 2, 1, 2, 0, 1])]]
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)

prompt:
Tabs inside right-to-left text keep the embedded level.

Input [original classes, resolved levels, paragraph level]. Reset to the paragraph level: every S and B; any run of WS and isolate formatting characters (FSI LRI RLI PDI) immediately before an S or B; and such a run at the end of the line. Return levels.

split: open-access


prompt:
The final space on the line keeps its embedded level.

Input [original classes, resolved levels, paragraph level]. Reset to the paragraph level: every S and B; any run of WS and isolate formatting characters (FSI LRI RLI PDI) immediately before an S or B; and such a run at the end of the line. Return levels.

split: open-access