broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None if current and len(current)>2 else current
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A fully outside edge does not end the current piece, so a later part starting at the same boundary point joins it.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=list(pieces)
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if pc]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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:
Edges touching the window at a single point produce one-vertex pieces.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>3: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>=2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()[:-1]
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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:
Closed triangles never receive their closing edge.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0][:0]=pieces.pop()
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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
from fractions import Fraction
N = 1
observations = []
def solve(commands, size):
    def seg(p,q):
        t0,t1=Fraction(0),Fraction(1)
        for d,e in ((q[0]-p[0],p[0]),(q[1]-p[1],p[1])):
            for pp,qq in ((-d,e),(d,size-1-e)):
                if pp==0:
                    if qq<0: return None
                else:
                    u=qq/pp
                    if pp<0: t0=max(t0,u)
                    else: t1=min(t1,u)
        if t0>t1: return None
        a=(p[0]+t0*(q[0]-p[0]),p[1]+t0*(q[1]-p[1]))
        b=(p[0]+t1*(q[0]-p[0]),p[1]+t1*(q[1]-p[1]))
        return a,b
    out=[]
    for points,closed in commands:
        pts=[(Fraction(x),Fraction(y)) for x,y in points]
        edges=list(zip(pts,pts[1:]))
        if closed and len(pts)>2: edges.append((pts[-1],pts[0]))
        pieces=[]
        current=None
        for p,q in edges:
            part=seg(p,q)
            if part is None:
                current=None
                continue
            a,b=part
            if current is not None and current[-1]==a:
                if b!=a: current.append(b)
            else:
                current=[a] if a==b else [a,b]
                pieces.append(current)
        if closed and len(pieces)>1 and pieces[0][0]==pieces[-1][-1]:
            pieces[0].extend(pieces.pop()[:-1])
        pieces=[pc for pc in pieces if len(pc)>=2]
        out.append([[[str(x),str(y)] for x,y in pc] for pc in pieces])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit case 0', solve([[[[1, 1], [4, 1], [4, 4]], False]], 6), [[[['1', '1'], ['4', '1'], ['4', '4']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 6), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 6), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 6), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 6), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 6), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 6), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 6), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 6), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 2:
    check('explicit case 0', solve([[[[1, 1], [5, 1], [5, 5]], False]], 7), [[[['1', '1'], ['5', '1'], ['5', '5']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 7), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 7), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 7), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 7), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 7), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 7), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 7), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 7), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 3:
    check('explicit case 0', solve([[[[1, 1], [6, 1], [6, 6]], False]], 8), [[[['1', '1'], ['6', '1'], ['6', '6']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 8), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 8), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 8), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 8), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 8), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 8), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 8), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 8), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 4:
    check('explicit case 0', solve([[[[1, 1], [7, 1], [7, 7]], False]], 9), [[[['1', '1'], ['7', '1'], ['7', '7']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 9), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 9), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 9), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 9), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 9), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 9), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 9), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 9), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
if N == 5:
    check('explicit case 0', solve([[[[1, 1], [8, 1], [8, 8]], False]], 10), [[[['1', '1'], ['8', '1'], ['8', '8']]]])
    check('explicit case 1', solve([[[[1, 1], [1, -3], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['5/2', '0'], ['3', '1']]]])
    check('explicit case 2', solve([[[[1, 1], [2, 1], [2, 1], [3, 2]], False]], 10), [[[['1', '1'], ['2', '1'], ['3', '2']]]])
    check('explicit case 3', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], False]], 10), [[[['1', '1'], ['1', '0']], [['3', '0'], ['3', '1']]]])
    check('explicit case 4', solve([[[[1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['1', '0'], ['2', '2']]]])
    check('explicit case 5', solve([[[[-1, 1], [1, -1]], False]], 10), [[]])
    check('explicit case 6', solve([[[[1, 1], [3, 1], [2, 3]], True]], 10), [[[['1', '1'], ['3', '1'], ['2', '3'], ['1', '1']]]])
    check('explicit case 7', solve([[[[1, 1], [3, 1]], True]], 10), [[[['1', '1'], ['3', '1']]]])
    check('explicit case 8', solve([[[[1, 1], [1, -2], [3, -2], [3, 1]], True]], 10), [[[['3', '0'], ['3', '1'], ['1', '1'], ['1', '0']]]])
    check('explicit case 9', solve([[[[-2, 2], [2, 2], [2, -2], [-2, 2]], False]], 10), [[[['0', '2'], ['2', '2'], ['2', '0']]]])
    check('explicit case 10', solve([[[[2, 1], [1, 0], [1, -2], [3, -2], [1, 0], [2, 2]], False]], 10), [[[['2', '1'], ['1', '0']], [['1', '0'], ['2', '2']]]])
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:
Merging the wrap-around piece repeats the shared start vertex.

Each command is [points,closed]. Consecutive vertices (plus the closing edge when closed and at least three points) are clipped against the closed pixel-center window [0,size-1]x[0,size-1] with exact parametric clipping. Visible parts that start where the current piece ends extend it (skipping zero-length repeats); any other visible part starts a new piece; a fully rejected edge ends the current piece. For closed paths, a last piece ending where the first piece begins is merged in front of it without repeating the joint. Pieces with fewer than two vertices are dropped. Vertices are exact rational strings.

split: open-access


prompt:
Row distance is measured from the row top rather than the pixel center, skewing the disc vertically.

Each command is [cx,cy,r,scissor] for a filled disc centred on the integer pixel-corner point (cx,cy). Pixel (x,y) is covered when its center (x+1/2,y+1/2) lies within the closed disc. Rows of the half-open scissor [left,top,right,bottom) intersected with [0,size) are scanned in order, computing exact integer span bounds with half-pixel doubled coordinates and an integer square root, then clipping to scissor columns. Non-empty spans are [row,start,end).

split: open-access


prompt:
The left span bound floors the half-pixel coordinate, covering a pixel whose center lies outside the disc.

Each command is [cx,cy,r,scissor] for a filled disc centred on the integer pixel-corner point (cx,cy). Pixel (x,y) is covered when its center (x+1/2,y+1/2) lies within the closed disc. Rows of the half-open scissor [left,top,right,bottom) intersected with [0,size) are scanned in order, computing exact integer span bounds with half-pixel doubled coordinates and an integer square root, then clipping to scissor columns. Non-empty spans are [row,start,end).

split: open-access


prompt:
The doubled half-width is rounded instead of floored, admitting pixel centers just outside the disc.

Each command is [cx,cy,r,scissor] for a filled disc centred on the integer pixel-corner point (cx,cy). Pixel (x,y) is covered when its center (x+1/2,y+1/2) lies within the closed disc. Rows of the half-open scissor [left,top,right,bottom) intersected with [0,size) are scanned in order, computing exact integer span bounds with half-pixel doubled coordinates and an integer square root, then clipping to scissor columns. Non-empty spans are [row,start,end).

split: open-access


prompt:
The inclusive right pixel index is used as the exclusive end, dropping the last covered pixel.

Each command is [cx,cy,r,scissor] for a filled disc centred on the integer pixel-corner point (cx,cy). Pixel (x,y) is covered when its center (x+1/2,y+1/2) lies within the closed disc. Rows of the half-open scissor [left,top,right,bottom) intersected with [0,size) are scanned in order, computing exact integer span bounds with half-pixel doubled coordinates and an integer square root, then clipping to scissor columns. Non-empty spans are [row,start,end).

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"]//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 = max(1,p["w"]//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)

prompt:
The returned physical layout descriptor disagrees with the declared buffer mapping at pages_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