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

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-directory-index fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('local-directory-index fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('local-directory-index fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('local-directory-index fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('local-directory-index fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('local-directory-index fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('local-directory-index fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('local-directory-index fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('local-directory-index fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('local-directory-index fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('local-directory-index fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('local-directory-index fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('local-directory-index fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',p-size,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-directory-index fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('local-directory-index fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('local-directory-index fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('local-directory-index fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('local-directory-index fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('local-directory-index fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('local-directory-index fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('local-directory-index fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('local-directory-index fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('local-directory-index fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('local-directory-index fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('local-directory-index fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('local-directory-index fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('local-directory-index fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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 remote archive reader locates the central directory from a suffix range response: local directory slices use the recorded offset rather than end-record adjacency.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


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

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('scan-first-offset fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('scan-first-offset fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('scan-first-offset fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('scan-first-offset fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('scan-first-offset fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('scan-first-offset fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('scan-first-offset fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('scan-first-offset fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('scan-first-offset fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('scan-first-offset fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('scan-first-offset fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('scan-first-offset fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('scan-first-offset fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>0 or len(data)==22:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('scan-first-offset fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('scan-first-offset fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('scan-first-offset fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('scan-first-offset fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('scan-first-offset fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('scan-first-offset fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('scan-first-offset fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('scan-first-offset fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('scan-first-offset fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('scan-first-offset fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('scan-first-offset fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('scan-first-offset fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('scan-first-offset fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('scan-first-offset fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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 remote archive reader locates the central directory from a suffix range response: an exhausted backward scan cannot fall through to an unchecked first tail byte.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if i<len(x['local']) and x['local'][i]==d and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('relocated-block-match fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('relocated-block-match fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('relocated-block-match fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('relocated-block-match fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('relocated-block-match fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('relocated-block-match fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('relocated-block-match fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('relocated-block-match fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('relocated-block-match fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('relocated-block-match fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in x['local'][:i+1] and d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('relocated-block-match fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('relocated-block-match fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('relocated-block-match fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('relocated-block-match fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('relocated-block-match fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('relocated-block-match fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('relocated-block-match fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('relocated-block-match fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('relocated-block-match fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('relocated-block-match fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('relocated-block-match fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: matching content is found at any local block position.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('short-tail-fetch fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('short-tail-fetch fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('short-tail-fetch fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('short-tail-fetch fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('short-tail-fetch fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('short-tail-fetch fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('short-tail-fetch fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('short-tail-fetch fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('short-tail-fetch fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('short-tail-fetch fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n>0:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('short-tail-fetch fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('short-tail-fetch fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('short-tail-fetch fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('short-tail-fetch fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('short-tail-fetch fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('short-tail-fetch fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('short-tail-fetch fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('short-tail-fetch fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('short-tail-fetch fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('short-tail-fetch fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('short-tail-fetch fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: a short final remote block is fetched instead of matched against a full local block.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=B
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('final-block-length fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('final-block-length fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('final-block-length fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('final-block-length fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('final-block-length fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('final-block-length fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('final-block-length fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('final-block-length fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('final-block-length fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('final-block-length fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('final-block-length fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('final-block-length fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('final-block-length fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=T%B if i==len(remote)-1 else B
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('final-block-length fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('final-block-length fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('final-block-length fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('final-block-length fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('final-block-length fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('final-block-length fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('final-block-length fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('final-block-length fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('final-block-length fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('final-block-length fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('final-block-length fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('final-block-length fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('final-block-length fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: the final remote block length is the remaining representation bytes.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d],n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('copy-source-offset fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('copy-source-offset fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('copy-source-offset fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('copy-source-offset fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('copy-source-offset fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('copy-source-offset fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('copy-source-offset fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('copy-source-offset fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('copy-source-offset fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('copy-source-offset fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,i*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('copy-source-offset fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('copy-source-offset fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('copy-source-offset fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('copy-source-offset fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('copy-source-offset fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('copy-source-offset fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('copy-source-offset fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('copy-source-offset fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('copy-source-offset fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('copy-source-offset fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('copy-source-offset fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: copy instructions address the local block by byte offset.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('run-adjacency fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('run-adjacency fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('run-adjacency fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('run-adjacency fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('run-adjacency fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('run-adjacency fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('run-adjacency fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('run-adjacency fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('run-adjacency fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('run-adjacency fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]<=i*B: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('run-adjacency fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('run-adjacency fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('run-adjacency fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('run-adjacency fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('run-adjacency fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('run-adjacency fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('run-adjacency fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('run-adjacency fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('run-adjacency fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('run-adjacency fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('run-adjacency fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: only byte-adjacent missing blocks extend the current fetch run.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('batch-slice fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('batch-slice fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('batch-slice fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('batch-slice fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-slice fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('batch-slice fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('batch-slice fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('batch-slice fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-slice fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('batch-slice fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('batch-slice fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('batch-slice fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('batch-slice fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R-1]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('batch-slice fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('batch-slice fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('batch-slice fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('batch-slice fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-slice fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('batch-slice fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('batch-slice fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('batch-slice fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-slice fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('batch-slice fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('batch-slice fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('batch-slice fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('batch-slice fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: each request batch takes the next R runs from its own start.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs)-1,R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('batch-stride fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('batch-stride fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('batch-stride fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('batch-stride fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-stride fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('batch-stride fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('batch-stride fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('batch-stride fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-stride fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('batch-stride fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('batch-stride fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('batch-stride fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('batch-stride fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs)-R+1,R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('batch-stride fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('batch-stride fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('batch-stride fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('batch-stride fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-stride fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('batch-stride fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('batch-stride fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('batch-stride fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('batch-stride fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('batch-stride fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('batch-stride fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('batch-stride fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('batch-stride fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: the final partial batch of runs is still requested.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)<T//B: return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('manifest-block-count fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('manifest-block-count fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('manifest-block-count fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('manifest-block-count fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('manifest-block-count fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('manifest-block-count fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('manifest-block-count fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('manifest-block-count fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('manifest-block-count fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('manifest-block-count fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)<-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<=x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('manifest-block-count fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('manifest-block-count fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('manifest-block-count fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('manifest-block-count fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('manifest-block-count fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('manifest-block-count fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('manifest-block-count fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('manifest-block-count fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('manifest-block-count fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('manifest-block-count fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('manifest-block-count fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: the digest manifest must describe exactly the remote block count.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access


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

N = 1
observations = []
def solve(x):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-short-block fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('local-short-block fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('local-short-block fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('local-short-block fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('local-short-block fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('local-short-block fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('local-short-block fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('local-short-block fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('local-short-block fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('local-short-block fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('local-short-block fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('local-short-block fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('local-short-block fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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):
    T=x['total']
    B=x['block']
    remote=x['remote']
    if B<=0 or T<0 or len(remote)!=-(-T//B): return None
    where={}
    for j,d in enumerate(x['local']):
        if (j+1)*B<x['local_total']: where.setdefault(d,j)
    copies=[]
    runs=[]
    for i,d in enumerate(remote):
        n=min(B,T-i*B)
        if d in where and n==B:
            copies.append([i*B,where[d]*B,n])
            continue
        if runs and runs[-1][1]==i*B-1: runs[-1][1]=i*B+n-1
        else: runs.append([i*B,i*B+n-1])
    R=x['max_ranges']
    headers=[]
    for k in range(0,len(runs),R):
        headers.append('bytes='+','.join('%d-%d'%(a,b) for a,b in runs[k:k+R]))
    return [copies,headers]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-short-block fixture 0', json.loads(json.dumps(solve({'block':4,'local':['b','x'],'local_total':8,'max_ranges':2,'remote':['a','b','c'],'total':10}))), json.loads(json.dumps([[[4,0,4]],['bytes=0-3,8-9']])))
check('local-short-block fixture 1', json.loads(json.dumps(solve({'block':4,'local':['z','z','a'],'local_total':12,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,8,4]],['bytes=4-7']])))
check('local-short-block fixture 2', json.loads(json.dumps(solve({'block':4,'local':['t','a','b'],'local_total':12,'max_ranges':2,'remote':['a','b','t'],'total':10}))), json.loads(json.dumps([[[0,4,4],[4,8,4]],['bytes=8-9']])))
check('local-short-block fixture 3', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('local-short-block fixture 4', json.loads(json.dumps(solve({'block':4,'local':['k'],'local_total':4,'max_ranges':2,'remote':['a','k','b','k','c','k'],'total':24}))), json.loads(json.dumps([[[4,0,4],[12,0,4],[20,0,4]],['bytes=0-3,8-11','bytes=16-19']])))
check('local-short-block fixture 5', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':10}))), json.loads(json.dumps(None)))
check('local-short-block fixture 6', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b','c'],'total':8}))), json.loads(json.dumps(None)))
check('local-short-block fixture 7', json.loads(json.dumps(solve({'block':4,'local':['s'],'local_total':2,'max_ranges':2,'remote':['a','s'],'total':8}))), json.loads(json.dumps([[],['bytes=0-7']])))
check('local-short-block fixture 8', json.loads(json.dumps(solve({'block':4,'local':['a'],'local_total':4,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps([[[0,0,4]],['bytes=4-7']])))
check('local-short-block fixture 9', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':2,'remote':[],'total':0}))), json.loads(json.dumps([[],[]])))
check('local-short-block fixture 10', json.loads(json.dumps(solve({'block':0,'local':[],'local_total':0,'max_ranges':2,'remote':['a','b'],'total':8}))), json.loads(json.dumps(None)))
check('local-short-block fixture 11', json.loads(json.dumps(solve({'block':4,'local':[],'local_total':0,'max_ranges':1,'remote':['a','b','c'],'total':12}))), json.loads(json.dumps([[],['bytes=0-11']])))
check('local-short-block fixture 12', json.loads(json.dumps(solve({'block':4,'local':['h'],'local_total':4,'max_ranges':2,'remote':["h"]*N,'total':4*N}))), json.loads(json.dumps([[[4*i,0,4] for i in range(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 delta downloader reuses matching local blocks and fetches the rest with batched ranges: a short local tail block is not a reusable full block.

x has remote total length, block size, one remote digest per block (the last block may be short), local digests per local block with the local file length, and a per-request range limit R>=1. Reject nonpositive block size, negative total, or a manifest whose count is not ceil(total/block). Only complete local blocks may be copied; a full remote block whose digest occurs at any local position is copied from the first such complete local block as [dest-offset,source-offset,length]. The short final remote block is always fetched. Missing bytes form maximal adjacent inclusive runs, sent in consecutive batches of at most R ranges. Return [copies,Range values].

split: open-access