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

N = 1
observations = []
def solve(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<(1-i) for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=len([i for i in range(2) if i not in group])
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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:
Grouping metadata reverses the declared dimension bit order.

Expand every fact [a,b,payload] once per supplied grouping-set list of column positions. Emit [projected-a,projected-b,grouping-mask,payload], using None for omitted keys and bit 1 for omitted a, bit 2 for omitted b. Preserve duplicate grouping sets and null source keys.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,sets=d
        out=[]
        for group in dict.fromkeys(tuple(g) for g in sets):
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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(d):
    try:
        rows,sets=d
        out=[]
        for group in sorted(set(tuple(g) for g in sets)):
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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:
Grouping expansion deduplicates repeated grouping sets.

Expand every fact [a,b,payload] once per supplied grouping-set list of column positions. Emit [projected-a,projected-b,grouping-mask,payload], using None for omitted keys and bit 1 for omitted a, bit 2 for omitted b. Preserve duplicate grouping sets and null source keys.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=keys
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else 0 for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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:
Grouping expansion leaks source keys into rolled-up slots.

Expand every fact [a,b,payload] once per supplied grouping-set list of column positions. Emit [projected-a,projected-b,grouping-mask,payload], using None for omitted keys and bit 1 for omitted a, bit 2 for omitted b. Preserve duplicate grouping sets and null source keys.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,a])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in rows:
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,b])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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:
Grouping expansion carries a key instead of the fact payload.

Expand every fact [a,b,payload] once per supplied grouping-set list of column positions. Emit [projected-a,projected-b,grouping-mask,payload], using None for omitted keys and bit 1 for omitted a, bit 2 for omitted b. Preserve duplicate grouping sets and null source keys.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in dict.fromkeys(tuple(r) for r in rows):
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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(d):
    try:
        rows,sets=d
        out=[]
        for group in sets:
            for a,b,value in sorted(set(tuple(r) for r in rows),key=repr):
                keys=[a,b]
                projected=[keys[i] if i in group else None for i in range(2)]
                mask=sum(1<<i for i in range(2) if i not in group)
                out.append(projected+[mask,value])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('one dimension', solve([[['a', 'b', 1]], [[0]]]), [['a', None, 2, 1]])
    check('other dimension', solve([[['a', 'b', 1]], [[1]]]), [[None, 'b', 1, 1]])
    check('real null key', solve([[[None, 'b', 1]], [[0, 1]]]), [[None, 'b', 0, 1]])
    check('grand total row', solve([[['a', 'b', 1]], [[]]]), [[None, None, 3, 1]])
    check('duplicate sets', solve([[['a', 'b', 1]], [[0], [0]]]), [['a', None, 2, 1], ['a', None, 2, 1]])
    check('duplicate facts', solve([[['a', 'b', 1], ['a', 'b', 1]], [[0, 1]]]), [['a', 'b', 0, 1], ['a', 'b', 0, 1]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 2:
    check('one dimension', solve([[['a', 'b', 2]], [[0]]]), [['a', None, 2, 2]])
    check('other dimension', solve([[['a', 'b', 2]], [[1]]]), [[None, 'b', 1, 2]])
    check('real null key', solve([[[None, 'b', 2]], [[0, 1]]]), [[None, 'b', 0, 2]])
    check('grand total row', solve([[['a', 'b', 2]], [[]]]), [[None, None, 3, 2]])
    check('duplicate sets', solve([[['a', 'b', 2]], [[0], [0]]]), [['a', None, 2, 2], ['a', None, 2, 2]])
    check('duplicate facts', solve([[['a', 'b', 2], ['a', 'b', 2]], [[0, 1]]]), [['a', 'b', 0, 2], ['a', 'b', 0, 2]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 3:
    check('one dimension', solve([[['a', 'b', 3]], [[0]]]), [['a', None, 2, 3]])
    check('other dimension', solve([[['a', 'b', 3]], [[1]]]), [[None, 'b', 1, 3]])
    check('real null key', solve([[[None, 'b', 3]], [[0, 1]]]), [[None, 'b', 0, 3]])
    check('grand total row', solve([[['a', 'b', 3]], [[]]]), [[None, None, 3, 3]])
    check('duplicate sets', solve([[['a', 'b', 3]], [[0], [0]]]), [['a', None, 2, 3], ['a', None, 2, 3]])
    check('duplicate facts', solve([[['a', 'b', 3], ['a', 'b', 3]], [[0, 1]]]), [['a', 'b', 0, 3], ['a', 'b', 0, 3]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 4:
    check('one dimension', solve([[['a', 'b', 4]], [[0]]]), [['a', None, 2, 4]])
    check('other dimension', solve([[['a', 'b', 4]], [[1]]]), [[None, 'b', 1, 4]])
    check('real null key', solve([[[None, 'b', 4]], [[0, 1]]]), [[None, 'b', 0, 4]])
    check('grand total row', solve([[['a', 'b', 4]], [[]]]), [[None, None, 3, 4]])
    check('duplicate sets', solve([[['a', 'b', 4]], [[0], [0]]]), [['a', None, 2, 4], ['a', None, 2, 4]])
    check('duplicate facts', solve([[['a', 'b', 4], ['a', 'b', 4]], [[0, 1]]]), [['a', 'b', 0, 4], ['a', 'b', 0, 4]])
    check('empty facts', solve([[], [[0], []]]), [])
elif N == 5:
    check('one dimension', solve([[['a', 'b', 5]], [[0]]]), [['a', None, 2, 5]])
    check('other dimension', solve([[['a', 'b', 5]], [[1]]]), [[None, 'b', 1, 5]])
    check('real null key', solve([[[None, 'b', 5]], [[0, 1]]]), [[None, 'b', 0, 5]])
    check('grand total row', solve([[['a', 'b', 5]], [[]]]), [[None, None, 3, 5]])
    check('duplicate sets', solve([[['a', 'b', 5]], [[0], [0]]]), [['a', None, 2, 5], ['a', None, 2, 5]])
    check('duplicate facts', solve([[['a', 'b', 5], ['a', 'b', 5]], [[0, 1]]]), [['a', 'b', 0, 5], ['a', 'b', 0, 5]])
    check('empty facts', solve([[], [[0], []]]), [])
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:
Grouping expansion deduplicates equal facts before expansion.

Expand every fact [a,b,payload] once per supplied grouping-set list of column positions. Emit [projected-a,projected-b,grouping-mask,payload], using None for omitted keys and bit 1 for omitted a, bit 2 for omitted b. Preserve duplicate grouping sets and null source keys.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in sorted(categories):
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in reversed(categories):
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot sorts categories instead of honoring declared columns.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(i for i,c,v in rows if c in categories))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(i for i,c,v in rows if c==categories[0])) if categories else []
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot drops identities seen only in unrequested categories.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if c==category]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident]
                record.append(cell)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot mixes values from different row identities.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append([v for v in cell if v is not None])
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append([0 if v is None else v for v in cell])
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot drops null fact values inside a cell.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell if cell else [None])
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(cell if cell else None)
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot substitutes a null element for an absent cell.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(list(dict.fromkeys(cell)))
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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(d):
    try:
        rows,categories=d
        ids=list(dict.fromkeys(row[0] for row in rows))
        out=[]
        for ident in ids:
            record=[ident]
            for category in categories:
                cell=[value for i,c,value in rows if i==ident and c==category]
                record.append(sorted(set(cell),key=repr))
            out.append(record)
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('column order', solve([[[1, 'a', 1], [1, 'b', 2]], ['b', 'a']]), [[1, [2], [1]]])
    check('unknown-only row', solve([[[1, 'z', 1]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 1], [2, 'a', 2]], ['a']]), [[1, [1]], [2, [2]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 1], [1, 'a', 1]], ['a']]), [[1, [1, 1]]])
    check('no categories', solve([[[1, 'a', 1]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 2:
    check('column order', solve([[[1, 'a', 2], [1, 'b', 3]], ['b', 'a']]), [[1, [3], [2]]])
    check('unknown-only row', solve([[[1, 'z', 2]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 2], [2, 'a', 3]], ['a']]), [[1, [2]], [2, [3]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 2], [1, 'a', 2]], ['a']]), [[1, [2, 2]]])
    check('no categories', solve([[[1, 'a', 2]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 3:
    check('column order', solve([[[1, 'a', 3], [1, 'b', 4]], ['b', 'a']]), [[1, [4], [3]]])
    check('unknown-only row', solve([[[1, 'z', 3]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 3], [2, 'a', 4]], ['a']]), [[1, [3]], [2, [4]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 3], [1, 'a', 3]], ['a']]), [[1, [3, 3]]])
    check('no categories', solve([[[1, 'a', 3]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 4:
    check('column order', solve([[[1, 'a', 4], [1, 'b', 5]], ['b', 'a']]), [[1, [5], [4]]])
    check('unknown-only row', solve([[[1, 'z', 4]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 4], [2, 'a', 5]], ['a']]), [[1, [4]], [2, [5]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 4], [1, 'a', 4]], ['a']]), [[1, [4, 4]]])
    check('no categories', solve([[[1, 'a', 4]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
elif N == 5:
    check('column order', solve([[[1, 'a', 5], [1, 'b', 6]], ['b', 'a']]), [[1, [6], [5]]])
    check('unknown-only row', solve([[[1, 'z', 5]], ['a']]), [[1, []]])
    check('two row groups', solve([[[1, 'a', 5], [2, 'a', 6]], ['a']]), [[1, [5]], [2, [6]]])
    check('null fact', solve([[[1, 'a', None]], ['a']]), [[1, [None]]])
    check('duplicate fact', solve([[[1, 'a', 5], [1, 'a', 5]], ['a']]), [[1, [5, 5]]])
    check('no categories', solve([[[1, 'a', 5]], []]), [[1]])
    check('no facts', solve([[], ['a']]), [])
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:
Pivot treats equal fact values as one fact.

Pivot [row-id,category,value] into [row-id,list-for-category...] using the caller category order. Each cell is an ordered bag list. Unknown categories do not populate cells but retain their row identity; absent cells are empty lists and null values remain elements.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        rows,columns=d
        result=[]
        for row in rows:
            ident=row['id']
            for column in columns:
                if False: continue
                result.append([ident,column,row.get(column)])
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('source column order', solve([[{'id': 9, 'a': 1, 'b': 2}], ['b', 'a']]), [[9, 'b', 2], [9, 'a', 1]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 1}], ['a', 'b']]), [[9, 'a', 1]])
    check('duplicate column', solve([[{'id': 9, 'a': 1}], ['a', 'a']]), [[9, 'a', 1], [9, 'a', 1]])
    check('parent order', solve([[{'id': 9, 'a': 1}, {'id': 2, 'a': 2}], ['a']]), [[9, 'a', 1], [2, 'a', 2]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 1}], []]), [])
elif N == 2:
    check('source column order', solve([[{'id': 9, 'a': 2, 'b': 3}], ['b', 'a']]), [[9, 'b', 3], [9, 'a', 2]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 2}], ['a', 'b']]), [[9, 'a', 2]])
    check('duplicate column', solve([[{'id': 9, 'a': 2}], ['a', 'a']]), [[9, 'a', 2], [9, 'a', 2]])
    check('parent order', solve([[{'id': 9, 'a': 2}, {'id': 2, 'a': 3}], ['a']]), [[9, 'a', 2], [2, 'a', 3]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 2}], []]), [])
elif N == 3:
    check('source column order', solve([[{'id': 9, 'a': 3, 'b': 4}], ['b', 'a']]), [[9, 'b', 4], [9, 'a', 3]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 3}], ['a', 'b']]), [[9, 'a', 3]])
    check('duplicate column', solve([[{'id': 9, 'a': 3}], ['a', 'a']]), [[9, 'a', 3], [9, 'a', 3]])
    check('parent order', solve([[{'id': 9, 'a': 3}, {'id': 2, 'a': 4}], ['a']]), [[9, 'a', 3], [2, 'a', 4]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 3}], []]), [])
elif N == 4:
    check('source column order', solve([[{'id': 9, 'a': 4, 'b': 5}], ['b', 'a']]), [[9, 'b', 5], [9, 'a', 4]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 4}], ['a', 'b']]), [[9, 'a', 4]])
    check('duplicate column', solve([[{'id': 9, 'a': 4}], ['a', 'a']]), [[9, 'a', 4], [9, 'a', 4]])
    check('parent order', solve([[{'id': 9, 'a': 4}, {'id': 2, 'a': 5}], ['a']]), [[9, 'a', 4], [2, 'a', 5]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 4}], []]), [])
elif N == 5:
    check('source column order', solve([[{'id': 9, 'a': 5, 'b': 6}], ['b', 'a']]), [[9, 'b', 6], [9, 'a', 5]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 5}], ['a', 'b']]), [[9, 'a', 5]])
    check('duplicate column', solve([[{'id': 9, 'a': 5}], ['a', 'a']]), [[9, 'a', 5], [9, 'a', 5]])
    check('parent order', solve([[{'id': 9, 'a': 5}, {'id': 2, 'a': 6}], ['a']]), [[9, 'a', 5], [2, 'a', 6]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 5}], []]), [])
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(d):
    try:
        rows,columns=d
        result=[]
        for row in rows:
            ident=row['id']
            for column in columns:
                if column not in row and column==columns[0]: continue
                result.append([ident,column,row.get(column)])
        return result
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('source column order', solve([[{'id': 9, 'a': 1, 'b': 2}], ['b', 'a']]), [[9, 'b', 2], [9, 'a', 1]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 1}], ['a', 'b']]), [[9, 'a', 1]])
    check('duplicate column', solve([[{'id': 9, 'a': 1}], ['a', 'a']]), [[9, 'a', 1], [9, 'a', 1]])
    check('parent order', solve([[{'id': 9, 'a': 1}, {'id': 2, 'a': 2}], ['a']]), [[9, 'a', 1], [2, 'a', 2]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 1}], []]), [])
elif N == 2:
    check('source column order', solve([[{'id': 9, 'a': 2, 'b': 3}], ['b', 'a']]), [[9, 'b', 3], [9, 'a', 2]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 2}], ['a', 'b']]), [[9, 'a', 2]])
    check('duplicate column', solve([[{'id': 9, 'a': 2}], ['a', 'a']]), [[9, 'a', 2], [9, 'a', 2]])
    check('parent order', solve([[{'id': 9, 'a': 2}, {'id': 2, 'a': 3}], ['a']]), [[9, 'a', 2], [2, 'a', 3]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 2}], []]), [])
elif N == 3:
    check('source column order', solve([[{'id': 9, 'a': 3, 'b': 4}], ['b', 'a']]), [[9, 'b', 4], [9, 'a', 3]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 3}], ['a', 'b']]), [[9, 'a', 3]])
    check('duplicate column', solve([[{'id': 9, 'a': 3}], ['a', 'a']]), [[9, 'a', 3], [9, 'a', 3]])
    check('parent order', solve([[{'id': 9, 'a': 3}, {'id': 2, 'a': 4}], ['a']]), [[9, 'a', 3], [2, 'a', 4]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 3}], []]), [])
elif N == 4:
    check('source column order', solve([[{'id': 9, 'a': 4, 'b': 5}], ['b', 'a']]), [[9, 'b', 5], [9, 'a', 4]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 4}], ['a', 'b']]), [[9, 'a', 4]])
    check('duplicate column', solve([[{'id': 9, 'a': 4}], ['a', 'a']]), [[9, 'a', 4], [9, 'a', 4]])
    check('parent order', solve([[{'id': 9, 'a': 4}, {'id': 2, 'a': 5}], ['a']]), [[9, 'a', 4], [2, 'a', 5]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 4}], []]), [])
elif N == 5:
    check('source column order', solve([[{'id': 9, 'a': 5, 'b': 6}], ['b', 'a']]), [[9, 'b', 6], [9, 'a', 5]])
    check('explicit null', solve([[{'id': 9, 'a': None}], ['a']]), [[9, 'a', None]])
    check('missing field', solve([[{'id': 9, 'a': 5}], ['a', 'b']]), [[9, 'a', 5]])
    check('duplicate column', solve([[{'id': 9, 'a': 5}], ['a', 'a']]), [[9, 'a', 5], [9, 'a', 5]])
    check('parent order', solve([[{'id': 9, 'a': 5}, {'id': 2, 'a': 6}], ['a']]), [[9, 'a', 5], [2, 'a', 6]])
    check('zero value', solve([[{'id': 9, 'a': 0}], ['a']]), [[9, 'a', 0]])
    check('empty projection', solve([[{'id': 9, 'a': 5}], []]), [])
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:
Unpivot materializes absent columns as explicit null values.

Unpivot selected columns of record dictionaries into [id,column,value] rows. Include explicitly present None values, skip absent columns, respect requested column order and repetitions, and retain parent row order.

split: open-access