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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a, min(b + 1, len(levels))))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: selection end exclusivity', [[3, 1, 1, 1, 1, 1, 1, 1, 1, 1], 1, 5], [[5, 9]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 3, 3, 3, 3, 1, 1], 0, 8], [[3, 11]]), ('regression: selection end exclusivity', [[1, 1], 0, 1], [[1, 2]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 1], 6, 6], []), ('control layout', [[1], 1, 1], []), ('control layout', [[3], 1, 1], [])], [('regression: selection end exclusivity', [[1, 1, 0, 0, 0, 0], 2, 2], []), ('regression: selection end exclusivity', [[3, 3, 3, 3, 3], 0, 3], [[2, 5]]), ('partial-repair probe', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('regression: selection end exclusivity', [[3, 3, 3, 0, 3, 3, 3, 1, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1, 1], 2, 0], [[2, 4]]), ('regression: selection end exclusivity', [[3, 3], 1, 1], []), ('regression: selection end exclusivity', [[2, 2, 2, 2, 2, 2, 2, 2], 3, 5], [[3, 5]]), ('regression: selection end exclusivity', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0], 1, 1], []), ('control layout', [[0, 0, 0], 3, 3], [])], [('regression: selection end exclusivity', [[1, 1, 1, 0], 3, 1], [[0, 2]]), ('regression: selection end exclusivity', [[4, 1, 1, 1, 1], 3, 3], []), ('regression: selection end exclusivity', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: selection end exclusivity', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 8, 10], [[8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1], 0, 0], []), ('regression: selection end exclusivity', [[0, 3, 0, 1], 0, 2], [[0, 2]]), ('regression: selection end exclusivity', [[0, 1, 1, 1, 1, 0, 0, 0], 6, 3], [[1, 3], [5, 6]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 1, 0, 0], 6, 7], [[6, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[1], 1, 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a + 1, min(b + 1, len(levels))))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: selection end exclusivity', [[3, 1, 1, 1, 1, 1, 1, 1, 1, 1], 1, 5], [[5, 9]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 3, 3, 3, 3, 1, 1], 0, 8], [[3, 11]]), ('regression: selection end exclusivity', [[1, 1], 0, 1], [[1, 2]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 1], 6, 6], []), ('control layout', [[1], 1, 1], []), ('control layout', [[3], 1, 1], [])], [('regression: selection end exclusivity', [[1, 1, 0, 0, 0, 0], 2, 2], []), ('regression: selection end exclusivity', [[3, 3, 3, 3, 3], 0, 3], [[2, 5]]), ('partial-repair probe', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('regression: selection end exclusivity', [[3, 3, 3, 0, 3, 3, 3, 1, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1, 1], 2, 0], [[2, 4]]), ('regression: selection end exclusivity', [[3, 3], 1, 1], []), ('regression: selection end exclusivity', [[2, 2, 2, 2, 2, 2, 2, 2], 3, 5], [[3, 5]]), ('regression: selection end exclusivity', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0], 1, 1], []), ('control layout', [[0, 0, 0], 3, 3], [])], [('regression: selection end exclusivity', [[1, 1, 1, 0], 3, 1], [[0, 2]]), ('regression: selection end exclusivity', [[4, 1, 1, 1, 1], 3, 3], []), ('regression: selection end exclusivity', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: selection end exclusivity', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 8, 10], [[8, 10]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1], 2, 2], []), ('control layout', [[2, 2], 2, 2], [])], [('regression: selection end exclusivity', [[1, 1, 1], 0, 0], []), ('regression: selection end exclusivity', [[0, 3, 0, 1], 0, 2], [[0, 2]]), ('regression: selection end exclusivity', [[0, 1, 1, 1, 1, 0, 0, 0], 6, 3], [[1, 3], [5, 6]]), ('regression: selection end exclusivity', [[3, 3, 1, 1, 1, 1, 0, 0], 6, 7], [[6, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[1], 1, 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:
Highlights include one character past the selection.

Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = [pos[i] for i in range(a, b)]
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: slot sorting', [[0, 0, 0, 0, 2, 0, 0, 0, 3, 3, 0, 0], 12, 7], [[7, 12]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 1], 8, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]]), ('control layout', [[2, 2, 2, 1, 1, 1, 1, 3, 3], 6, 5], [[3, 4]]), ('control layout', [[0], 1, 1], [])], [('regression: slot sorting', [[3, 3, 3, 3, 3, 3, 3, 2], 8, 4], [[0, 3], [7, 8]]), ('regression: slot sorting', [[1, 1, 1, 1, 3, 1, 1, 1, 2, 2, 2], 9, 3], [[0, 1], [3, 8]]), ('regression: slot sorting', [[3, 3, 3, 1, 1, 1, 2], 4, 2], [[3, 5]]), ('regression: slot sorting', [[3, 3, 3, 2, 2, 1, 1, 1, 1, 2, 2], 3, 8], [[3, 6], [9, 11]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[1, 1, 2, 2, 2, 2, 1, 3, 3, 1, 1], 8, 9], [[2, 3]])], [('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: slot sorting', [[1, 1, 1, 1, 4, 4, 3, 2, 2], 4, 7], [[0, 3]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0, 0], 0, 0], []), ('control layout', [[3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2], 2, 1], [[9, 10]]), ('control layout', [[1, 1], 1, 1], [])], [('regression: slot sorting', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1], 6, 11], [[0, 5]]), ('regression: slot sorting', [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3], 8, 3], [[4, 9]]), ('regression: slot sorting', [[3, 3, 3, 3, 2], 4, 2], [[0, 2]]), ('partial-repair probe', [[4, 2, 2, 2, 2, 2, 2, 2], 7, 1], [[1, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2], 0, 0], []), ('control layout', [[1, 3, 3, 3, 3, 0, 0], 1, 0], [[4, 5]])], [('regression: slot sorting', [[0, 1, 1, 2, 2, 0, 0, 0, 0], 2, 8], [[1, 4], [5, 8]]), ('regression: slot sorting', [[2, 2, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 4], 3, 1], [[3, 5]]), ('partial-repair probe', [[2, 2, 4, 2, 2, 2, 2, 2], 7, 4], [[4, 7]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]])]]
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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted((pos[i] for i in range(a, b)), reverse=True)
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('regression: slot sorting', [[0, 0, 0, 0, 2, 0, 0, 0, 3, 3, 0, 0], 12, 7], [[7, 12]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('partial-repair probe', [[2, 2, 2, 2, 1, 1, 4, 4, 4, 4, 1], 8, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]]), ('control layout', [[2, 2, 2, 1, 1, 1, 1, 3, 3], 6, 5], [[3, 4]]), ('control layout', [[0], 1, 1], [])], [('regression: slot sorting', [[3, 3, 3, 3, 3, 3, 3, 2], 8, 4], [[0, 3], [7, 8]]), ('regression: slot sorting', [[1, 1, 1, 1, 3, 1, 1, 1, 2, 2, 2], 9, 3], [[0, 1], [3, 8]]), ('regression: slot sorting', [[3, 3, 3, 1, 1, 1, 2], 4, 2], [[3, 5]]), ('regression: slot sorting', [[3, 3, 3, 2, 2, 1, 1, 1, 1, 2, 2], 3, 8], [[3, 6], [9, 11]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[1, 1, 2, 2, 2, 2, 1, 3, 3, 1, 1], 8, 9], [[2, 3]])], [('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: slot sorting', [[1, 1, 1, 1, 4, 4, 3, 2, 2], 4, 7], [[0, 3]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0, 0], 0, 0], []), ('control layout', [[3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2], 2, 1], [[9, 10]]), ('control layout', [[1, 1], 1, 1], [])], [('regression: slot sorting', [[4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1], 6, 11], [[0, 5]]), ('regression: slot sorting', [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3], 8, 3], [[4, 9]]), ('regression: slot sorting', [[3, 3, 3, 3, 2], 4, 2], [[0, 2]]), ('partial-repair probe', [[4, 2, 2, 2, 2, 2, 2, 2], 7, 1], [[1, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2], 0, 0], []), ('control layout', [[1, 3, 3, 3, 3, 0, 0], 1, 0], [[4, 5]])], [('regression: slot sorting', [[0, 1, 1, 2, 2, 0, 0, 0, 0], 2, 8], [[1, 4], [5, 8]]), ('regression: slot sorting', [[2, 2, 1, 1], 4, 1], [[0, 2], [3, 4]]), ('regression: slot sorting', [[1, 1, 1, 4, 4, 4], 3, 1], [[3, 5]]), ('partial-repair probe', [[2, 2, 4, 2, 2, 2, 2, 2], 7, 4], [[4, 7]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 3, 3, 3, 0, 0, 3, 3], 8, 8], []), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]])]]
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:
RTL selections are drawn as many one-unit fragments.

Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] >= p - 1:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('regression: rectangle adjacency', [[1, 1, 1, 1, 1, 3, 0, 0, 0, 0], 1, 10], [[0, 5], [6, 10]]), ('partial-repair probe', [[0, 3, 0, 0, 0, 3], 2, 0], [[0, 2]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('partial-repair probe', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('partial-repair probe', [[3, 3, 3, 3, 2, 2, 2, 1, 1], 4, 1], [[2, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]])], [('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('regression: rectangle adjacency', [[4, 4, 1, 1, 1, 1, 2], 1, 6], [[1, 5], [6, 7]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0, 0], 1, 2], [[1, 2]]), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[4, 4, 4, 4, 3, 2], 1, 5], [[0, 1], [2, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('partial-repair probe', [[3, 2, 2, 2, 2, 0, 1], 7, 2], [[2, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 2], 4, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2, 0, 1, 3], 1, 0], [[0, 1]]), ('control layout', [[1, 1, 1, 1], 1, 1], [])], [('regression: rectangle adjacency', [[2, 2, 2, 1, 1], 1, 4], [[1, 2], [3, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('partial-repair probe', [[2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1], 11, 6], [[0, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[4, 4, 4, 1, 1], 0, 1], [[2, 3]]), ('control layout', [[2, 2, 2, 1, 4, 4], 4, 3], [[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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] + 1 == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('regression: rectangle adjacency', [[1, 1, 1, 1, 1, 3, 0, 0, 0, 0], 1, 10], [[0, 5], [6, 10]]), ('partial-repair probe', [[0, 3, 0, 0, 0, 3], 2, 0], [[0, 2]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('regression: rectangle adjacency', [[2, 2, 2, 2, 1, 1, 1, 4, 4, 1, 1], 8, 2], [[2, 3], [4, 7], [9, 11]]), ('partial-repair probe', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('partial-repair probe', [[3, 3, 3, 3, 2, 2, 2, 1, 1], 4, 1], [[2, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 2, 2, 2, 4, 4, 4, 4, 1, 1, 1], 10, 9], [[1, 2]]), ('control layout', [[4, 4, 4, 4, 1, 1, 3], 1, 0], [[3, 4]])], [('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 3, 0, 0, 3, 3, 3, 0], 3, 9], [[3, 7], [8, 10]]), ('regression: rectangle adjacency', [[4, 4, 1, 1, 1, 1, 2], 1, 6], [[1, 5], [6, 7]]), ('partial-repair probe', [[0, 0, 0, 0, 0, 2, 0, 0, 1, 0], 8, 6], [[6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[0, 0], 1, 2], [[1, 2]]), ('control layout', [[3, 3, 3, 1, 1], 3, 4], [[1, 2]])], [('regression: rectangle adjacency', [[4, 4, 4, 4, 3, 2], 1, 5], [[0, 1], [2, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('partial-repair probe', [[3, 2, 2, 2, 2, 0, 1], 7, 2], [[2, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 2], 4, 6], [[1, 3]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2, 0, 1, 3], 1, 0], [[0, 1]]), ('control layout', [[1, 1, 1, 1], 1, 1], [])], [('regression: rectangle adjacency', [[2, 2, 2, 1, 1], 1, 4], [[1, 2], [3, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 3, 1], 2, 4], [[2, 3], [4, 5]]), ('regression: rectangle adjacency', [[0, 0, 0, 0, 2, 2, 2, 2, 1], 2, 6], [[2, 4], [5, 7]]), ('partial-repair probe', [[2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1], 11, 6], [[0, 5]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[4, 4, 4, 1, 1], 0, 1], [[2, 3]]), ('control layout', [[2, 2, 2, 1, 4, 4], 4, 3], [[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:
Separate highlight fragments are fused across unselected gaps.

Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = a, b
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: backward selection normalisation', [[2, 4, 4, 3, 3], 4, 1], [[2, 5]]), ('partial-repair probe', [[0, 0, 0, 1, 1, 1, 1], 1, 4], [[1, 3], [6, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 4, 2, 2, 2, 2, 1], 4, 9], [[1, 4], [6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 1, 1], []), ('control layout', [[1, 1, 1], 0, 0], []), ('control layout', [[3], 1, 1], [])], [('regression: backward selection normalisation', [[1, 3, 3], 1, 0], [[2, 3]]), ('regression: backward selection normalisation', [[1, 1, 2, 1, 2, 2, 2, 2, 4, 4], 5, 1], [[0, 1], [6, 9]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('partial-repair probe', [[0, 2, 2, 0, 0, 0, 0, 2, 2], 0, 4], [[0, 4]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1, 1, 2], 3, 3], []), ('control layout', [[4, 4, 2, 3, 3, 3, 4, 2, 2, 2, 2], 6, 6], [])], [('regression: backward selection normalisation', [[4, 4, 3, 4], 4, 2], [[0, 2]]), ('regression: backward selection normalisation', [[2, 2, 2, 2, 2, 4, 4], 7, 0], [[0, 7]]), ('partial-repair probe', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 1, 3, 3, 3, 3], 0, 0], []), ('control layout', [[2, 2], 1, 1], [])], [('regression: backward selection normalisation', [[1], 1, 0], [[0, 1]]), ('regression: backward selection normalisation', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('partial-repair probe', [[2, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4], 5, 11], [[0, 4], [9, 11]]), ('partial-repair probe', [[1, 1, 1, 1, 0, 0, 0], 3, 7], [[0, 1], [4, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0], 1, 1], []), ('control layout', [[1], 0, 0], [])], [('regression: backward selection normalisation', [[3, 3, 1, 1, 1, 4, 1, 1, 1, 1], 8, 6], [[2, 4]]), ('regression: backward selection normalisation', [[0, 0, 3, 3, 3, 2, 3, 0, 0], 8, 4], [[2, 3], [5, 8]]), ('partial-repair probe', [[0, 0, 0, 0], 0, 4], [[0, 4]]), ('partial-repair probe', [[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1], 4, 7], [[7, 10]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3], 2, 2], []), ('control layout', [[1], 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = b, a
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(pos[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: backward selection normalisation', [[2, 4, 4, 3, 3], 4, 1], [[2, 5]]), ('partial-repair probe', [[0, 0, 0, 1, 1, 1, 1], 1, 4], [[1, 3], [6, 7]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 4, 2, 2, 2, 2, 1], 4, 9], [[1, 4], [6, 8]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[1, 1], 1, 1], []), ('control layout', [[1, 1, 1], 0, 0], []), ('control layout', [[3], 1, 1], [])], [('regression: backward selection normalisation', [[1, 3, 3], 1, 0], [[2, 3]]), ('regression: backward selection normalisation', [[1, 1, 2, 1, 2, 2, 2, 2, 4, 4], 5, 1], [[0, 1], [6, 9]]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 2, 8], [[0, 5], [7, 8]]), ('partial-repair probe', [[0, 2, 2, 0, 0, 0, 0, 2, 2], 0, 4], [[0, 4]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 1, 1, 2], 3, 3], []), ('control layout', [[4, 4, 2, 3, 3, 3, 4, 2, 2, 2, 2], 6, 6], [])], [('regression: backward selection normalisation', [[4, 4, 3, 4], 4, 2], [[0, 2]]), ('regression: backward selection normalisation', [[2, 2, 2, 2, 2, 4, 4], 7, 0], [[0, 7]]), ('partial-repair probe', [[1, 1, 1, 4, 4, 3, 3, 3, 2], 3, 7], [[1, 5]]), ('partial-repair probe', [[2, 2, 2, 2, 2, 4, 4, 4, 3, 3, 3], 10, 11], [[5, 6]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[4, 1, 3, 3, 3, 3], 0, 0], []), ('control layout', [[2, 2], 1, 1], [])], [('regression: backward selection normalisation', [[1], 1, 0], [[0, 1]]), ('regression: backward selection normalisation', [[3, 3, 3, 0], 4, 3], [[3, 4]]), ('partial-repair probe', [[2, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4], 5, 11], [[0, 4], [9, 11]]), ('partial-repair probe', [[1, 1, 1, 1, 0, 0, 0], 3, 7], [[0, 1], [4, 7]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[0], 1, 1], []), ('control layout', [[1], 0, 0], [])], [('regression: backward selection normalisation', [[3, 3, 1, 1, 1, 4, 1, 1, 1, 1], 8, 6], [[2, 4]]), ('regression: backward selection normalisation', [[0, 0, 3, 3, 3, 2, 3, 0, 0], 8, 4], [[2, 3], [5, 8]]), ('partial-repair probe', [[0, 0, 0, 0], 0, 4], [[0, 4]]), ('partial-repair probe', [[0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1], 4, 7], [[7, 10]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3], 2, 2], []), ('control layout', [[1], 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:
Selections dragged right-to-left highlight nothing.

Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = list(range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: logical to visual mapping', [[4, 4, 2, 4, 1], 4, 2], [[3, 5]]), ('regression: logical to visual mapping', [[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1], 6, 3], [[5, 8]]), ('regression: logical to visual mapping', [[4, 4, 4, 1], 2, 3], [[3, 4]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 2, 2, 2, 2, 2], 2, 4], [[2, 4]]), ('control layout', [[2, 2, 3, 3, 2, 2, 0, 0], 8, 2], [[2, 8]])], [('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 0], 12, 9], [[0, 2], [11, 12]]), ('regression: logical to visual mapping', [[1, 0, 1, 2, 2, 2, 3, 2, 1, 1, 3], 9, 4], [[4, 5], [6, 10]]), ('regression: logical to visual mapping', [[4, 4, 2, 2, 1, 1, 1, 1, 1, 1], 7, 0], [[3, 10]]), ('regression: logical to visual mapping', [[2, 2, 2, 2, 1, 1, 1], 0, 1], [[3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('control layout', [[2, 3, 3], 3, 3], [])], [('regression: logical to visual mapping', [[3, 3, 3, 3, 1], 4, 5], [[0, 1]]), ('regression: logical to visual mapping', [[1, 1, 1, 2], 3, 0], [[1, 4]]), ('regression: logical to visual mapping', [[1, 1, 1, 3, 2, 2, 2, 2, 4, 4], 2, 6], [[0, 3], [7, 8]]), ('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 1, 1, 1], 2, 1], [[4, 5]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[2, 2], 2, 1], [[1, 2]]), ('control layout', [[0, 0, 0, 0, 0, 1, 1, 1], 4, 2], [[2, 4]])], [('regression: logical to visual mapping', [[3, 3], 1, 0], [[1, 2]]), ('regression: logical to visual mapping', [[2, 2, 2, 1, 4, 4], 4, 3], [[2, 3]]), ('regression: logical to visual mapping', [[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1], 6, 3], [[5, 8]]), ('regression: logical to visual mapping', [[1, 4, 4, 4, 4, 4, 4, 1, 1, 2], 10, 5], [[0, 3], [7, 9]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 0, 0, 1, 1], 2, 0], [[0, 2]]), ('control layout', [[2, 1, 1, 1, 1, 1, 4], 7, 0], [[0, 7]])], [('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 1, 1], 0, 3], [[2, 5]]), ('regression: logical to visual mapping', [[2, 4, 1, 1, 1, 1, 1], 6, 1], [[1, 5], [6, 7]]), ('regression: logical to visual mapping', [[4, 4, 4, 4, 4, 4, 1, 1, 1, 2, 2], 9, 1], [[2, 5], [6, 11]]), ('regression: logical to visual mapping', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2, 2, 2, 2, 4], 2, 0], [[0, 2]]), ('control layout', [[1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1], 10, 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, a, b = x
    a, b = min(a, b), max(a, b)
    vis = reorder(levels)
    pos = [0] * len(levels)
    for v, i in enumerate(vis):
        pos[i] = v
    sel = sorted(vis[i] for i in range(a, b))
    rects = []
    for p in sel:
        if rects and rects[-1][1] == p:
            rects[-1][1] = p + 1
        else:
            rects.append([p, p + 1])
    return rects
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('regression: logical to visual mapping', [[4, 4, 2, 4, 1], 4, 2], [[3, 5]]), ('regression: logical to visual mapping', [[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1], 6, 3], [[5, 8]]), ('regression: logical to visual mapping', [[4, 4, 4, 1], 2, 3], [[3, 4]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3], 10, 10], []), ('control layout', [[3, 2, 2, 2, 2, 2], 2, 4], [[2, 4]]), ('control layout', [[2, 2, 3, 3, 2, 2, 0, 0], 8, 2], [[2, 8]])], [('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 0], 12, 9], [[0, 2], [11, 12]]), ('regression: logical to visual mapping', [[1, 0, 1, 2, 2, 2, 3, 2, 1, 1, 3], 9, 4], [[4, 5], [6, 10]]), ('regression: logical to visual mapping', [[4, 4, 2, 2, 1, 1, 1, 1, 1, 1], 7, 0], [[3, 10]]), ('regression: logical to visual mapping', [[2, 2, 2, 2, 1, 1, 1], 0, 1], [[3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 3, 3, 3, 3, 3, 0, 0, 0, 2, 2], 6, 9], [[6, 9]]), ('control layout', [[2, 3, 3], 3, 3], [])], [('regression: logical to visual mapping', [[3, 3, 3, 3, 1], 4, 5], [[0, 1]]), ('regression: logical to visual mapping', [[1, 1, 1, 2], 3, 0], [[1, 4]]), ('regression: logical to visual mapping', [[1, 1, 1, 3, 2, 2, 2, 2, 4, 4], 2, 6], [[0, 3], [7, 8]]), ('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 1, 1, 1], 2, 1], [[4, 5]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[2, 2], 2, 1], [[1, 2]]), ('control layout', [[0, 0, 0, 0, 0, 1, 1, 1], 4, 2], [[2, 4]])], [('regression: logical to visual mapping', [[3, 3], 1, 0], [[1, 2]]), ('regression: logical to visual mapping', [[2, 2, 2, 1, 4, 4], 4, 3], [[2, 3]]), ('regression: logical to visual mapping', [[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1], 6, 3], [[5, 8]]), ('regression: logical to visual mapping', [[1, 4, 4, 4, 4, 4, 4, 1, 1, 2], 10, 5], [[0, 3], [7, 9]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('control layout', [[1, 0, 0, 1, 1], 2, 0], [[0, 2]]), ('control layout', [[2, 1, 1, 1, 1, 1, 4], 7, 0], [[0, 7]])], [('regression: logical to visual mapping', [[2, 2, 2, 2, 2, 2, 1, 1], 0, 3], [[2, 5]]), ('regression: logical to visual mapping', [[2, 4, 1, 1, 1, 1, 1], 6, 1], [[1, 5], [6, 7]]), ('regression: logical to visual mapping', [[4, 4, 4, 4, 4, 4, 1, 1, 1, 2, 2], 9, 1], [[2, 5], [6, 11]]), ('regression: logical to visual mapping', [[2, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4], 7, 10], [[0, 2], [3, 4]]), ('backward selection', [[1, 1, 1], 3, 1], [[0, 2]]), ('selection crossing direction change', [[0, 0, 1, 1, 0], 1, 4], [[1, 4]]), ('control layout', [[2, 2, 2, 2, 2, 4], 2, 0], [[0, 2]]), ('control layout', [[1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1], 10, 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:
Highlights follow the logical range as if the line were unidirectional.

Input [levels, anchor, focus]. The logical selection covers characters min..max-1. Each selected character occupies its unit visual slot (level reversal); merge adjacent slots into [x0, x1) rectangles sorted by x. Return the rectangles.

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(px // 2, n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: left clamp', [[1, 3], -1], [1, True, 2]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 2, 2], 1], [7, True, 8]), ('regression: left clamp', [[3, 3, 1, 1, 1, 1, 4, 2], -3], [6, False, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1, 1, 1, 1, 1, 1, 1, 0, 0], 15], [7, True, 8]), ('control layout', [[3, 2, 2, 3, 1, 1, 1, 1, 1], 10], [0, True, 1])], [('regression: left clamp', [[1, 1, 1, 1], -1], [3, True, 4]), ('regression: left clamp', [[2, 2, 1, 1, 1, 3], -1], [5, True, 6]), ('regression: left clamp', [[1, 1, 1, 1, 0, 3, 3], -1], [3, True, 4]), ('regression: left clamp', [[2, 2, 1, 0, 0, 0, 0], -2], [2, True, 3]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[2, 2, 2, 1, 1, 1, 1], 15], [2, True, 3])], [('regression: left clamp', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: left clamp', [[2, 2, 2, 2, 2, 2], -1], [0, False, 0]), ('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('partial-repair probe', [[1, 1, 1, 1], 1], [3, False, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4], 8], [4, False, 4]), ('control layout', [[0, 0, 0, 3], 7], [3, False, 3])], [('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: left clamp', [[3, 3, 1, 1, 1, 1], -1], [5, True, 6]), ('regression: left clamp', [[2, 2, 4, 4, 4, 4, 4, 2, 2], -1], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[3, 3, 3, 2, 2, 2, 2, 0, 1, 1], 20], [8, False, 8]), ('control layout', [[2, 2, 2, 2], 7], [3, True, 4])], [('regression: left clamp', [[0, 0, 1, 1, 0], -1], [0, False, 0]), ('regression: left clamp', [[1, 1, 1, 1, 1, 3, 1, 1], -2], [7, True, 8]), ('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('regression: left clamp', [[0, 1], -2], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('control layout', [[0, 0, 0, 1, 1, 1, 1, 3, 3], 3], [1, True, 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 1), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: left clamp', [[1, 3], -1], [1, True, 2]), ('partial-repair probe', [[1, 1, 1, 1, 1, 1, 1, 2, 2], 1], [7, True, 8]), ('regression: left clamp', [[3, 3, 1, 1, 1, 1, 4, 2], -3], [6, False, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1, 1, 1, 1, 1, 1, 1, 0, 0], 15], [7, True, 8]), ('control layout', [[3, 2, 2, 3, 1, 1, 1, 1, 1], 10], [0, True, 1])], [('regression: left clamp', [[1, 1, 1, 1], -1], [3, True, 4]), ('regression: left clamp', [[2, 2, 1, 1, 1, 3], -1], [5, True, 6]), ('regression: left clamp', [[1, 1, 1, 1, 0, 3, 3], -1], [3, True, 4]), ('regression: left clamp', [[2, 2, 1, 0, 0, 0, 0], -2], [2, True, 3]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[2, 2, 2, 1, 1, 1, 1], 15], [2, True, 3])], [('regression: left clamp', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: left clamp', [[2, 2, 2, 2, 2, 2], -1], [0, False, 0]), ('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('partial-repair probe', [[1, 1, 1, 1], 1], [3, False, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 2, 4, 4, 4], 8], [4, False, 4]), ('control layout', [[0, 0, 0, 3], 7], [3, False, 3])], [('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: left clamp', [[3, 3, 1, 1, 1, 1], -1], [5, True, 6]), ('regression: left clamp', [[2, 2, 4, 4, 4, 4, 4, 2, 2], -1], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[3, 3, 3, 2, 2, 2, 2, 0, 1, 1], 20], [8, False, 8]), ('control layout', [[2, 2, 2, 2], 7], [3, True, 4])], [('regression: left clamp', [[0, 0, 1, 1, 0], -1], [0, False, 0]), ('regression: left clamp', [[1, 1, 1, 1, 1, 3, 1, 1], -2], [7, True, 8]), ('regression: left clamp', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('regression: left clamp', [[0, 1], -2], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('control layout', [[0, 0, 0, 1, 1, 1, 1, 3, 3], 3], [1, True, 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:
Clicks left of the line hit characters at the far end.

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 2, 2, 2, 2, 0, 0], 0], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 4, 4, 4, 4, 3], -3], [8, True, 9]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[0], 1], [0, True, 1])], [('regression: trailing side for RTL', [[1, 1, 1, 3, 3, 3, 3, 2, 3], 11], [8, False, 8]), ('regression: trailing side for RTL', [[0, 0, 2, 3, 3, 3, 3, 3], 19], [3, False, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: trailing side for RTL', [[2, 2, 2, 3, 3, 3], 6], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 0, 0, 2, 2], 15], [5, True, 6]), ('control layout', [[1, 1, 0], 7], [2, True, 3])], [('regression: trailing side for RTL', [[1, 1, 2, 3], 2], [3, True, 4]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: trailing side for RTL', [[1, 1, 1, 0, 3, 3, 3, 3, 0, 0], 14], [4, True, 5]), ('regression: trailing side for RTL', [[1, 1, 1, 1], -1], [3, True, 4]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2, 2, 2, 1, 1, 3, 1], 11], [1, True, 2]), ('control layout', [[0, 0, 0, 1], 0], [0, False, 0])], [('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 1], [5, False, 5]), ('regression: trailing side for RTL', [[2, 2, 2, 2, 2, 2, 3, 3], 17], [6, False, 6]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4]), ('regression: trailing side for RTL', [[1, 1], -1], [1, True, 2]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1, 2, 2], 1], [1, True, 2]), ('control layout', [[4, 4], -2], [0, False, 0])], [('regression: trailing side for RTL', [[2, 2, 2, 1, 1], -3], [4, True, 5]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 2, 2, 2, 2, 1, 1], 4], [3, True, 4]), ('regression: trailing side for RTL', [[1, 0, 3, 3, 3, 3, 3, 3, 3], -2], [0, True, 1]), ('regression: trailing side for RTL', [[1, 1], 0], [1, True, 2]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[4], 4], [0, True, 1]), ('control layout', [[2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 16], [5, False, 5])]]
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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half and not rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 2, 2, 2, 2, 0, 0], 0], [2, True, 3]), ('regression: trailing side for RTL', [[1, 1, 1, 1, 4, 4, 4, 4, 3], -3], [8, True, 9]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('control layout', [[0], 1], [0, True, 1])], [('regression: trailing side for RTL', [[1, 1, 1, 3, 3, 3, 3, 2, 3], 11], [8, False, 8]), ('regression: trailing side for RTL', [[0, 0, 2, 3, 3, 3, 3, 3], 19], [3, False, 3]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: trailing side for RTL', [[2, 2, 2, 3, 3, 3], 6], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 0, 0, 2, 2], 15], [5, True, 6]), ('control layout', [[1, 1, 0], 7], [2, True, 3])], [('regression: trailing side for RTL', [[1, 1, 2, 3], 2], [3, True, 4]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: trailing side for RTL', [[1, 1, 1, 0, 3, 3, 3, 3, 0, 0], 14], [4, True, 5]), ('regression: trailing side for RTL', [[1, 1, 1, 1], -1], [3, True, 4]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2, 2, 2, 1, 1, 3, 1], 11], [1, True, 2]), ('control layout', [[0, 0, 0, 1], 0], [0, False, 0])], [('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 1], [5, False, 5]), ('regression: trailing side for RTL', [[2, 2, 2, 2, 2, 2, 3, 3], 17], [6, False, 6]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4]), ('regression: trailing side for RTL', [[1, 1], -1], [1, True, 2]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1, 2, 2], 1], [1, True, 2]), ('control layout', [[4, 4], -2], [0, False, 0])], [('regression: trailing side for RTL', [[2, 2, 2, 1, 1], -3], [4, True, 5]), ('regression: trailing side for RTL', [[3, 3, 3, 3, 2, 2, 2, 2, 1, 1], 4], [3, True, 4]), ('regression: trailing side for RTL', [[1, 0, 3, 3, 3, 3, 3, 3, 3], -2], [0, True, 1]), ('regression: trailing side for RTL', [[1, 1], 0], [1, True, 2]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[4], 4], [0, True, 1]), ('control layout', [[2, 2, 2, 2, 2, 2, 2, 1, 1, 1], 16], [5, False, 5])]]
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:
Clicking the right half of an RTL character places the caret after it logically.

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = v
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1], 8], [2, False, 2]), ('regression: visual slot lookup', [[1, 1, 1, 1, 3, 3, 0, 1, 2, 2], 1], [5, False, 5]), ('partial-repair probe', [[0, 0, 0, 0], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[2, 2, 2, 2, 2, 4, 2, 2, 2], 9], [4, True, 5])], [('regression: visual slot lookup', [[1, 1, 1, 3], 10], [0, False, 0]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1], 9], [1, False, 1]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 1, 1], -3], [2, True, 3]), ('regression: visual slot lookup', [[1, 1, 2, 2, 2, 3, 3], 16], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[4, 4, 4, 1, 4, 4, 4], 6], [3, True, 4])], [('regression: visual slot lookup', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('regression: visual slot lookup', [[1, 2], 7], [0, False, 0]), ('regression: visual slot lookup', [[4, 4, 4, 4, 1, 1], 11], [3, True, 4]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1, 1, 2], 0], [6, False, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2], 4], [0, True, 1]), ('control layout', [[1], 3], [0, False, 0])], [('regression: visual slot lookup', [[1, 3, 3, 3, 3, 1, 1, 1], 9], [3, False, 3]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 0, 3], -1], [2, True, 3]), ('partial-repair probe', [[1, 0, 0, 0, 0], -1], [0, True, 1]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1, 1, 1, 3], 17], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[1], -2], [0, True, 1])], [('regression: visual slot lookup', [[3, 3, 0, 0, 0], -2], [1, True, 2]), ('regression: visual slot lookup', [[1, 1, 1, 3, 3], 13], [0, False, 0]), ('regression: visual slot lookup', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: visual slot lookup', [[0, 0, 0, 2, 2, 3, 3, 3, 3, 1], 20], [5, False, 5]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 0], [0, True, 1]), ('control layout', [[2, 2, 2], 3], [1, True, 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[n - 1 - v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1], 8], [2, False, 2]), ('regression: visual slot lookup', [[1, 1, 1, 1, 3, 3, 0, 1, 2, 2], 1], [5, False, 5]), ('partial-repair probe', [[0, 0, 0, 0], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[2, 2, 2, 2, 2, 4, 2, 2, 2], 9], [4, True, 5])], [('regression: visual slot lookup', [[1, 1, 1, 3], 10], [0, False, 0]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1], 9], [1, False, 1]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 1, 1], -3], [2, True, 3]), ('regression: visual slot lookup', [[1, 1, 2, 2, 2, 3, 3], 16], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 4], [0, False, 0]), ('control layout', [[4, 4, 4, 1, 4, 4, 4], 6], [3, True, 4])], [('regression: visual slot lookup', [[3, 3, 3, 3, 3, 1, 2, 2, 2, 2], 11], [4, False, 4]), ('regression: visual slot lookup', [[1, 2], 7], [0, False, 0]), ('regression: visual slot lookup', [[4, 4, 4, 4, 1, 1], 11], [3, True, 4]), ('regression: visual slot lookup', [[2, 2, 2, 1, 1, 1, 2], 0], [6, False, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[2], 4], [0, True, 1]), ('control layout', [[1], 3], [0, False, 0])], [('regression: visual slot lookup', [[1, 3, 3, 3, 3, 1, 1, 1], 9], [3, False, 3]), ('regression: visual slot lookup', [[1, 1, 1, 0, 0, 0, 3], -1], [2, True, 3]), ('partial-repair probe', [[1, 0, 0, 0, 0], -1], [0, True, 1]), ('regression: visual slot lookup', [[1, 1, 1, 1, 1, 1, 1, 1, 3], 17], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[1], -2], [0, True, 1])], [('regression: visual slot lookup', [[3, 3, 0, 0, 0], -2], [1, True, 2]), ('regression: visual slot lookup', [[1, 1, 1, 3, 3], 13], [0, False, 0]), ('regression: visual slot lookup', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('regression: visual slot lookup', [[0, 0, 0, 2, 2, 3, 3, 3, 3, 1], 20], [5, False, 5]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1], 0], [0, True, 1]), ('control layout', [[2, 2, 2], 3], [1, True, 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:
Clicks hit the character with the logical index equal to the slot.

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v > 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: half boundary', [[3, 3, 3, 3, 1, 1, 1, 1, 1], 15], [1, False, 1]), ('partial-repair probe', [[4, 4, 4, 4, 1, 1, 1, 1], 16], [3, True, 4]), ('partial-repair probe', [[1, 3, 3, 3, 3, 1, 3], 14], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 3, 1, 1, 1, 1, 3], 14], [2, True, 3]), ('control layout', [[1, 1], 2], [0, True, 1])], [('regression: half boundary', [[2, 2, 1, 1, 2, 2, 2, 2, 2, 2], 1], [4, True, 5]), ('regression: half boundary', [[3, 3, 3, 1, 1, 1], 3], [4, False, 4]), ('partial-repair probe', [[1, 1, 1, 1, 2, 2, 2], -3], [4, False, 4]), ('partial-repair probe', [[4, 4, 4, 4, 4, 4], 14], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 0, 0, 0], 9], [3, True, 4]), ('control layout', [[2, 2], 2], [1, False, 1])], [('regression: half boundary', [[0, 0, 0, 0, 3, 3, 3, 1, 3], 13], [6, False, 6]), ('regression: half boundary', [[3, 3, 3], 1], [2, False, 2]), ('partial-repair probe', [[1, 1], -1], [1, True, 2]), ('partial-repair probe', [[4, 4, 4, 2, 2, 2], 12], [5, True, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1, 2, 3], 2], [8, True, 9]), ('control layout', [[2, 2, 1, 1, 1, 2], 15], [1, True, 2])], [('regression: half boundary', [[2, 2, 2, 2, 2], 3], [1, True, 2]), ('regression: half boundary', [[1, 0, 0, 0, 0], 3], [1, True, 2]), ('partial-repair probe', [[1, 1, 1], -1], [2, True, 3]), ('partial-repair probe', [[1, 1, 3, 3, 3, 3, 3, 3, 3], 18], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[2, 2, 2, 2], -2], [0, False, 0])], [('regression: half boundary', [[4, 4, 4, 1, 1, 1], 3], [4, False, 4]), ('regression: half boundary', [[0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 13], [5, False, 5]), ('partial-repair probe', [[4], 4], [0, True, 1]), ('partial-repair probe', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1, 1, 1, 1, 1, 1], 6], [2, True, 3]), ('control layout', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4])]]
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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px % 2 == 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if trailing else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: half boundary', [[3, 3, 3, 3, 1, 1, 1, 1, 1], 15], [1, False, 1]), ('partial-repair probe', [[4, 4, 4, 4, 1, 1, 1, 1], 16], [3, True, 4]), ('partial-repair probe', [[1, 3, 3, 3, 3, 1, 3], 14], [0, False, 0]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[0, 0, 3, 1, 1, 1, 1, 3], 14], [2, True, 3]), ('control layout', [[1, 1], 2], [0, True, 1])], [('regression: half boundary', [[2, 2, 1, 1, 2, 2, 2, 2, 2, 2], 1], [4, True, 5]), ('regression: half boundary', [[3, 3, 3, 1, 1, 1], 3], [4, False, 4]), ('partial-repair probe', [[1, 1, 1, 1, 2, 2, 2], -3], [4, False, 4]), ('partial-repair probe', [[4, 4, 4, 4, 4, 4], 14], [5, True, 6]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('control layout', [[2, 0, 0, 0], 9], [3, True, 4]), ('control layout', [[2, 2], 2], [1, False, 1])], [('regression: half boundary', [[0, 0, 0, 0, 3, 3, 3, 1, 3], 13], [6, False, 6]), ('regression: half boundary', [[3, 3, 3], 1], [2, False, 2]), ('partial-repair probe', [[1, 1], -1], [1, True, 2]), ('partial-repair probe', [[4, 4, 4, 2, 2, 2], 12], [5, True, 6]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[2, 2, 2, 2, 1, 1, 1, 2, 3], 2], [8, True, 9]), ('control layout', [[2, 2, 1, 1, 1, 2], 15], [1, True, 2])], [('regression: half boundary', [[2, 2, 2, 2, 2], 3], [1, True, 2]), ('regression: half boundary', [[1, 0, 0, 0, 0], 3], [1, True, 2]), ('partial-repair probe', [[1, 1, 1], -1], [2, True, 3]), ('partial-repair probe', [[1, 1, 3, 3, 3, 3, 3, 3, 3], 18], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('control layout', [[1], 3], [0, False, 0]), ('control layout', [[2, 2, 2, 2], -2], [0, False, 0])], [('regression: half boundary', [[4, 4, 4, 1, 1, 1], 3], [4, False, 4]), ('regression: half boundary', [[0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 13], [5, False, 5]), ('partial-repair probe', [[4], 4], [0, True, 1]), ('partial-repair probe', [[0, 0, 1, 1, 1, 1, 1], -1], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('control layout', [[1, 1, 1, 1, 1, 1], 6], [2, True, 3]), ('control layout', [[3, 3, 3, 3, 3, 3, 3], 6], [3, True, 4])]]
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:
Clicks in the right half are treated as left half.

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

split: open-access


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

N = 1
observations = []
def solve(x):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i if trailing else i + 1]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[2, 2, 0, 0, 0], 13], [4, True, 5]), ('regression: caret offset from edge', [[3, 3], 5], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: caret offset from edge', [[3, 3, 3, 1, 1, 1, 1, 1, 1, 3], 6], [6, True, 7]), ('regression: caret offset from edge', [[4, 1, 1, 1], 11], [0, True, 1]), ('regression: caret offset from edge', [[3, 3], -1], [1, True, 2])], [('regression: caret offset from edge', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: caret offset from edge', [[2, 2, 2, 2], -2], [0, False, 0]), ('regression: caret offset from edge', [[1, 1, 1, 4, 4, 2, 2], 17], [0, False, 0]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 3, 3, 3, 3], -1], [8, True, 9]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[0, 1, 1, 1, 1, 0, 0, 0], 15], [7, True, 8]), ('regression: caret offset from edge', [[0, 0], 7], [1, True, 2])], [('regression: caret offset from edge', [[2, 2, 2, 2], 4], [2, False, 2]), ('regression: caret offset from edge', [[1, 1, 1, 1, 2, 2, 2, 2, 3, 2], 23], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('regression: caret offset from edge', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1], -3], [9, True, 10]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[1], -2], [0, True, 1]), ('regression: caret offset from edge', [[4, 4, 4, 4, 4, 4, 4, 2, 2, 2], 8], [4, False, 4])], [('regression: caret offset from edge', [[0, 0, 0, 1, 1, 1, 1, 3, 3], 3], [1, True, 2]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: caret offset from edge', [[1, 1, 1], 8], [0, False, 0]), ('regression: caret offset from edge', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('regression: caret offset from edge', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 3, 3, 3, 3], -1], [8, True, 9])], [('regression: caret offset from edge', [[3, 3, 3, 1, 1, 1, 1, 2], 2], [6, True, 7]), ('regression: caret offset from edge', [[2], 4], [0, True, 1]), ('regression: caret offset from edge', [[3, 3, 3, 2, 2], -2], [2, True, 3]), ('regression: caret offset from edge', [[3, 3, 3, 3, 1, 1, 1, 1], 18], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[0, 0, 0, 0, 0, 0, 1, 1, 2, 0], 13], [8, True, 9]), ('regression: caret offset from edge', [[4, 4, 3], 1], [2, False, 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):
    def reorder(lv):
        vis = list(range(len(lv)))
        odd = [l for l in lv if l % 2 == 1]
        if not odd:
            return vis
        for lev in range(max(lv), min(odd) - 1, -1):
            i = 0
            while i < len(vis):
                if lv[vis[i]] >= lev:
                    j = i
                    while j < len(vis) and lv[vis[j]] >= lev:
                        j += 1
                    vis[i:j] = vis[i:j][::-1]
                    i = j
                else:
                    i += 1
        return vis

    levels, px = x
    n = len(levels)
    if n == 0:
        return [None, False, 0]
    vis = reorder(levels)
    v = min(max(px // 2, 0), n - 1)
    i = vis[v]
    right_half = px - 2 * v >= 1
    rtl = levels[i] % 2 == 1
    trailing = right_half != rtl
    return [i, trailing, i + 1 if right_half else i]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[2, 2, 0, 0, 0], 13], [4, True, 5]), ('regression: caret offset from edge', [[3, 3], 5], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('regression: caret offset from edge', [[3, 3, 3, 1, 1, 1, 1, 1, 1, 3], 6], [6, True, 7]), ('regression: caret offset from edge', [[4, 1, 1, 1], 11], [0, True, 1]), ('regression: caret offset from edge', [[3, 3], -1], [1, True, 2])], [('regression: caret offset from edge', [[3, 3, 3, 3, 4, 4, 4, 1], 8], [3, True, 4]), ('regression: caret offset from edge', [[2, 2, 2, 2], -2], [0, False, 0]), ('regression: caret offset from edge', [[1, 1, 1, 4, 4, 2, 2], 17], [0, False, 0]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 3, 3, 3, 3], -1], [8, True, 9]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[0, 1, 1, 1, 1, 0, 0, 0], 15], [7, True, 8]), ('regression: caret offset from edge', [[0, 0], 7], [1, True, 2])], [('regression: caret offset from edge', [[2, 2, 2, 2], 4], [2, False, 2]), ('regression: caret offset from edge', [[1, 1, 1, 1, 2, 2, 2, 2, 3, 2], 23], [0, False, 0]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('regression: caret offset from edge', [[1, 1, 1, 2, 2, 2, 2, 1, 1, 1], -3], [9, True, 10]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[1], -2], [0, True, 1]), ('regression: caret offset from edge', [[4, 4, 4, 4, 4, 4, 4, 2, 2, 2], 8], [4, False, 4])], [('regression: caret offset from edge', [[0, 0, 0, 1, 1, 1, 1, 3, 3], 3], [1, True, 2]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 1, 0, 0, 3], 6], [2, True, 3]), ('regression: caret offset from edge', [[1, 1, 1], 8], [0, False, 0]), ('regression: caret offset from edge', [[3, 3, 3, 3, 1, 1, 1], -2], [6, True, 7]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click past end', [[0, 1, 1], 9], [1, False, 1]), ('regression: caret offset from edge', [[2, 2, 3, 3, 1, 1, 1], 8], [1, False, 1]), ('regression: caret offset from edge', [[1, 1, 1, 1, 1, 3, 3, 3, 3], -1], [8, True, 9])], [('regression: caret offset from edge', [[3, 3, 3, 1, 1, 1, 1, 2], 2], [6, True, 7]), ('regression: caret offset from edge', [[2], 4], [0, True, 1]), ('regression: caret offset from edge', [[3, 3, 3, 2, 2], -2], [2, True, 3]), ('regression: caret offset from edge', [[3, 3, 3, 3, 1, 1, 1, 1], 18], [0, False, 0]), ('right half of RTL char', [[1, 1], 1], [1, False, 1]), ('click left of RTL line', [[1, 1, 1], -1], [2, True, 3]), ('regression: caret offset from edge', [[0, 0, 0, 0, 0, 0, 1, 1, 2, 0], 13], [8, True, 9]), ('regression: caret offset from edge', [[4, 4, 3], 1], [2, False, 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:
The caret lands on the wrong side of the hit character.

Input [levels, x in half-character units]. Clamp to a visual slot (each character 2 units). The right half of an LTR character or the left half of an RTL character is its trailing side. Points before the line use the left half of slot 0, beyond it the right half of the last slot. Return [logical index, trailing, caret offset].

split: open-access