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=sum(delta for x,delta in deltas.items() if x<0)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x-1,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<0)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0) if x>0 else 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:
Crossings are applied after their owning sample, shifting the filled span right.

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=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)

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):
    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<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:
Nonzero filling drops clockwise contours with negative winding.

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=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=winding==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<0)
        covered=[]
        for x in range(size):
            winding+=deltas.get(x,0)
            if rule=='nonzero': inside=winding!=0
            elif rule=='odd': inside=abs(winding)==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:
Even-odd fill recognizes only positive unit winding.

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=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
        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==1
            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:
Positive fill includes zero-winding gaps.

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=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
        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==-1
            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:
Negative fill includes zero-winding gaps.

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=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=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<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:
The overlap clip test rejects negatively oriented double coverage.

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=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 or 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<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 not inside if inverse else True: 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:
Inverse fill adds the exterior without removing the original interior.

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