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

N = 1
observations = []
def solve(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if bool(maximum) and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)-(end-start)
        text = proposed
        results.append([True,start+len(replacement),delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if maximum is not None and maximum > 0 and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)-(end-start)
        text = proposed
        results.append([True,start+len(replacement),delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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:
Zero-capacity accessible editors accept inserted text.

Input [text,readonly,maximum,operations] operations [start,end,replacement]. Validate integer codepoint bounds 0<=start<=end<=len(current_text); readonly rejects each edit. Replace half-open range; reject proposed length beyond maximum (None unlimited) atomically. Return [final_text,edit_results] where successful result [True,caret,delta] caret is start+replacement length and delta replacement length minus removed length; rejected [False,None,0]. Empty replacement deletes, empty interval inserts. Subsequent offsets address current text.

split: open-access


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

N = 1
observations = []
def solve(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if maximum is not None and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)-(end-start)
        text = proposed
        results.append([True,end,delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if maximum is not None and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)-(end-start)
        text = proposed
        results.append([True,start+len(replacement)-1,delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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:
Successful replacement reports the removed range end.

Input [text,readonly,maximum,operations] operations [start,end,replacement]. Validate integer codepoint bounds 0<=start<=end<=len(current_text); readonly rejects each edit. Replace half-open range; reject proposed length beyond maximum (None unlimited) atomically. Return [final_text,edit_results] where successful result [True,caret,delta] caret is start+replacement length and delta replacement length minus removed length; rejected [False,None,0]. Empty replacement deletes, empty interval inserts. Subsequent offsets address current text.

split: open-access


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

N = 1
observations = []
def solve(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if maximum is not None and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)+(end-start)
        text = proposed
        results.append([True,start+len(replacement),delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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(data):
    text,readonly,maximum,operations = data
    results = []
    for start,end,replacement in operations:
        if readonly or not (0 <= start <= end <= len(text)):
            results.append([False,None,0]); continue
        proposed = text[:start]+replacement+text[end:]
        if maximum is not None and len(proposed) > maximum:
            results.append([False,None,0]); continue
        delta = len(replacement)-max(0,end-start-1)
        text = proposed
        results.append([True,start+len(replacement),delta])
    return [text,results]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve(['A'*N+'BC',False,None,[[N,N+1,'xy'],[N+2,N+3,'']]],), ['A'*N+'xy',[[True,N+2,1],[True,N+2,-1]]])
check('contract fixture 2', solve(['ab',False,3,[[1,1,'X'],[0,0,'Y']]],), ['aXb',[[True,2,1],[False,None,0]]])
check('contract fixture 3', solve(['ab',True,None,[[0,2,'x']]],), ['ab',[[False,None,0]]])
check('contract fixture 4', solve(['ab',False,None,[[-1,1,'x'],[2,1,'x'],[0,3,'x']]],), ['ab',[[False,None,0],[False,None,0],[False,None,0]]])
check('contract fixture 5', solve(['',False,0,[[0,0,''],[0,0,'x']]],), ['',[[True,0,0],[False,None,0]]])
check('contract fixture 6', solve(['😀x',False,None,[[0,1,'é']]],), ['éx',[[True,1,0]]])
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:
Deletion is reported as positive text growth.

Input [text,readonly,maximum,operations] operations [start,end,replacement]. Validate integer codepoint bounds 0<=start<=end<=len(current_text); readonly rejects each edit. Replace half-open range; reject proposed length beyond maximum (None unlimited) atomically. Return [final_text,edit_results] where successful result [True,caret,delta] caret is start+replacement length and delta replacement length minus removed length; rejected [False,None,0]. Empty replacement deletes, empty interval inserts. Subsequent offsets address current text.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif not readonly and kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif (not readonly or multi) and kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Read-only text incorrectly blocks selection APIs.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and -1 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Selection API accepts a negative anchor.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length+1:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Selection API accepts focus beyond text extent.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor < length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= max(0,length-1) and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
A caret at the text end is rejected.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and True: ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or len(ranges)<2): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Single-selection adapters append a second range.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append(sorted([anchor,focus])); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([min(anchor,focus),max(anchor,focus)]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Reverse text selections lose their active end.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and -len(ranges) <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and -1 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Negative range indices replace the final selection.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.clear(); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Removing one range clears every text selection.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear' and 0 <= anchor <= length and 0 <= focus <= length: ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear' and index == 0: ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Clearing selections unnecessarily validates stale endpoint arguments.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[-1][0] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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(data):
    length,multi,readonly,selections,operation = data
    ranges = [list(x) for x in selections]
    kind,index,anchor,focus = operation
    ok = False
    if kind == 'clear': ranges,ok = [],True
    elif kind in ('add','replace') and 0 <= anchor <= length and 0 <= focus <= length:
        if kind == 'add' and (multi or not ranges): ranges.append([anchor,focus]); ok = True
        elif kind == 'replace' and 0 <= index < len(ranges): ranges[index] = [anchor,focus]; ok = True
    elif kind == 'remove' and 0 <= index < len(ranges): ranges.pop(index); ok = True
    return [ranges,ok,ranges[0][1] if ranges else None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,True,False,[[0,1]],['add',0,N+3,N]],), [[[0,1],[N+3,N]],True,N])
check('contract fixture 2', solve([5,False,True,[],['add',0,5,5]],), [[[5,5]],True,5])
check('contract fixture 3', solve([5,False,False,[[0,1]],['add',0,2,3]],), [[[0,1]],False,1])
check('contract fixture 4', solve([5,True,False,[[0,1],[2,3]],['replace',0,4,2]],), [[[4,2],[2,3]],True,3])
check('contract fixture 5', solve([5,True,False,[[0,1],[2,3]],['remove',0,0,0]],), [[[2,3]],True,3])
check('contract fixture 6', solve([5,False,False,[[0,1]],['clear',99,-1,99]],), [[],True,None])
check('contract fixture 7', solve([5,True,False,[[0,1]],['replace',-1,2,3]],), [[[0,1]],False,1])
check('contract fixture 8', solve([5,True,False,[],['add',0,-1,3]],), [[],False,None])
check('contract fixture 9', solve([5,True,False,[],['add',0,1,6]],), [[],False,None])
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:
Text API reports anchor as active selection position.

Input [text_length,multi,readonly,selections,operation] selections ordered [anchor,focus]; operation [kind,index,anchor,focus]. API supports add,replace,remove,clear; readonly concerns text edits and does not prevent selecting. Validate endpoints inclusive0..length and index for replace/remove. add only when multi or no selection; remove preserves other ranges; clear ignores index. Return [ranges,success,active] where active is last range's focus or None. Preserve anchor direction and collapsed selections. Failure leaves input unchanged.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind == 'invalid' or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Unrecognized annotation kinds cross the accessibility bridge.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} : continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or not types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Annotation queries ignore the requested type mask.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved and not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Resolved comments remain in active annotation queries.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or detail is None: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Nameless annotation markers enter text attribute ranges.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),end
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length+1,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Annotation endpoints extend beyond accessible text.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start > end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start > end or start == end == 0 and False or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Zero-width annotations are exposed as text spans.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end : continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen and not detail: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Annotation ID collisions produce ambiguous descriptors.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[0],row[1],row[2]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail])
    return sorted(result,key=lambda row:(row[1],row[0],row[2]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Annotation results use identifier order instead of text order.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access


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

N = 1
observations = []
def solve(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,kind])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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(data):
    length,annotations,types = data
    seen = set()
    result = []
    for ident,start,end,kind,detail,resolved in annotations:
        if kind not in {'spelling','grammar','comment'} or kind not in types: continue
        if resolved or not detail: continue
        start,end = max(0,start),min(length,end)
        if start >= end or ident in seen: continue
        seen.add(ident)
        result.append([ident,start,end,kind,detail[:1]])
    return sorted(result,key=lambda row:(row[1],row[2],row[0]))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('contract fixture 1', solve([N+5,[['b',N,N+3,'comment','B',False],['a',N,N+2,'spelling','A',False],['c',N,N+2,'grammar','C',False]],['comment','spelling','grammar']],), [['a',N,N+2,'spelling','A'],['c',N,N+2,'grammar','C'],['b',N,N+3,'comment','B']])
check('contract fixture 2', solve([4,[['a',-2,2,'comment','A',False],['b',2,8,'comment','B',False]],['comment']],), [['a',0,2,'comment','A'],['b',2,4,'comment','B']])
check('contract fixture 3', solve([4,[['a',0,2,'comment','A',True],['b',0,2,'spelling','B',False],['c',0,2,'unknown','C',False],['d',0,2,'comment','',False]],['comment','unknown']],), [])
check('contract fixture 4', solve([4,[['a',0,0,'comment','zero',False],['b',3,1,'comment','reverse',False]],['comment']],), [])
check('contract fixture 5', solve([4,[['a',2,3,'comment','first',False],['a',0,1,'comment','later',False]],['comment']],), [['a',2,3,'comment','first']])
check('contract fixture 6', solve([4,[['a',0,2,'comment','resolved',True],['a',1,3,'comment','live',False]],['comment']],), [['a',1,3,'comment','live']])
check('contract fixture 7', solve([0,[],[]],), [])
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:
Annotation descriptors return internal kind in the explanation channel.

Input [length,annotations,types] annotations [id,start,end,kind,detail,resolved]. Admit allowed types and unresolved annotations with nonempty detail. Clamp half-open ranges, discard empty or reversed. Preserve overlapping annotations; dedupe same ID by first eligible record. Output sorted by start,end,ID. Return [id,start,end,kind,detail]. Spelling, grammar, comment are the only recognized kinds even if types requests unknown types.

split: open-access