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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)|erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-prior
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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:
Morphological clip gradient retains the eroded interior.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=erode(prior)-prior
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=dilate(prior)-prior
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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:
Inner clip boundary subtraction reverses operands and yields empty coverage.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-erode(prior)
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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:
Exterior clip boundary incorrectly retains original covered samples.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(source)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(0,iterations)):
            prior=set(result) if _==0 else set(source)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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:
Repeated morphology restarts from the original clip each iteration.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(1,iterations)):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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

N = 1
observations = []
def solve(commands, size):
    full=set(range(size))
    out=[]
    for cmd in commands:
        source,kernel,mode,iterations=cmd
        source=set(source)&full
        kernel=set(kernel)
        def dilate(s): return {x for x in full if any(x-k in s for k in kernel)}
        def erode(s): return {x for x in full if kernel and all(x+k in s for k in kernel)}
        result=set(source)
        for _ in range(max(1,iterations)) if source else range(0):
            prior=set(result)
            if mode=='dilate': result=dilate(prior)
            elif mode=='erode': result=erode(prior)
            elif mode=='open': result=dilate(erode(prior))
            elif mode=='close': result=erode(dilate(prior))
            elif mode=='gradient': result=dilate(prior)-erode(prior)
            elif mode=='inner': result=prior-erode(prior)
            else: result=dilate(prior)-prior
        out.append(sorted(result))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 4), [[1, 2]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 4), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 4), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 4), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 4), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 4), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 4), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 4), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 4), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 4), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 4), [[0, 1, 2]])
if N == 2:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 5), [[1, 2, 3]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 5), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 5), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 5), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 5), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 5), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 5), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 5), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 5), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 5), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 5), [[0, 1, 2]])
if N == 3:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 6), [[1, 2, 3, 4]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 6), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 6), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 6), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 6), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 6), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 6), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 6), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 6), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 6), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 6), [[0, 1, 2]])
if N == 4:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 7), [[1, 2, 3, 4, 5]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 7), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 7), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 7), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 7), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 7), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 7), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 7), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 7), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 7), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 7), [[0, 1, 2]])
if N == 5:
    check('explicit sequence 0', solve([[[1], [0, 1], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 1', solve([[[0, 1, 2, 3, 4, 5, 6, 7], [-1, 0, 1], 'erode', 1]], 8), [[1, 2, 3, 4, 5, 6]])
    check('explicit sequence 2', solve([[[1], [], 'erode', 1]], 8), [[]])
    check('explicit sequence 3', solve([[[1], [0, 1], 'open', 1]], 8), [[]])
    check('explicit sequence 4', solve([[[0, 2], [0, 1], 'close', 1]], 8), [[0, 1, 2]])
    check('explicit sequence 5', solve([[[0, 1, 2], [0, 1], 'gradient', 1]], 8), [[2, 3]])
    check('explicit sequence 6', solve([[[0, 1, 2], [0, 1], 'inner', 1]], 8), [[2]])
    check('explicit sequence 7', solve([[[1], [0, 1], 'outer', 1]], 8), [[2]])
    check('explicit sequence 8', solve([[[0], [0, 1], 'dilate', 2]], 8), [[0, 1, 2]])
    check('explicit sequence 9', solve([[[1], [0, 1], 'dilate', 0]], 8), [[1]])
    check('explicit sequence 10', solve([[[2], [-1, 0], 'dilate', 1]], 8), [[1, 2]])
    check('explicit sequence 11', solve([[[0, 1, 2], [0, 1], 'open', 1]], 8), [[0, 1, 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:
Zero iterations still applies the morphology operator once.

A binary sample mask supports dilation/erosion by an explicit signed structuring element. Out-of-target samples are uncovered; empty structuring elements yield empty output. Open erodes then dilates; close dilates then erodes. Gradient is dilated minus eroded; boundary is original minus eroded; exterior boundary is dilated minus original. Iterations use complete prior masks.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    out=[]
    for events,rule,inverse in commands:
        deltas={}
        for x,delta in events: deltas[x]=delta
        winding=sum(delta for x,delta in deltas.items() if x<0)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0)
            if rule=='nonzero': inside=winding!=0
            elif rule=='odd': inside=abs(winding)%2==1
            elif rule=='positive': inside=winding>0
            elif rule=='negative': inside=winding<0
            else: inside=abs(winding)>=2
            if inside ^ inverse: covered.append(x)
        out.append(covered)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 4), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 4), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 4), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 4), [[2, 3]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 4), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 4), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 5), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 5), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 5), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 5), [[2, 3, 4]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 5), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 5), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 6), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 6), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 6), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 6), [[2, 3, 4, 5]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 6), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 6), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 7), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 7), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 7), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 7), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 7), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 8), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 8), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 8), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 8), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 8), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 8), [[]])
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(commands, size):
    out=[]
    for events,rule,inverse in commands:
        deltas={}
        for x,delta in events: deltas[x]=deltas.get(x,0)+delta if delta>0 else delta
        winding=sum(delta for x,delta in deltas.items() if x<0)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0)
            if rule=='nonzero': inside=winding!=0
            elif rule=='odd': inside=abs(winding)%2==1
            elif rule=='positive': inside=winding>0
            elif rule=='negative': inside=winding<0
            else: inside=abs(winding)>=2
            if inside ^ inverse: covered.append(x)
        out.append(covered)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 4), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 4), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 4), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 4), [[2, 3]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 4), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 4), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 5), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 5), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 5), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 5), [[2, 3, 4]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 5), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 5), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 6), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 6), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 6), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 6), [[2, 3, 4, 5]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 6), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 6), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 7), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 7), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 7), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 7), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 7), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 8), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 8), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 8), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 8), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 8), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 8), [[]])
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:
Coincident crossings overwrite each other and lose multiplicity.

Signed crossing events occur before their integer sample coordinate. For each finite target sample, sum all event deltas at or to its left, including events outside the left target edge. Fill rules are nonzero, odd, positive, negative, or magnitude-at-least-two. Inverse filling complements the result inside the target. Zero deltas are inert and coincident events add.

split: open-access


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

N = 1
observations = []
def solve(commands, size):
    out=[]
    for events,rule,inverse in commands:
        deltas={}
        for x,delta in events: deltas[x]=deltas.get(x,0)+delta
        winding=0
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0)
            if rule=='nonzero': inside=winding!=0
            elif rule=='odd': inside=abs(winding)%2==1
            elif rule=='positive': inside=winding>0
            elif rule=='negative': inside=winding<0
            else: inside=abs(winding)>=2
            if inside ^ inverse: covered.append(x)
        out.append(covered)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 4), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 4), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 4), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 4), [[2, 3]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 4), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 4), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 5), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 5), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 5), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 5), [[2, 3, 4]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 5), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 5), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 6), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 6), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 6), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 6), [[2, 3, 4, 5]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 6), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 6), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 7), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 7), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 7), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 7), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 7), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 8), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 8), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 8), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 8), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 8), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 8), [[]])
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(commands, size):
    out=[]
    for events,rule,inverse in commands:
        deltas={}
        for x,delta in events: deltas[x]=deltas.get(x,0)+delta
        winding=sum(delta for x,delta in deltas.items() if x==-1)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0)
            if rule=='nonzero': inside=winding!=0
            elif rule=='odd': inside=abs(winding)%2==1
            elif rule=='positive': inside=winding>0
            elif rule=='negative': inside=winding<0
            else: inside=abs(winding)>=2
            if inside ^ inverse: covered.append(x)
        out.append(covered)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 4), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 4), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 4), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 4), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 4), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 4), [[2, 3]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 4), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 4), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 4), [[]])
if N == 2:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 5), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 5), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 5), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 5), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 5), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 5), [[2, 3, 4]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 5), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 5), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 5), [[]])
if N == 3:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 6), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 6), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 6), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 6), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 6), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 6), [[2, 3, 4, 5]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 6), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 6), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 6), [[]])
if N == 4:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 7), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 7), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 7), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 7), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 7), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 7), [[2, 3, 4, 5, 6]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 7), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 7), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 7), [[]])
if N == 5:
    check('explicit sequence 0', solve([[[[0, 1], [0, 1], [2, -2]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 1', solve([[[[-3, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 2', solve([[[[0, 1], [2, -1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 3', solve([[[[0, -1], [2, 1]], 'nonzero', False]], 8), [[0, 1]])
    check('explicit sequence 4', solve([[[[0, 3], [2, -3]], 'odd', False]], 8), [[0, 1]])
    check('explicit sequence 5', solve([[[[0, 2], [2, -2]], 'positive', False]], 8), [[0, 1]])
    check('explicit sequence 6', solve([[[[0, -2], [2, 2]], 'negative', False]], 8), [[0, 1]])
    check('explicit sequence 7', solve([[[[0, -3], [2, 3]], 'double', False]], 8), [[0, 1]])
    check('explicit sequence 8', solve([[[[0, 1], [2, -1]], 'nonzero', True]], 8), [[2, 3, 4, 5, 6, 7]])
    check('explicit sequence 9', solve([[[[0, 1], [1, 1], [3, -2]], 'nonzero', False]], 8), [[0, 1, 2]])
    check('explicit sequence 10', solve([[[[0, 1], [0, -1]], 'nonzero', False]], 8), [[]])
    check('explicit sequence 11', solve([[[], 'odd', False]], 8), [[]])
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:
Discarding crossings left of the target loses the winding state entering the raster.

Signed crossing events occur before their integer sample coordinate. For each finite target sample, sum all event deltas at or to its left, including events outside the left target edge. Fill rules are nonzero, odd, positive, negative, or magnitude-at-least-two. Inverse filling complements the result inside the target. Zero deltas are inert and coincident events add.

split: open-access