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

N = 1
observations = []
def solve(x):
    offset=x['offset']
    remaining=x['remaining']
    state='running'
    opened=True
    out=[]
    for accepted,error in x['events']:
        if state in ('complete','aborted','truncated'):
            out.append([offset,remaining,state,opened])
            continue
        if accepted<0 or accepted>remaining:
            state='aborted'
            opened=False
            out.append([offset,remaining,state,opened])
            continue
        offset+=accepted
        remaining-=accepted
        if error=='fatal': state='aborted'
        elif remaining==0: state='complete'
        elif error=='again': state='blocked'
        elif error=='interrupt': state='running'
        elif accepted==0: state='truncated'
        else: state='running'
        opened=state!='complete'
        out.append([offset,remaining,state,opened])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('terminal-handle-close fixture 0', json.loads(json.dumps(solve({'offset':10,'remaining':5,'events':[[2,'interrupt'],[1,'again'],[2,'none']]}))), json.loads(json.dumps([[12,3,'running',True],[13,2,'blocked',True],[15,0,'complete',False]])))
check('terminal-handle-close fixture 1', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[0,'again'],[0,'interrupt'],[0,'none'],[1,'none']]}))), json.loads(json.dumps([[0,2,'blocked',True],[0,2,'running',True],[0,2,'truncated',False],[0,2,'truncated',False]])))
check('terminal-handle-close fixture 2', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[1,'fatal'],[1,'none']]}))), json.loads(json.dumps([[1,1,'aborted',False],[1,1,'aborted',False]])))
check('terminal-handle-close fixture 3', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[-1,'none']]}))), json.loads(json.dumps([[0,2,'aborted',False]])))
check('terminal-handle-close fixture 4', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[3,'none']]}))), json.loads(json.dumps([[0,2,'aborted',False]])))
check('terminal-handle-close fixture 5', json.loads(json.dumps(solve({'offset':N,'remaining':N,'events':[[N,'again'],[0,'fatal']]}))), json.loads(json.dumps([[2*N,0,'complete',False],[2*N,0,'complete',False]])))
check('terminal-handle-close fixture 6', json.loads(json.dumps(solve({'offset':0,'remaining':0,'events':[[0,'none']]}))), json.loads(json.dumps([[0,0,'complete',False]])))
check('terminal-handle-close fixture 7', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[2,'fatal']]}))), json.loads(json.dumps([[2,0,'aborted',False]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    offset=x['offset']
    remaining=x['remaining']
    state='running'
    opened=True
    out=[]
    for accepted,error in x['events']:
        if state in ('complete','aborted','truncated'):
            out.append([offset,remaining,state,opened])
            continue
        if accepted<0 or accepted>remaining:
            state='aborted'
            opened=False
            out.append([offset,remaining,state,opened])
            continue
        offset+=accepted
        remaining-=accepted
        if error=='fatal': state='aborted'
        elif remaining==0: state='complete'
        elif error=='again': state='blocked'
        elif error=='interrupt': state='running'
        elif accepted==0: state='truncated'
        else: state='running'
        opened=state not in ('complete','aborted')
        out.append([offset,remaining,state,opened])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('terminal-handle-close fixture 0', json.loads(json.dumps(solve({'offset':10,'remaining':5,'events':[[2,'interrupt'],[1,'again'],[2,'none']]}))), json.loads(json.dumps([[12,3,'running',True],[13,2,'blocked',True],[15,0,'complete',False]])))
check('terminal-handle-close fixture 1', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[0,'again'],[0,'interrupt'],[0,'none'],[1,'none']]}))), json.loads(json.dumps([[0,2,'blocked',True],[0,2,'running',True],[0,2,'truncated',False],[0,2,'truncated',False]])))
check('terminal-handle-close fixture 2', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[1,'fatal'],[1,'none']]}))), json.loads(json.dumps([[1,1,'aborted',False],[1,1,'aborted',False]])))
check('terminal-handle-close fixture 3', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[-1,'none']]}))), json.loads(json.dumps([[0,2,'aborted',False]])))
check('terminal-handle-close fixture 4', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[3,'none']]}))), json.loads(json.dumps([[0,2,'aborted',False]])))
check('terminal-handle-close fixture 5', json.loads(json.dumps(solve({'offset':N,'remaining':N,'events':[[N,'again'],[0,'fatal']]}))), json.loads(json.dumps([[2*N,0,'complete',False],[2*N,0,'complete',False]])))
check('terminal-handle-close fixture 6', json.loads(json.dumps(solve({'offset':0,'remaining':0,'events':[[0,'none']]}))), json.loads(json.dumps([[0,0,'complete',False]])))
check('terminal-handle-close fixture 7', json.loads(json.dumps(solve({'offset':0,'remaining':2,'events':[[2,'fatal']]}))), json.loads(json.dumps([[2,0,'aborted',False]])))
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 zero-copy range sender accounts for partial progress reported with syscall errors: aborted and truncated range streams release the source handle.

x contains absolute offset, remaining promised bytes, and syscall events [accepted,error], where error is none,again,interrupt,fatal. Counts outside0..remaining abort without advancing. Valid accepted bytes advance even when again or interrupt accompanies them. Fatal errors abort; zero remaining completes; again blocks; interrupt reschedules; zero bytes with none truncates. Terminal states ignore later events. Return state snapshots [offset,remaining,state,handle-open] after each event.

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if rs is None: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('empty-request fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('empty-request fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('empty-request fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('empty-request fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('empty-request fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('empty-request fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('empty-request fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('empty-request fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('empty-request fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('empty-request fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('empty-request fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs and x['length']: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('empty-request fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('empty-request fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('empty-request fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('empty-request fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('empty-request fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('empty-request fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('empty-request fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('empty-request fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('empty-request fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('empty-request fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('empty-request fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('empty-request fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: an empty resolved range list never becomes an empty partial response.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in {tuple(r) for r in rs}:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('amplification-duplicates fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('amplification-duplicates fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('amplification-duplicates fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('amplification-duplicates fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('amplification-duplicates fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('amplification-duplicates fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('amplification-duplicates fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('amplification-duplicates fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('amplification-duplicates fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('amplification-duplicates fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('amplification-duplicates fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in {r[0]:r for r in rs}.values():
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('amplification-duplicates fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('amplification-duplicates fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('amplification-duplicates fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('amplification-duplicates fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('amplification-duplicates fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('amplification-duplicates fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('amplification-duplicates fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('amplification-duplicates fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('amplification-duplicates fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('amplification-duplicates fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('amplification-duplicates fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('amplification-duplicates fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: repeated identical ranges each count toward the amplification budget.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=rs
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('overlap-sorted-sweep fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('overlap-sorted-sweep fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('overlap-sorted-sweep fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('overlap-sorted-sweep fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('overlap-sorted-sweep fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('overlap-sorted-sweep fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('overlap-sorted-sweep fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('overlap-sorted-sweep fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('overlap-sorted-sweep fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('overlap-sorted-sweep fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('overlap-sorted-sweep fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs,key=lambda r:r[1])
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('overlap-sorted-sweep fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('overlap-sorted-sweep fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('overlap-sorted-sweep fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('overlap-sorted-sweep fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('overlap-sorted-sweep fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('overlap-sorted-sweep fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('overlap-sorted-sweep fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('overlap-sorted-sweep fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('overlap-sorted-sweep fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('overlap-sorted-sweep fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('overlap-sorted-sweep fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('overlap-sorted-sweep fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: overlap detection sweeps ranges in start order rather than request order.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end+1: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('adjacency-not-overlap fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('adjacency-not-overlap fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('adjacency-not-overlap fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('adjacency-not-overlap fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('adjacency-not-overlap fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('adjacency-not-overlap fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('adjacency-not-overlap fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('adjacency-not-overlap fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('adjacency-not-overlap fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('adjacency-not-overlap fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('adjacency-not-overlap fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('adjacency-not-overlap fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('adjacency-not-overlap fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('adjacency-not-overlap fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('adjacency-not-overlap fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('adjacency-not-overlap fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('adjacency-not-overlap fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('adjacency-not-overlap fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('adjacency-not-overlap fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('adjacency-not-overlap fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('adjacency-not-overlap fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('adjacency-not-overlap fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('adjacency-not-overlap fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: touching ranges are not counted as overlapping while a shared byte is.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('merge-adjacent fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('merge-adjacent fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('merge-adjacent fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('merge-adjacent fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('merge-adjacent fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('merge-adjacent fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('merge-adjacent fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('merge-adjacent fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('merge-adjacent fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('merge-adjacent fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('merge-adjacent fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1 and hi>merged[-1][1]:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('merge-adjacent fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('merge-adjacent fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('merge-adjacent fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('merge-adjacent fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('merge-adjacent fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('merge-adjacent fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('merge-adjacent fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('merge-adjacent fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('merge-adjacent fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('merge-adjacent fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('merge-adjacent fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('merge-adjacent fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: coalescing joins ranges that touch without a byte gap.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=hi
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('merge-contained-end fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('merge-contained-end fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('merge-contained-end fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('merge-contained-end fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('merge-contained-end fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('merge-contained-end fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('merge-contained-end fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('merge-contained-end fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('merge-contained-end fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('merge-contained-end fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('merge-contained-end fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[i-1][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][0],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('merge-contained-end fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('merge-contained-end fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('merge-contained-end fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('merge-contained-end fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('merge-contained-end fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('merge-contained-end fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('merge-contained-end fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('merge-contained-end fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('merge-contained-end fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('merge-contained-end fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('merge-contained-end fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('merge-contained-end fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: a contained range cannot shrink the coalesced end.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access


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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<rs[0][0]: disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('disorder-neighbor fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('disorder-neighbor fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('disorder-neighbor fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('disorder-neighbor fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('disorder-neighbor fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('disorder-neighbor fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('disorder-neighbor fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('disorder-neighbor fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('disorder-neighbor fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('disorder-neighbor fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('disorder-neighbor fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    L=x['length']
    rs=x['ranges']
    if not rs: return ['full',None]
    if len(rs)>x['max_ranges']: return ['full',None]
    total=0
    for a,b in rs:
        total+=b-a+1
    if total>2*L: return ['full',None]
    if sum(1 for a,b in rs if b-a+1<x['min_span'])>x['max_tiny']: return ['full',None]
    order=sorted(rs)
    overlaps=0
    end=-1
    for a,b in order:
        if a<=end: overlaps+=1
        end=max(end,b)
    if overlaps>x['max_overlaps']: return ['full',None]
    disorder=0
    for i in range(1,len(rs)):
        if rs[i][0]<max(r[0] for r in rs[:i]): disorder+=1
    if overlaps==0 and disorder<=x['max_disorder']: return ['ranges',[list(r) for r in rs]]
    merged=[]
    for lo,hi in order:
        if merged and lo<=merged[-1][1]+1:
            merged[-1][1]=max(merged[-1][1],hi)
        else:
            merged.append([lo,hi])
    return ['ranges',merged]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('disorder-neighbor fixture 0', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 1', json.loads(json.dumps(solve({'length':0,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 2', json.loads(json.dumps(solve({'length':10,'max_disorder':1,'max_overlaps':5,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[0,9],[0,9]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 3', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29]]])))
check('disorder-neighbor fixture 4', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[0,9]]}))), json.loads(json.dumps(['ranges',[[50,59],[0,9]]])))
check('disorder-neighbor fixture 5', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[0,9]]}))), json.loads(json.dumps(['ranges',[[0,9],[20,29],[50,59]]])))
check('disorder-neighbor fixture 6', json.loads(json.dumps(solve({'length':100,'max_disorder':0,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[10,19],[30,39],[20,29]]}))), json.loads(json.dumps(['ranges',[[10,39]]])))
check('disorder-neighbor fixture 7', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[50,59],[20,29],[30,39]]}))), json.loads(json.dumps(['ranges',[[50,59],[20,29],[30,39]]])))
check('disorder-neighbor fixture 8', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[5,14]]}))), json.loads(json.dumps(['ranges',[[0,14]]])))
check('disorder-neighbor fixture 9', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,20],[5,9]]}))), json.loads(json.dumps(['ranges',[[0,20]]])))
check('disorder-neighbor fixture 10', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[1,9],[2,9],[3,9]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 11', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[20,29],[0,5],[40,49],[30,35]]}))), json.loads(json.dumps(['ranges',[[0,5],[20,35],[40,49]]])))
check('disorder-neighbor fixture 12', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,50],[10,20],[30,40]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 13', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':1,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[10,19],[20,29]]}))), json.loads(json.dumps(['ranges',[[0,9],[10,19],[20,29]]])))
check('disorder-neighbor fixture 14', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':0,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,9],[9,19]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 15', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':1,'min_span':4,'ranges':[[0,0],[10,10],[20,29]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 16', json.loads(json.dumps(solve({'length':100,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,1],[10,11],[20,21],[30,31],[40,41],[50,51],[60,61],[70,71],[80,81]]}))), json.loads(json.dumps(['full',None])))
check('disorder-neighbor fixture 17', json.loads(json.dumps(solve({'length':10*N,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,N-1],[N,2*N-1]]}))), json.loads(json.dumps(['ranges',[[0,N-1],[N,2*N-1]]])))
check('disorder-neighbor fixture 18', json.loads(json.dumps(solve({'length':5*N+1,'max_disorder':1,'max_overlaps':2,'max_ranges':8,'max_tiny':8,'min_span':1,'ranges':[[0,5*N],[0,5*N]]}))), json.loads(json.dumps(['ranges',[[0,5*N]]])))
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 range-set guard limits amplification before serving resolved byte ranges: inversions compare each member with its immediate request predecessor.

x holds a representation length, already resolved satisfiable inclusive ranges in request order, and local policy limits. Serve ["full",null] for an empty list, more than max_ranges members, requested byte sum above twice the length (duplicates count every time), more than max_tiny members shorter than min_span, or more than max_overlaps overlaps. Overlaps are counted by a sweep over start-sorted ranges against the running maximum end; adjacent ranges do not overlap. Inversions count request neighbors whose start decreases. Without overlaps and with inversions within max_disorder, return ["ranges",request-order ranges]; otherwise return ["ranges",start-sorted ranges with overlapping or adjacent members coalesced].

split: open-access