broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=max(verts)+1
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c==1:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2*comps-chi-loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]]], [['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=sum(len(f) for f in faces)
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c==1:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2*comps-chi-loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]]], [['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Meshes with unused index gaps report extra vertices and a wrong genus.

Input: list of polygon faces (vertex index lists). V counts referenced vertices, E distinct undirected edges (closing edge included), F faces, chi=V-E+F, C connected components (via edges), B boundary loops = components of the graph of edges used by exactly one face. Return [V,E,F,chi,C,B,genus] with genus=(2C-chi-B)/2 or null when that numerator is odd (non-orientable signal).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=len(verts)
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c!=2:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2*comps-chi-loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=len(verts)
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c%2==1:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2*comps-chi-loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Non-manifold fins are counted as boundary loops.

Input: list of polygon faces (vertex index lists). V counts referenced vertices, E distinct undirected edges (closing edge included), F faces, chi=V-E+F, C connected components (via edges), B boundary loops = components of the graph of edges used by exactly one face. Return [V,E,F,chi,C,B,genus] with genus=(2C-chi-B)/2 or null when that numerator is odd (non-orientable signal).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=len(verts)
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c==1:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2-chi-loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]]], [['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    edges={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            k=(min(a,b),max(a,b))
            edges[k]=edges.get(k,0)+1
    verts=sorted({v for f in faces for v in f})
    V=len(verts)
    E=len(edges)
    Fc=len(faces)
    chi=V-E+Fc
    parent={v:v for v in verts}
    def find(v):
        while parent[v]!=v:
            v=parent[v]
        return v
    for a,b in edges:
        ra,rb=find(a),find(b)
        if ra!=rb: parent[ra]=rb
    comps=len({find(v) for v in verts})
    bpar={}
    def bfind(v):
        while bpar[v]!=v:
            v=bpar[v]
        return v
    for (a,b),c in edges.items():
        if c==1:
            bpar.setdefault(a,a)
            bpar.setdefault(b,b)
            ra,rb=bfind(a),bfind(b)
            if ra!=rb: bpar[ra]=rb
    loops=len({bfind(v) for v in bpar})
    g=2*comps-chi+loops
    genus=None if g%2 else g//2
    return [V,E,Fc,chi,comps,loops,genus]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], [6, 12, 8, 2, 1, 0, 0]], ['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]]], [['quad torus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0], [3, 6, 7, 4], [4, 7, 8, 5], [5, 8, 6, 3], [6, 0, 1, 7], [7, 1, 2, 8], [8, 2, 0, 6]]], [9, 18, 9, 0, 1, 0, 1]], ['triangle torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [9, 27, 18, 0, 1, 0, 1]], ['disk fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [6, 10, 5, 1, 1, 1, 0]], ['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['quad annulus', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 3, 0]]], [6, 9, 3, 0, 1, 2, 0]], ['mobius strip', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 9, 3, 0, 1, 1, None]], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [6, 15, 10, 1, 1, 0, None]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]]], [['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['gapped indices', [[[0, 1, 5], [1, 7, 5]]], [4, 5, 2, 1, 1, 1, 0]], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], [8, 16, 8, 0, 1, 2, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['quad grid', [[[0, 1, 4, 3], [1, 2, 5, 4], [3, 4, 7, 6], [4, 5, 8, 7]]], [9, 12, 4, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [4, 6, 4, 2, 1, 0, 0]], ['cube quads', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [8, 12, 6, 2, 1, 0, 0]], ['two tetrahedra', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [4, 6, 5], [4, 5, 7], [5, 6, 7], [4, 7, 6]]], [8, 12, 8, 4, 2, 0, 0]], ['book of three pages', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [5, 7, 3, 1, 1, 1, 0]], ['mixed quad and triangle', [[[0, 1, 2, 3], [3, 2, 4]]], [5, 6, 2, 1, 1, 1, 0]], ['tetra plus disk', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [10, 11, 12], [10, 12, 13], [10, 13, 14], [10, 14, 15], [10, 15, 11]]], [10, 16, 9, 3, 2, 1, 0]], ['tetrahedra sharing a face', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2], [0, 1, 4], [1, 2, 4], [0, 4, 2]]], [5, 9, 7, 3, 1, 0, None]]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Two disjoint spheres are reported with genus -1.

Input: list of polygon faces (vertex index lists). V counts referenced vertices, E distinct undirected edges (closing edge included), F faces, chi=V-E+F, C connected components (via edges), B boundary loops = components of the graph of edges used by exactly one face. Return [V,E,F,chi,C,B,genus] with genus=(2C-chi-B)/2 or null when that numerator is odd (non-orientable signal).

split: open-access


prompt:
Moebius strips and projective planes report genus 0 instead of the null signal.

Input: list of polygon faces (vertex index lists). V counts referenced vertices, E distinct undirected edges (closing edge included), F faces, chi=V-E+F, C connected components (via edges), B boundary loops = components of the graph of edges used by exactly one face. Return [V,E,F,chi,C,B,genus] with genus=(2C-chi-B)/2 or null when that numerator is odd (non-orientable signal).

split: open-access


prompt:
Every properly oriented closed mesh is reported non-orientable.

Input: polygon faces. Empty input returns "empty". Consecutive repeated indices form no edge (skip that pair only). Undirected edges used once are boundary, twice interior, more non-manifold; an interior edge whose two uses have the same direction is inconsistent. Verdict precedence: non-manifold, then "non-orientable-or-inconsistent", then "open-oriented" (boundary present), else "closed-oriented". Return [boundary, interior, nonmanifold, inconsistent, verdict].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if not faces: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            if a==b: continue
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)==2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=1
    if inc: v='non-orientable-or-inconsistent'
    elif nm: v='non-manifold'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']]], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if not faces: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            if a==b: continue
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)==2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=1
    if nm>inc: v='non-manifold'
    elif inc: v='non-orientable-or-inconsistent'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']]], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A mesh with both fins and flipped faces is reported as merely inconsistent.

Input: polygon faces. Empty input returns "empty". Consecutive repeated indices form no edge (skip that pair only). Undirected edges used once are boundary, twice interior, more non-manifold; an interior edge whose two uses have the same direction is inconsistent. Verdict precedence: non-manifold, then "non-orientable-or-inconsistent", then "open-oriented" (boundary present), else "closed-oriented". Return [boundary, interior, nonmanifold, inconsistent, verdict].

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if not faces: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        if len(set(f))<n: continue
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)==2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=1
    if nm: v='non-manifold'
    elif inc: v='non-orientable-or-inconsistent'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']]], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Faces with a duplicated corner add a phantom boundary edge.

Input: polygon faces. Empty input returns "empty". Consecutive repeated indices form no edge (skip that pair only). Undirected edges used once are boundary, twice interior, more non-manifold; an interior edge whose two uses have the same direction is inconsistent. Verdict precedence: non-manifold, then "non-orientable-or-inconsistent", then "open-oriented" (boundary present), else "closed-oriented". Return [boundary, interior, nonmanifold, inconsistent, verdict].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if not faces: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            if a==b: continue
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)>=2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=1
    if nm: v='non-manifold'
    elif inc: v='non-orientable-or-inconsistent'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if not faces: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            if a==b: continue
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)==2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=len(u)-2
    if nm: v='non-manifold'
    elif inc: v='non-orientable-or-inconsistent'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Non-manifold fins disappear from the report.

Input: polygon faces. Empty input returns "empty". Consecutive repeated indices form no edge (skip that pair only). Undirected edges used once are boundary, twice interior, more non-manifold; an interior edge whose two uses have the same direction is inconsistent. Verdict precedence: non-manifold, then "non-orientable-or-inconsistent", then "open-oriented" (boundary present), else "closed-oriented". Return [boundary, interior, nonmanifold, inconsistent, verdict].

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    if faces is None: return 'empty'
    uses={}
    for f in faces:
        n=len(f)
        for i in range(n):
            a,b=f[i],f[(i+1)%n]
            if a==b: continue
            uses.setdefault((min(a,b),max(a,b)),[]).append((a,b))
    bd=it=nm=inc=0
    for k in sorted(uses):
        u=uses[k]
        if len(u)==1: bd+=1
        elif len(u)==2:
            it+=1
            if u[0]==u[1]: inc+=1
        else: nm+=1
    if nm: v='non-manifold'
    elif inc: v='non-orientable-or-inconsistent'
    elif bd: v='open-oriented'
    else: v='closed-oriented'
    return [bd,it,nm,inc,v]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['empty', [[]], 'empty']], [['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['flipped pair', [[[0, 1, 2], [0, 1, 3]]], [4, 1, 0, 1, 'non-orientable-or-inconsistent']], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']]], [['bowtie', [[[0, 1, 2], [0, 3, 4]]], [6, 0, 0, 0, 'open-oriented']], ['empty', [[]], 'empty'], ['repeated corner', [[[0, 1, 1, 2], [2, 1, 3]]], [4, 1, 0, 0, 'open-oriented']], ['book and flipped pair', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [5, 6, 7], [5, 6, 8]]], [10, 1, 1, 1, 'non-manifold']], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['empty', [[]], 'empty'], ['four sheets', [[[0, 1, 2], [1, 0, 3], [0, 1, 4], [1, 0, 5]]], [8, 0, 1, 0, 'non-manifold']], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], [0, 27, 0, 0, 'closed-oriented']], ['projective plane', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 4], [2, 3, 5], [3, 4, 1], [4, 5, 2], [5, 1, 3]]], [0, 15, 0, 10, 'non-orientable-or-inconsistent']], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']], ['cube', [[[0, 3, 2, 1], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]]], [0, 12, 0, 0, 'closed-oriented']], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], [5, 5, 0, 0, 'open-oriented']], ['mobius', [[[0, 3, 4, 1], [1, 4, 5, 2], [2, 5, 0, 3]]], [6, 3, 0, 1, 'non-orientable-or-inconsistent']], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], [6, 0, 1, 0, 'non-manifold']], ['empty', [[]], 'empty'], ['repeated corner closed', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 3, 2]]], [0, 6, 0, 0, 'closed-oriented']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Empty meshes pass watertightness checks.

Input: polygon faces. Empty input returns "empty". Consecutive repeated indices form no edge (skip that pair only). Undirected edges used once are boundary, twice interior, more non-manifold; an interior edge whose two uses have the same direction is inconsistent. Verdict precedence: non-manifold, then "non-orientable-or-inconsistent", then "open-oriented" (boundary present), else "closed-oriented". Return [boundary, interior, nonmanifold, inconsistent, verdict].

split: open-access


prompt:
Every loop comes back in reversed vertex order.

Input: consistently oriented polygon faces. A half-edge (a,b) is boundary when (b,a) is not a half-edge. If any vertex starts two boundary half-edges return "ambiguous". Otherwise walk loops along the half-edge direction, each starting at its smallest vertex, and return them sorted by descending length then first vertex.

split: open-access


prompt:
A bowtie vertex yields a loop answer instead of "ambiguous".

Input: consistently oriented polygon faces. A half-edge (a,b) is boundary when (b,a) is not a half-edge. If any vertex starts two boundary half-edges return "ambiguous". Otherwise walk loops along the half-edge direction, each starting at its smallest vertex, and return them sorted by descending length then first vertex.

split: open-access


prompt:
The outer boundary is no longer listed first when a hole has a smaller vertex id.

Input: consistently oriented polygon faces. A half-edge (a,b) is boundary when (b,a) is not a half-edge. If any vertex starts two boundary half-edges return "ambiguous". Otherwise walk loops along the half-edge direction, each starting at its smallest vertex, and return them sorted by descending length then first vertex.

split: open-access


prompt:
Loops start at whichever vertex was inserted first rather than at their smallest vertex.

Input: consistently oriented polygon faces. A half-edge (a,b) is boundary when (b,a) is not a half-edge. If any vertex starts two boundary half-edges return "ambiguous". Otherwise walk loops along the half-edge direction, each starting at its smallest vertex, and return them sorted by descending length then first vertex.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    link={}
    for f in faces:
        for i in range(3):
            v=f[i]
            a=f[(i+1)%3]
            b=f[(i+2)%3]
            link.setdefault(v,[]).append((a,b))
    out={}
    for v in sorted(link):
        es=link[v]
        deg={}
        for a,b in es:
            deg[a]=deg.get(a,0)+1
            deg[b]=deg.get(b,0)+1
        if any(d>3 for d in deg.values()):
            out[str(v)]='nonmanifold'
            continue
        adj={}
        for a,b in es:
            adj.setdefault(a,[]).append(b)
            adj.setdefault(b,[]).append(a)
        start=next(iter(adj))
        stack=[start]
        seen={start}
        while stack:
            u=stack.pop()
            for w in adj.get(u,[]):
                if w not in seen:
                    seen.add(w)
                    stack.append(w)
        if len(seen)!=len(adj): out[str(v)]='nonmanifold'
        elif all(d==2 for d in deg.values()): out[str(v)]='interior'
        else: out[str(v)]='boundary'
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}]], [['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['double disk pinch', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [0, 6, 7], [0, 7, 8], [0, 8, 6]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['double disk pinch', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [0, 6, 7], [0, 7, 8], [0, 8, 6]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['single triangle', [[[0, 1, 2]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary'}], ['two triangles sharing edge', [[[0, 1, 2], [2, 1, 3]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary'}]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['two triangles sharing edge', [[[0, 1, 2], [2, 1, 3]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary'}]], [['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    faces=x
    link={}
    for f in faces:
        for i in range(3):
            v=f[i]
            a=f[(i+1)%3]
            b=f[(i+2)%3]
            link.setdefault(v,[]).append((a,b))
    out={}
    for v in sorted(link):
        es=link[v]
        deg={}
        for a,b in es:
            deg[a]=deg.get(a,0)+1
            deg[b]=deg.get(b,0)+1
        if any(d>=2 for d in deg.values()):
            out[str(v)]='nonmanifold'
            continue
        adj={}
        for a,b in es:
            adj.setdefault(a,[]).append(b)
            adj.setdefault(b,[]).append(a)
        start=next(iter(adj))
        stack=[start]
        seen={start}
        while stack:
            u=stack.pop()
            for w in adj.get(u,[]):
                if w not in seen:
                    seen.add(w)
                    stack.append(w)
        if len(seen)!=len(adj): out[str(v)]='nonmanifold'
        elif all(d==2 for d in deg.values()): out[str(v)]='interior'
        else: out[str(v)]='boundary'
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}]], [['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['double disk pinch', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [0, 6, 7], [0, 7, 8], [0, 8, 6]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['double disk pinch', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [0, 6, 7], [0, 7, 8], [0, 8, 6]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}], ['single triangle', [[[0, 1, 2]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary'}], ['two triangles sharing edge', [[[0, 1, 2], [2, 1, 3]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary'}]], [['tetrahedron', [[[0, 2, 1], [0, 1, 3], [1, 2, 3], [0, 3, 2]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior'}], ['disk', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1]]], {'0': 'interior', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary'}], ['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['two triangles sharing edge', [[[0, 1, 2], [2, 1, 3]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary'}]], [['fan', [[[0, 1, 2], [0, 2, 3], [0, 3, 4]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['bowtie', [[[0, 1, 2], [0, 3, 4]]], {'0': 'nonmanifold', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['book', [[[0, 1, 2], [1, 0, 3], [0, 1, 4]]], {'0': 'nonmanifold', '1': 'nonmanifold', '2': 'boundary', '3': 'boundary', '4': 'boundary'}], ['octahedron', [[[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], [5, 2, 1], [5, 3, 2], [5, 4, 3], [5, 1, 4]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior'}], ['torus', [[[0, 3, 4], [0, 4, 1], [1, 4, 5], [1, 5, 2], [2, 5, 3], [2, 3, 0], [3, 6, 7], [3, 7, 4], [4, 7, 8], [4, 8, 5], [5, 8, 6], [5, 6, 3], [6, 0, 1], [6, 1, 7], [7, 1, 2], [7, 2, 8], [8, 2, 0], [8, 0, 6]]], {'0': 'interior', '1': 'interior', '2': 'interior', '3': 'interior', '4': 'interior', '5': 'interior', '6': 'interior', '7': 'interior', '8': 'interior'}], ['open cylinder', [[[0, 1, 5], [0, 5, 4], [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'boundary', '5': 'boundary', '6': 'boundary', '7': 'boundary'}], ['triangle grid', [[[0, 1, 4], [0, 4, 3], [1, 2, 5], [1, 5, 4], [3, 4, 7], [3, 7, 6], [4, 5, 8], [4, 8, 7]]], {'0': 'boundary', '1': 'boundary', '2': 'boundary', '3': 'boundary', '4': 'interior', '5': 'boundary', '6': 'boundary', '7': 'boundary', '8': 'boundary'}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Vertices on a three-sheet fin are classified as manifold.

Input: triangle faces. For each referenced vertex v, its link is the set of opposite edges of incident triangles. v is "nonmanifold" if a link vertex has degree above 2 or the link graph is disconnected, "interior" if every link vertex has degree 2, else "boundary". Return {vertex string: class}.

split: open-access