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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = p["h"]//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = max(1,p["h"]//4)
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at pages_y.

Square 4x4 texel pages use row-major page-directory order and Morton x/y interleaving within each page. Each page has an eight-byte header; directory entries are four bytes and directory storage precedes page bodies. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at directory_bytes.

Square 4x4 texel pages use row-major page-directory order and Morton x/y interleaving within each page. Each page has an eight-byte header; directory entries are four bytes and directory storage precedes page bodies. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]%4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = (p["x"]+3)//4
    page_y = p["y"]//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at page_x.

Square 4x4 texel pages use row-major page-directory order and Morton x/y interleaving within each page. Each page has an eight-byte header; directory entries are four bytes and directory storage precedes page bodies. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]%4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = (p["y"]+3)//4
    page_index = page_y*pages_x+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at page_y.

Square 4x4 texel pages use row-major page-directory order and Morton x/y interleaving within each page. Each page has an eight-byte header; directory entries are four bytes and directory storage precedes page bodies. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access


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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_x*pages_y+page_y
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(p):
    p = dict(p)
    pages_x = (p["w"]+3)//4
    pages_y = (p["h"]+3)//4
    directory_bytes = pages_x*pages_y*p["entry"]
    page_x = p["x"]//4
    page_y = p["y"]//4
    page_index = page_y+page_x
    morton = sum(((p["x"]>>i)&1)<<(2*i) | ((p["y"]>>i)&1)<<(2*i+1) for i in range(2))
    page_bytes = 16*p["b"]+p["header"]
    page_start = p["base"]+directory_bytes+page_index*page_bytes
    address = page_start+p["header"]+morton*p["b"]
    return {'pages_x': pages_x, 'pages_y': pages_y, 'directory_bytes': directory_bytes, 'page_x': page_x, 'page_y': page_y, 'page_index': page_index, 'morton': morton, 'page_bytes': page_bytes, 'page_start': page_start, 'address': address}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 40, 'page_start': 15, 'address': 23}), ({'w': 6, 'h': 4, 'x': 1, 'y': 2, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 1, 'directory_bytes': 8, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 40, 'page_start': 19, 'address': 45}), ({'w': 10, 'h': 8, 'x': 8, 'y': 6, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 40, 'page_start': 235, 'address': 259}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 40, 'page_start': 323, 'address': 361}), ({'w': 18, 'h': 10, 'x': 16, 'y': 8, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 40, 'page_start': 631, 'address': 639}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 2, 'base': 11, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 40, 'page_start': 283, 'address': 301})], 2: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 56, 'page_start': 26, 'address': 34}), ({'w': 7, 'h': 5, 'x': 1, 'y': 2, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 56, 'page_start': 38, 'address': 73}), ({'w': 11, 'h': 9, 'x': 8, 'y': 6, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 56, 'page_start': 338, 'address': 370}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 56, 'page_start': 446, 'address': 499}), ({'w': 19, 'h': 11, 'x': 16, 'y': 8, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 56, 'page_start': 866, 'address': 874}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 3, 'base': 22, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 56, 'page_start': 390, 'address': 413})], 3: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 72, 'page_start': 37, 'address': 45}), ({'w': 8, 'h': 6, 'x': 1, 'y': 2, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 2, 'directory_bytes': 16, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 72, 'page_start': 49, 'address': 93}), ({'w': 12, 'h': 10, 'x': 8, 'y': 6, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 3, 'directory_bytes': 36, 'page_x': 2, 'page_y': 1, 'page_index': 5, 'morton': 8, 'page_bytes': 72, 'page_start': 429, 'address': 469}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 72, 'page_start': 569, 'address': 637}), ({'w': 20, 'h': 12, 'x': 16, 'y': 8, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 5, 'pages_y': 3, 'directory_bytes': 60, 'page_x': 4, 'page_y': 2, 'page_index': 14, 'morton': 0, 'page_bytes': 72, 'page_start': 1101, 'address': 1109}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 4, 'base': 33, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 72, 'page_start': 497, 'address': 525})], 4: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 88, 'page_start': 48, 'address': 56}), ({'w': 9, 'h': 7, 'x': 1, 'y': 2, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 88, 'page_start': 68, 'address': 121}), ({'w': 13, 'h': 11, 'x': 8, 'y': 6, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 88, 'page_start': 620, 'address': 668}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 88, 'page_start': 692, 'address': 775}), ({'w': 21, 'h': 13, 'x': 16, 'y': 8, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 88, 'page_start': 1548, 'address': 1556}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 5, 'base': 44, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 88, 'page_start': 604, 'address': 637})], 5: [({'w': 1, 'h': 1, 'x': 0, 'y': 0, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 1, 'pages_y': 1, 'directory_bytes': 4, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 0, 'page_bytes': 104, 'page_start': 59, 'address': 67}), ({'w': 10, 'h': 8, 'x': 1, 'y': 2, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 3, 'pages_y': 2, 'directory_bytes': 24, 'page_x': 0, 'page_y': 0, 'page_index': 0, 'morton': 9, 'page_bytes': 104, 'page_start': 79, 'address': 141}), ({'w': 14, 'h': 12, 'x': 8, 'y': 6, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 3, 'directory_bytes': 48, 'page_x': 2, 'page_y': 1, 'page_index': 6, 'morton': 8, 'page_bytes': 104, 'page_start': 727, 'address': 783}), ({'w': 16, 'h': 8, 'x': 15, 'y': 7, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 4, 'pages_y': 2, 'directory_bytes': 32, 'page_x': 3, 'page_y': 1, 'page_index': 7, 'morton': 15, 'page_bytes': 104, 'page_start': 815, 'address': 913}), ({'w': 22, 'h': 14, 'x': 16, 'y': 8, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 6, 'pages_y': 4, 'directory_bytes': 96, 'page_x': 4, 'page_y': 2, 'page_index': 16, 'morton': 0, 'page_bytes': 104, 'page_start': 1815, 'address': 1823}), ({'w': 7, 'h': 13, 'x': 3, 'y': 12, 'b': 6, 'base': 55, 'px': 4, 'py': 4, 'header': 8, 'entry': 4}, {'pages_x': 2, 'pages_y': 4, 'directory_bytes': 32, 'page_x': 0, 'page_y': 3, 'page_index': 6, 'morton': 5, 'page_bytes': 104, 'page_start': 711, 'address': 749})]}
for i, (p, expected) in enumerate(cases[N]):
    check("layout fixture " + str(i + 1), solve(p), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at page_index.

Square 4x4 texel pages use row-major page-directory order and Morton x/y interleaving within each page. Each page has an eight-byte header; directory entries are four bytes and directory storage precedes page bodies. Return the named intermediate layout descriptor and final address fields; all quantities are integer byte offsets unless explicitly stated.

split: open-access