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

N = 1
observations = []
def solve(depth, roster):
    budget = 10 + 5 * depth + depth // 5 * 10
    counts = {}
    picks = []
    while True:
        best = None
        for name, cost, need in roster:
            if need > depth or cost > budget or counts.get(name, 0) > 3:
                continue
            if best is None or cost > best[1] or (cost == best[1] and name < best[0]):
                best = (name, cost)
        if best is None:
            break
        picks.append(best[0])
        counts[best[0]] = counts.get(best[0], 0) + 1
        budget -= best[1]
    return {'picks': picks, 'left': budget}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('fault site copy limit #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('partial repair boundary #1',
   [10, [['imp', 2, 10], ['ogre', 5, 10], ['rat', 1, 3], ['bat', 2, 0], ['orc', 5, 3], ['wyrm', 24, 10]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'ogre', 'bat', 'rat'], 'left': 0}),
  ('regression copy limit #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]], {'picks': ['bat'], 'left': 7})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('fault site copy limit #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression copy limit #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression copy limit #3',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30}),
  ('control #2', [0, [['bat', 18, 0]]], {'picks': [], 'left': 10})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('fault site copy limit #1',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression copy limit #2',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression copy limit #3',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site copy limit #1',
   [1, [['imp', 10, 3], ['orc', 2, 0], ['rat', 10, 10], ['wyrm', 15, 5], ['bat', 15, 3]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 9}),
  ('regression copy limit #1',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression copy limit #2',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [0, [['imp', 10, 1], ['rat', 7, 10], ['orc', 5, 10], ['ogre', 1, 1], ['wyrm', 5, 5]]],
   {'picks': [], 'left': 10}),
  ('control #2', [9, [['ogre', 5, 10]]], {'picks': [], 'left': 65})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('fault site copy limit #1',
   [3, [['orc', 2, 0], ['wyrm', 2, 5]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 19}),
  ('partial repair boundary #1',
   [4, [['rat', 5, 1], ['orc', 8, 0], ['imp', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'rat'], 'left': 1}),
  ('partial repair boundary #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [1, [['wyrm', 8, 10], ['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(depth, roster):
    budget = 10 + 5 * depth + depth // 5 * 10
    counts = {}
    picks = []
    while True:
        best = None
        for name, cost, need in roster:
            if need > depth or cost > budget or len(picks) >= 3:
                continue
            if best is None or cost > best[1] or (cost == best[1] and name < best[0]):
                best = (name, cost)
        if best is None:
            break
        picks.append(best[0])
        counts[best[0]] = counts.get(best[0], 0) + 1
        budget -= best[1]
    return {'picks': picks, 'left': budget}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('fault site copy limit #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('partial repair boundary #1',
   [10, [['imp', 2, 10], ['ogre', 5, 10], ['rat', 1, 3], ['bat', 2, 0], ['orc', 5, 3], ['wyrm', 24, 10]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'ogre', 'bat', 'rat'], 'left': 0}),
  ('regression copy limit #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]], {'picks': ['bat'], 'left': 7})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('fault site copy limit #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression copy limit #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression copy limit #3',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30}),
  ('control #2', [0, [['bat', 18, 0]]], {'picks': [], 'left': 10})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('fault site copy limit #1',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression copy limit #2',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression copy limit #3',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site copy limit #1',
   [1, [['imp', 10, 3], ['orc', 2, 0], ['rat', 10, 10], ['wyrm', 15, 5], ['bat', 15, 3]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 9}),
  ('regression copy limit #1',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression copy limit #2',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [0, [['imp', 10, 1], ['rat', 7, 10], ['orc', 5, 10], ['ogre', 1, 1], ['wyrm', 5, 5]]],
   {'picks': [], 'left': 10}),
  ('control #2', [9, [['ogre', 5, 10]]], {'picks': [], 'left': 65})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('regression copy limit #1',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('fault site copy limit #1',
   [3, [['orc', 2, 0], ['wyrm', 2, 5]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 19}),
  ('partial repair boundary #1',
   [4, [['rat', 5, 1], ['orc', 8, 0], ['imp', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'rat'], 'left': 1}),
  ('partial repair boundary #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1', [1, [['wyrm', 8, 10], ['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Encounters exceed the three-per-type variety rule.

budget = 10 + 5*depth + 10*(depth//5). roster [name, cost, min_depth] with cost >= 1. Repeatedly pick the most expensive unlocked (min_depth <= depth) affordable enemy with fewer than 3 copies already picked, ties broken by name; stop when none qualifies. Returns {picks, left}.

split: open-access


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

N = 1
observations = []
def solve(depth, roster):
    budget = 10 + 5 * depth + depth // 5 * 10
    counts = {}
    picks = []
    while True:
        best = None
        for name, cost, need in roster:
            if need > depth or cost > budget or counts.get(name, 0) >= 3:
                continue
            if best is None or cost > best[1] or (cost == best[1] and name > best[0]):
                best = (name, cost)
        if best is None:
            break
        picks.append(best[0])
        counts[best[0]] = counts.get(best[0], 0) + 1
        budget -= best[1]
    return {'picks': picks, 'left': budget}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [10, [['imp', 2, 10], ['ogre', 5, 10], ['rat', 1, 3], ['bat', 2, 0], ['orc', 5, 3], ['wyrm', 24, 10]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'ogre', 'bat', 'rat'], 'left': 0}),
  ('regression tie break #2',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression tie break #3',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression tie break #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #3',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression tie break #2',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('regression tie break #3',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site tie break #1',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('regression tie break #1',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #2',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('regression tie break #3',
   [10, [['bat', 10, 1], ['ogre', 10, 10], ['orc', 5, 10]]],
   {'picks': ['bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre', 'orc', 'orc', 'orc'], 'left': 5}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site tie break #1',
   [20, [['orc', 5, 5], ['rat', 10, 0], ['ogre', 9, 1], ['imp', 5, 1], ['bat', 5, 3], ['wyrm', 1, 0]]],
   {'picks': ['rat',
              'rat',
              'rat',
              'ogre',
              'ogre',
              'ogre',
              'bat',
              'bat',
              'bat',
              'imp',
              'imp',
              'imp',
              'orc',
              'orc',
              'orc',
              'wyrm',
              'wyrm',
              'wyrm'],
    'left': 45}),
  ('regression tie break #1',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('regression tie break #2',
   [14, [['imp', 5, 1], ['rat', 5, 3], ['orc', 2, 5], ['ogre', 8, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre', 'imp', 'imp', 'imp', 'rat', 'rat', 'rat', 'orc', 'orc', 'orc'],
    'left': 40}),
  ('regression tie break #3',
   [9, [['ogre', 1, 1], ['wyrm', 1, 0], ['orc', 5, 3]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre', 'ogre', 'wyrm', 'wyrm', 'wyrm'], 'left': 44}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1', [5, [['orc', 10, 1], ['imp', 5, 10]]], {'picks': ['orc', 'orc', 'orc'], 'left': 15})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(depth, roster):
    budget = 10 + 5 * depth + depth // 5 * 10
    counts = {}
    picks = []
    while True:
        best = None
        for name, cost, need in roster:
            if need > depth or cost > budget or counts.get(name, 0) >= 3:
                continue
            if best is None or cost > best[1] or cost == best[1]:
                best = (name, cost)
        if best is None:
            break
        picks.append(best[0])
        counts[best[0]] = counts.get(best[0], 0) + 1
        budget -= best[1]
    return {'picks': picks, 'left': budget}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [10, [['imp', 2, 10], ['ogre', 5, 10], ['rat', 1, 3], ['bat', 2, 0], ['orc', 5, 3], ['wyrm', 24, 10]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'ogre', 'bat', 'rat'], 'left': 0}),
  ('regression tie break #2',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression tie break #3',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression tie break #2',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #3',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('regression tie break #1',
   [5, [['bat', 8, 1], ['orc', 15, 10], ['wyrm', 10, 1], ['ogre', 1, 3], ['rat', 1, 3], ['imp', 2, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'imp', 'imp', 'imp', 'ogre'], 'left': 0}),
  ('regression tie break #2',
   [10, [['imp', 15, 10], ['ogre', 5, 1], ['orc', 5, 5], ['rat', 5, 0], ['wyrm', 10, 1]]],
   {'picks': ['imp', 'imp', 'imp', 'wyrm', 'wyrm', 'wyrm', 'ogre'], 'left': 0}),
  ('regression tie break #3',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #4',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site tie break #1',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('regression tie break #1',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression tie break #2',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('regression tie break #3',
   [10, [['bat', 10, 1], ['ogre', 10, 10], ['orc', 5, 10]]],
   {'picks': ['bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre', 'orc', 'orc', 'orc'], 'left': 5}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site tie break #1',
   [20, [['orc', 5, 5], ['rat', 10, 0], ['ogre', 9, 1], ['imp', 5, 1], ['bat', 5, 3], ['wyrm', 1, 0]]],
   {'picks': ['rat',
              'rat',
              'rat',
              'ogre',
              'ogre',
              'ogre',
              'bat',
              'bat',
              'bat',
              'imp',
              'imp',
              'imp',
              'orc',
              'orc',
              'orc',
              'wyrm',
              'wyrm',
              'wyrm'],
    'left': 45}),
  ('regression tie break #1',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('regression tie break #2',
   [14, [['imp', 5, 1], ['rat', 5, 3], ['orc', 2, 5], ['ogre', 8, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre', 'imp', 'imp', 'imp', 'rat', 'rat', 'rat', 'orc', 'orc', 'orc'],
    'left': 40}),
  ('regression tie break #3',
   [9, [['ogre', 1, 1], ['wyrm', 1, 0], ['orc', 5, 3]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre', 'ogre', 'wyrm', 'wyrm', 'wyrm'], 'left': 44}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('control #1', [5, [['orc', 10, 1], ['imp', 5, 10]]], {'picks': ['orc', 'orc', 'orc'], 'left': 15})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Encounter composition depends on the name order reversed.

budget = 10 + 5*depth + 10*(depth//5). roster [name, cost, min_depth] with cost >= 1. Repeatedly pick the most expensive unlocked (min_depth <= depth) affordable enemy with fewer than 3 copies already picked, ties broken by name; stop when none qualifies. Returns {picks, left}.

split: open-access


prompt:
Rooms to the left are connected by a missing corridor leg.

Carve from centre a [x, y] to b. Horizontal-first walks x from ax to bx on row ay, then y from ay to by on column bx; otherwise y first on column ax, then x on row by. Both legs include their endpoints; returns cells [x, y] in walk order without duplicates.

split: open-access


prompt:
The corridor never enters the target room.

Carve from centre a [x, y] to b. Horizontal-first walks x from ax to bx on row ay, then y from ay to by on column bx; otherwise y first on column ax, then x on row by. Both legs include their endpoints; returns cells [x, y] in walk order without duplicates.

split: open-access


prompt:
Horizontal-first corridors leave the corner disconnected.

Carve from centre a [x, y] to b. Horizontal-first walks x from ax to bx on row ay, then y from ay to by on column bx; otherwise y first on column ax, then x on row by. Both legs include their endpoints; returns cells [x, y] in walk order without duplicates.

split: open-access


prompt:
The corner appears twice and corridor length is overcounted.

Carve from centre a [x, y] to b. Horizontal-first walks x from ax to bx on row ay, then y from ay to by on column bx; otherwise y first on column ax, then x on row by. Both legs include their endpoints; returns cells [x, y] in walk order without duplicates.

split: open-access


prompt:
Corridors bend on the wrong corner, cutting through rooms.

Carve from centre a [x, y] to b. Horizontal-first walks x from ax to bx on row ay, then y from ay to by on column bx; otherwise y first on column ax, then x on row by. Both legs include their endpoints; returns cells [x, y] in walk order without duplicates.

split: open-access


prompt:
Treasure spawns on doors or over chasms.

Cells: '#' wall, '~' chasm (not walkable), '.' floor, 'D' door (walkable). A dead end is a '.' cell, other than start and exit ([row, col] lists), with exactly one walkable in-bounds 4-neighbour. Returns dead ends in row-major order.

split: open-access


prompt:
Cells beside a chasm are not recognized as dead ends.

Cells: '#' wall, '~' chasm (not walkable), '.' floor, 'D' door (walkable). A dead end is a '.' cell, other than start and exit ([row, col] lists), with exactly one walkable in-bounds 4-neighbour. Returns dead ends in row-major order.

split: open-access


prompt:
Treasure is placed in sealed pockets the player cannot reach.

Cells: '#' wall, '~' chasm (not walkable), '.' floor, 'D' door (walkable). A dead end is a '.' cell, other than start and exit ([row, col] lists), with exactly one walkable in-bounds 4-neighbour. Returns dead ends in row-major order.

split: open-access


prompt:
The exit tile is reported as a treasure dead end.

Cells: '#' wall, '~' chasm (not walkable), '.' floor, 'D' door (walkable). A dead end is a '.' cell, other than start and exit ([row, col] lists), with exactly one walkable in-bounds 4-neighbour. Returns dead ends in row-major order.

split: open-access


prompt:
Mazes with diagonal openings pass validation.

Cells (x, y) with 0 <= x < w, 0 <= y < h. First pass over passages [[x1, y1], [x2, y2]]: out-of-bounds or non-orthogonally-adjacent pairs -> 'invalid-edge'; the same passage twice in either orientation -> 'duplicate'. Then union passages in order: joining already connected cells -> 'loop'. Finally 'perfect' if all cells are connected, else 'disconnected'.

split: open-access


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

N = 1
observations = []
def solve(w, h, passages):
    seen = set()
    parent = {(x, y): (x, y) for x in range(w) for y in range(h)}
    def find(p):
        while parent[p] != p:
            parent[p] = parent[parent[p]]
            p = parent[p]
        return p
    for (x1, y1), (x2, y2) in passages:
        if not (0 <= x1 < w and 0 <= y1 < h and 0 <= x2 < w and 0 <= y2 < h):
            return 'invalid-edge'
        if abs(x1 - x2) + abs(y1 - y2) != 1:
            return 'invalid-edge'
        key = tuple(sorted([x1, y1, x2, y2]))
        if key in seen:
            return 'duplicate'
        seen.add(key)
    for (x1, y1), (x2, y2) in passages:
        a, b = find((x1, y1)), find((x2, y2))
        if a == b:
            return 'loop'
        parent[a] = b
    roots = {find(p) for p in parent}
    return 'perfect' if len(roots) == 1 else 'disconnected'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('fault site duplicate key #1',
   [4, 1, [[[2, 0], [1, 0]], [[3, 0], [2, 0]], [[0, 0], [1, 0]], [[1, 0], [0, 0]]]],
   'duplicate'),
  ('fault site duplicate key #2',
   [3, 1, [[[1, 0], [0, 0]], [[0, 0], [1, 0]], [[1, 0], [2, 0]]]],
   'duplicate'),
  ('partial repair boundary #1',
   [4,
    3,
    [[[1, 0], [1, 1]],
     [[0, 1], [0, 0]],
     [[0, 1], [0, 2]],
     [[2, 0], [2, 1]],
     [[1, 0], [0, 0]],
     [[1, 0], [2, 0]],
     [[2, 1], [2, 2]],
     [[2, 2], [3, 2]],
     [[2, 1], [3, 1]],
     [[2, 2], [1, 2]],
     [[1, 1], [0, 1]],
     [[0, 2], [1, 2]]]],
   'loop'),
  ('partial repair boundary #2',
   [3,
    3,
    [[[1, 2], [0, 2]],
     [[1, 0], [2, 0]],
     [[0, 0], [0, 1]],
     [[1, 1], [1, 0]],
     [[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[0, 2], [0, 2]]]],
   'invalid-edge'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('single cell maze #1', [1, 1, []], 'perfect'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('fault site duplicate key #1',
   [3, 1, [[[1, 0], [0, 0]], [[0, 0], [1, 0]], [[1, 0], [2, 0]]]],
   'duplicate'),
  ('fault site duplicate key #2',
   [3,
    4,
    [[[1, 3], [2, 3]],
     [[0, 2], [1, 2]],
     [[2, 1], [2, 0]],
     [[1, 0], [2, 0]],
     [[2, 2], [2, 1]],
     [[0, 2], [0, 1]],
     [[0, 1], [1, 1]],
     [[1, 2], [1, 1]],
     [[1, 2], [2, 2]],
     [[2, 1], [2, 2]],
     [[1, 1], [1, 0]]]],
   'duplicate'),
  ('partial repair boundary #1',
   [3,
    3,
    [[[2, 1], [2, 0]],
     [[2, 0], [1, 0]],
     [[0, 1], [0, 0]],
     [[0, 1], [1, 1]],
     [[1, 0], [1, 1]],
     [[0, 0], [1, 0]],
     [[0, 1], [0, 2]]]],
   'loop'),
  ('partial repair boundary #2',
   [3, 2, [[[2, 1], [2, 0]], [[0, 1], [1, 1]], [[1, 0], [0, 0]], [[1, 1], [1, 0]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('single cell maze #1', [1, 1, []], 'perfect'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('fault site duplicate key #1',
   [2,
    3,
    [[[0, 0], [1, 0]],
     [[1, 0], [0, 0]],
     [[1, 2], [1, 1]],
     [[0, 1], [0, 1]],
     [[1, 0], [1, 1]],
     [[0, 1], [1, 1]],
     [[0, 1], [0, 2]],
     [[0, 2], [1, 2]]]],
   'duplicate'),
  ('fault site duplicate key #2',
   [3, 1, [[[1, 0], [2, 0]], [[0, 0], [1, 0]], [[1, 0], [0, 0]]]],
   'duplicate'),
  ('partial repair boundary #1',
   [4,
    2,
    [[[1, 0], [0, 0]],
     [[1, 0], [1, 1]],
     [[3, 0], [2, 0]],
     [[2, 1], [3, 1]],
     [[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[3, 1], [3, 0]]]],
   'loop'),
  ('partial repair boundary #2',
   [4,
    4,
    [[[0, 0], [1, 0]],
     [[0, 2], [0, 1]],
     [[2, 3], [2, 2]],
     [[2, 0], [3, 0]],
     [[1, 2], [2, 2]],
     [[3, 1], [3, 0]],
     [[3, 2], [2, 2]],
     [[2, 1], [2, 0]],
     [[3, 2], [3, 3]],
     [[1, 1], [0, 1]],
     [[1, 2], [1, 1]],
     [[0, 2], [1, 2]],
     [[3, 1], [3, 2]]]],
   'loop'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('single cell maze #1', [1, 1, []], 'perfect'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('fault site duplicate key #1',
   [4, 2, [[[1, 1], [1, 0]], [[2, 0], [2, 1]], [[2, 1], [1, 1]], [[2, 1], [2, 0]], [[0, 0], [0, 1]]]],
   'duplicate'),
  ('fault site duplicate key #2',
   [3,
    2,
    [[[2, 1], [2, 0]],
     [[2, 0], [2, 1]],
     [[0, 0], [0, 1]],
     [[0, 0], [1, 0]],
     [[1, 1], [2, 1]],
     [[1, 0], [2, 0]],
     [[1, 0], [1, 1]]]],
   'duplicate'),
  ('partial repair boundary #1',
   [4,
    4,
    [[[0, 0], [0, 1]],
     [[2, 0], [3, 0]],
     [[0, 2], [0, 1]],
     [[1, 0], [2, 0]],
     [[2, 1], [3, 1]],
     [[1, 3], [2, 3]],
     [[3, 3], [3, 2]],
     [[0, 2], [0, 3]],
     [[2, 1], [1, 1]],
     [[2, 2], [2, 1]],
     [[1, 3], [0, 3]],
     [[1, 1], [1, 2]],
     [[2, 0], [2, 1]],
     [[2, 2], [2, 3]],
     [[2, 3], [3, 3]],
     [[1, 2], [2, 2]]]],
   'loop'),
  ('partial repair boundary #2',
   [3, 2, [[[0, 1], [0, 0]], [[1, 1], [2, 1]], [[1, 1], [0, 1]], [[1, 0], [1, 1]], [[2, 1], [2, 0]]]],
   'perfect'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('single cell maze #1', [1, 1, []], 'perfect'),
  ('control #1', [4, 1, [[[2, 0], [2, 0]], [[1, 0], [0, 0]], [[2, 0], [1, 0]]]], 'invalid-edge')],
 [('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('fault site duplicate key #1',
   [1, 4, [[[0, 2], [0, 3]], [[0, 0], [0, 1]], [[0, 3], [0, 2]]]],
   'duplicate'),
  ('fault site duplicate key #2',
   [1, 4, [[[0, 3], [0, 2]], [[0, 1], [0, 2]], [[0, 2], [0, 3]], [[0, 0], [0, 1]]]],
   'duplicate'),
  ('partial repair boundary #1',
   [2,
    4,
    [[[1, 2], [1, 1]],
     [[1, 0], [0, 0]],
     [[1, 1], [0, 1]],
     [[0, 1], [0, 2]],
     [[1, 0], [1, 1]],
     [[0, 2], [1, 2]]]],
   'loop'),
  ('partial repair boundary #2', [2, 2, [[[1, 1], [0, 1]], [[1, 0], [1, 1]], [[0, 0], [0, 1]]]], 'perfect'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('single cell maze #1', [1, 1, []], 'perfect'),
  ('control #1',
   [3,
    3,
    [[[1, 0], [1, 0]],
     [[1, 0], [2, 0]],
     [[0, 2], [0, 1]],
     [[2, 2], [2, 1]],
     [[0, 2], [1, 2]],
     [[1, 0], [0, 0]],
     [[0, 1], [1, 1]]]],
   'invalid-edge')]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A passage listed both ways is reported as a loop.

Cells (x, y) with 0 <= x < w, 0 <= y < h. First pass over passages [[x1, y1], [x2, y2]]: out-of-bounds or non-orthogonally-adjacent pairs -> 'invalid-edge'; the same passage twice in either orientation -> 'duplicate'. Then union passages in order: joining already connected cells -> 'loop'. Finally 'perfect' if all cells are connected, else 'disconnected'.

split: open-access


prompt:
Connected mazes are reported as loops or disconnected.

Cells (x, y) with 0 <= x < w, 0 <= y < h. First pass over passages [[x1, y1], [x2, y2]]: out-of-bounds or non-orthogonally-adjacent pairs -> 'invalid-edge'; the same passage twice in either orientation -> 'duplicate'. Then union passages in order: joining already connected cells -> 'loop'. Finally 'perfect' if all cells are connected, else 'disconnected'.

split: open-access


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

N = 1
observations = []
def solve(w, h, passages):
    seen = set()
    parent = {(x, y): (x, y) for x in range(w) for y in range(h)}
    def find(p):
        while parent[p] != p:
            parent[p] = parent[parent[p]]
            p = parent[p]
        return p
    for (x1, y1), (x2, y2) in passages:
        if not (0 <= x1 < w and 0 <= y1 < h and 0 <= x2 < w and 0 <= y2 < h):
            return 'invalid-edge'
        if abs(x1 - x2) + abs(y1 - y2) != 1:
            return 'invalid-edge'
        key = tuple(sorted([(x1, y1), (x2, y2)]))
        if key in seen:
            return 'duplicate'
        seen.add(key)
    for (x1, y1), (x2, y2) in passages:
        a, b = find((x1, y1)), find((x2, y2))
        if a == b:
            return 'loop'
        parent[a] = b
    roots = {parent[p] for p in parent}
    return 'perfect' if len(roots) == 1 else 'disconnected'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [3, 2, [[[0, 1], [0, 0]], [[1, 1], [2, 1]], [[1, 1], [0, 1]], [[1, 0], [1, 1]], [[2, 1], [2, 0]]]],
   'perfect'),
  ('fault site component roots #2', [3, 1, [[[0, 0], [1, 0]], [[1, 0], [2, 0]]]], 'perfect'),
  ('partial repair boundary #1', [1, 3, [[[0, 1], [0, 2]]]], 'disconnected'),
  ('partial repair boundary #2',
   [4,
    2,
    [[[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [1, 0]],
     [[2, 1], [3, 1]],
     [[3, 0], [3, 1]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [2, 2, [[[0, 0], [0, 1]], [[0, 1], [1, 1]], [[1, 1], [1, 0]]]],
   'perfect'),
  ('fault site component roots #2', [1, 3, [[[0, 1], [0, 2]], [[0, 1], [0, 0]]]], 'perfect'),
  ('partial repair boundary #1',
   [4,
    2,
    [[[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [1, 0]],
     [[2, 1], [3, 1]],
     [[3, 0], [3, 1]]]],
   'disconnected'),
  ('partial repair boundary #2',
   [4, 2, [[[2, 1], [1, 1]], [[1, 0], [0, 0]], [[2, 1], [2, 0]], [[1, 0], [1, 1]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [1, 4, [[[0, 2], [0, 3]], [[0, 2], [0, 1]], [[0, 1], [0, 0]]]],
   'perfect'),
  ('fault site component roots #2',
   [3, 2, [[[1, 1], [2, 1]], [[0, 0], [1, 0]], [[2, 1], [2, 0]], [[0, 0], [0, 1]], [[1, 0], [2, 0]]]],
   'perfect'),
  ('partial repair boundary #1', [3, 1, [[[0, 0], [1, 0]]]], 'disconnected'),
  ('partial repair boundary #2',
   [3,
    4,
    [[[2, 0], [1, 0]],
     [[1, 2], [1, 1]],
     [[2, 2], [2, 3]],
     [[2, 2], [2, 1]],
     [[1, 0], [1, 1]],
     [[1, 1], [2, 1]],
     [[1, 0], [0, 0]],
     [[1, 3], [1, 2]],
     [[0, 2], [0, 1]],
     [[1, 2], [0, 2]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [2,
    4,
    [[[0, 0], [1, 0]],
     [[0, 2], [0, 1]],
     [[1, 2], [1, 3]],
     [[1, 2], [0, 2]],
     [[0, 3], [1, 3]],
     [[1, 0], [1, 1]],
     [[1, 1], [0, 1]]]],
   'perfect'),
  ('fault site component roots #2',
   [2, 3, [[[0, 2], [0, 1]], [[0, 0], [0, 1]], [[1, 1], [1, 0]], [[1, 2], [0, 2]], [[0, 0], [1, 0]]]],
   'perfect'),
  ('partial repair boundary #1', [1, 3, [[[0, 1], [0, 0]]]], 'disconnected'),
  ('partial repair boundary #2', [1, 3, [[[0, 2], [0, 1]]]], 'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [4,
    3,
    [[[1, 0], [1, 1]],
     [[0, 1], [0, 0]],
     [[0, 1], [0, 2]],
     [[2, 0], [2, 1]],
     [[1, 0], [0, 0]],
     [[1, 0], [2, 0]],
     [[2, 1], [2, 2]],
     [[2, 2], [3, 2]],
     [[2, 1], [3, 1]],
     [[2, 2], [1, 2]],
     [[1, 1], [0, 1]],
     [[0, 2], [1, 2]]]],
   'loop')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [1, 4, [[[0, 0], [0, 1]], [[0, 1], [0, 2]], [[0, 2], [0, 3]]]],
   'perfect'),
  ('fault site component roots #2',
   [4,
    2,
    [[[1, 0], [1, 1]],
     [[0, 0], [0, 1]],
     [[3, 1], [3, 0]],
     [[3, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [3, 0]],
     [[2, 1], [1, 1]]]],
   'perfect'),
  ('partial repair boundary #1', [2, 3, [[[0, 1], [0, 0]], [[0, 1], [0, 2]]]], 'disconnected'),
  ('partial repair boundary #2', [4, 1, [[[3, 0], [2, 0]], [[1, 0], [2, 0]]]], 'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [4, 1, [[[2, 0], [1, 0]], [[3, 0], [2, 0]], [[0, 0], [1, 0]], [[1, 0], [0, 0]]]],
   'duplicate')]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(w, h, passages):
    seen = set()
    parent = {(x, y): (x, y) for x in range(w) for y in range(h)}
    def find(p):
        while parent[p] != p:
            parent[p] = parent[parent[p]]
            p = parent[p]
        return p
    for (x1, y1), (x2, y2) in passages:
        if not (0 <= x1 < w and 0 <= y1 < h and 0 <= x2 < w and 0 <= y2 < h):
            return 'invalid-edge'
        if abs(x1 - x2) + abs(y1 - y2) != 1:
            return 'invalid-edge'
        key = tuple(sorted([(x1, y1), (x2, y2)]))
        if key in seen:
            return 'duplicate'
        seen.add(key)
    for (x1, y1), (x2, y2) in passages:
        a, b = find((x1, y1)), find((x2, y2))
        if a == b:
            return 'loop'
        parent[a] = b
    roots = {find(p) for p in parent if parent[p] != p}
    return 'perfect' if len(roots) == 1 else 'disconnected'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [3, 2, [[[0, 1], [0, 0]], [[1, 1], [2, 1]], [[1, 1], [0, 1]], [[1, 0], [1, 1]], [[2, 1], [2, 0]]]],
   'perfect'),
  ('fault site component roots #2', [3, 1, [[[0, 0], [1, 0]], [[1, 0], [2, 0]]]], 'perfect'),
  ('partial repair boundary #1', [1, 3, [[[0, 1], [0, 2]]]], 'disconnected'),
  ('partial repair boundary #2',
   [4,
    2,
    [[[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [1, 0]],
     [[2, 1], [3, 1]],
     [[3, 0], [3, 1]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [2, 2, [[[0, 0], [0, 1]], [[0, 1], [1, 1]], [[1, 1], [1, 0]]]],
   'perfect'),
  ('fault site component roots #2', [1, 3, [[[0, 1], [0, 2]], [[0, 1], [0, 0]]]], 'perfect'),
  ('partial repair boundary #1',
   [4,
    2,
    [[[2, 1], [2, 0]],
     [[1, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [1, 0]],
     [[2, 1], [3, 1]],
     [[3, 0], [3, 1]]]],
   'disconnected'),
  ('partial repair boundary #2',
   [4, 2, [[[2, 1], [1, 1]], [[1, 0], [0, 0]], [[2, 1], [2, 0]], [[1, 0], [1, 1]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [1, 4, [[[0, 2], [0, 3]], [[0, 2], [0, 1]], [[0, 1], [0, 0]]]],
   'perfect'),
  ('fault site component roots #2',
   [3, 2, [[[1, 1], [2, 1]], [[0, 0], [1, 0]], [[2, 1], [2, 0]], [[0, 0], [0, 1]], [[1, 0], [2, 0]]]],
   'perfect'),
  ('partial repair boundary #1', [3, 1, [[[0, 0], [1, 0]]]], 'disconnected'),
  ('partial repair boundary #2',
   [3,
    4,
    [[[2, 0], [1, 0]],
     [[1, 2], [1, 1]],
     [[2, 2], [2, 3]],
     [[2, 2], [2, 1]],
     [[1, 0], [1, 1]],
     [[1, 1], [2, 1]],
     [[1, 0], [0, 0]],
     [[1, 3], [1, 2]],
     [[0, 2], [0, 1]],
     [[1, 2], [0, 2]]]],
   'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [3, 2, [[[2, 1], [1, 1]], [[0, 1], [0, 0]], [[1, 1], [2, 2]], [[0, 0], [1, 0]]]],
   'invalid-edge')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [2,
    4,
    [[[0, 0], [1, 0]],
     [[0, 2], [0, 1]],
     [[1, 2], [1, 3]],
     [[1, 2], [0, 2]],
     [[0, 3], [1, 3]],
     [[1, 0], [1, 1]],
     [[1, 1], [0, 1]]]],
   'perfect'),
  ('fault site component roots #2',
   [2, 3, [[[0, 2], [0, 1]], [[0, 0], [0, 1]], [[1, 1], [1, 0]], [[1, 2], [0, 2]], [[0, 0], [1, 0]]]],
   'perfect'),
  ('partial repair boundary #1', [1, 3, [[[0, 1], [0, 0]]]], 'disconnected'),
  ('partial repair boundary #2', [1, 3, [[[0, 2], [0, 1]]]], 'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [4,
    3,
    [[[1, 0], [1, 1]],
     [[0, 1], [0, 0]],
     [[0, 1], [0, 2]],
     [[2, 0], [2, 1]],
     [[1, 0], [0, 0]],
     [[1, 0], [2, 0]],
     [[2, 1], [2, 2]],
     [[2, 2], [3, 2]],
     [[2, 1], [3, 1]],
     [[2, 2], [1, 2]],
     [[1, 1], [0, 1]],
     [[0, 2], [1, 2]]]],
   'loop')],
 [('single cell maze #1', [1, 1, []], 'perfect'),
  ('fault site component roots #1',
   [1, 4, [[[0, 0], [0, 1]], [[0, 1], [0, 2]], [[0, 2], [0, 3]]]],
   'perfect'),
  ('fault site component roots #2',
   [4,
    2,
    [[[1, 0], [1, 1]],
     [[0, 0], [0, 1]],
     [[3, 1], [3, 0]],
     [[3, 1], [2, 1]],
     [[1, 1], [0, 1]],
     [[2, 0], [3, 0]],
     [[2, 1], [1, 1]]]],
   'perfect'),
  ('partial repair boundary #1', [2, 3, [[[0, 1], [0, 0]], [[0, 1], [0, 2]]]], 'disconnected'),
  ('partial repair boundary #2', [4, 1, [[[3, 0], [2, 0]], [[1, 0], [2, 0]]]], 'disconnected'),
  ('diagonal passage #1', [2, 2, [[[0, 0], [1, 1]]]], 'invalid-edge'),
  ('reversed duplicate #1', [2, 1, [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 'duplicate'),
  ('control #1',
   [4, 1, [[[2, 0], [1, 0]], [[3, 0], [2, 0]], [[0, 0], [1, 0]], [[1, 0], [0, 0]]]],
   'duplicate')]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Fully connected mazes are reported disconnected.

Cells (x, y) with 0 <= x < w, 0 <= y < h. First pass over passages [[x1, y1], [x2, y2]]: out-of-bounds or non-orthogonally-adjacent pairs -> 'invalid-edge'; the same passage twice in either orientation -> 'duplicate'. Then union passages in order: joining already connected cells -> 'loop'. Finally 'perfect' if all cells are connected, else 'disconnected'.

split: open-access


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

N = 1
observations = []
def solve(n, doors, start):
    adj = {i: [] for i in range(n)}
    for a, b in doors:
        adj[a].append(b)
        pass
    dist = {start: 0}
    queue = [start]
    for u in queue:
        for v in sorted(adj[u]):
            if v not in dist:
                dist[v] = dist[u] + 1
                queue.append(v)
    best = None
    for room, d in dist.items():
        if room == start:
            continue
        if best is None or d > best[1] or (d == best[1] and room < best[0]):
            best = [room, d]
    return best
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [6, [[0, 1], [1, 2], [1, 3], [1, 4], [2, 0], [1, 4]], 2], [3, 2]),
  ('regression door symmetry #1', [7, [[0, 1], [0, 2], [1, 3], [4, 0], [3, 5], [6, 2]], 1], [6, 3]),
  ('regression door symmetry #2', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('regression door symmetry #3', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('regression door symmetry #1', [7, [[0, 1], [0, 2], [1, 3], [4, 0], [3, 5], [6, 2]], 1], [6, 3]),
  ('fault site door symmetry #1', [2, [[0, 1], [0, 1]], 1], [0, 1]),
  ('regression door symmetry #2', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('regression door symmetry #3', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [8, [[0, 1], [1, 2], [1, 4], [5, 2], [3, 6], [7, 3], [3, 7]], 2], [0, 2]),
  ('regression door symmetry #1', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('partial repair boundary #1', [4, [[0, 1], [2, 0], [1, 3], [2, 3], [0, 3]], 0], [1, 1]),
  ('regression door symmetry #2', [3, [[1, 0], [2, 1]], 0], [2, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('regression door symmetry #1', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('fault site door symmetry #1', [3, [[0, 1], [2, 1], [0, 1]], 2], [0, 2]),
  ('regression door symmetry #2', [6, [[2, 1], [3, 1], [1, 5]], 3], [2, 2]),
  ('regression door symmetry #3', [5, [[2, 1], [4, 2]], 1], [4, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [8, [[1, 0], [1, 3], [3, 4], [4, 5], [0, 6], [7, 4], [3, 7]], 2], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [4, [[0, 1], [0, 2], [0, 3], [1, 3], [2, 0]], 3], [2, 2]),
  ('regression door symmetry #1', [3, [[1, 0], [2, 1]], 0], [2, 2]),
  ('regression door symmetry #2', [4, [[1, 0], [2, 0], [3, 0]], 0], [1, 1]),
  ('regression door symmetry #3', [4, [[0, 2], [2, 1], [2, 0]], 1], [0, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [5, [[0, 1], [0, 2], [3, 0], [0, 3]], 4], None)]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(n, doors, start):
    adj = {i: [] for i in range(n)}
    for a, b in doors:
        adj[a].append(b)
        adj[b].append(a) if a < b else None
    dist = {start: 0}
    queue = [start]
    for u in queue:
        for v in sorted(adj[u]):
            if v not in dist:
                dist[v] = dist[u] + 1
                queue.append(v)
    best = None
    for room, d in dist.items():
        if room == start:
            continue
        if best is None or d > best[1] or (d == best[1] and room < best[0]):
            best = [room, d]
    return best
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [6, [[0, 1], [1, 2], [1, 3], [1, 4], [2, 0], [1, 4]], 2], [3, 2]),
  ('regression door symmetry #1', [7, [[0, 1], [0, 2], [1, 3], [4, 0], [3, 5], [6, 2]], 1], [6, 3]),
  ('regression door symmetry #2', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('regression door symmetry #3', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('regression door symmetry #1', [7, [[0, 1], [0, 2], [1, 3], [4, 0], [3, 5], [6, 2]], 1], [6, 3]),
  ('fault site door symmetry #1', [2, [[0, 1], [0, 1]], 1], [0, 1]),
  ('regression door symmetry #2', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('regression door symmetry #3', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [8, [[0, 1], [1, 2], [1, 4], [5, 2], [3, 6], [7, 3], [3, 7]], 2], [0, 2]),
  ('regression door symmetry #1', [6, [[1, 0], [0, 2], [3, 0], [4, 2], [3, 5]], 4], [5, 4]),
  ('partial repair boundary #1', [4, [[0, 1], [2, 0], [1, 3], [2, 3], [0, 3]], 0], [1, 1]),
  ('regression door symmetry #2', [3, [[1, 0], [2, 1]], 0], [2, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [1, [], 0], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('regression door symmetry #1', [7, [[0, 1], [3, 0], [4, 1], [5, 4], [6, 5], [4, 0]], 4], [3, 2]),
  ('fault site door symmetry #1', [3, [[0, 1], [2, 1], [0, 1]], 2], [0, 2]),
  ('regression door symmetry #2', [6, [[2, 1], [3, 1], [1, 5]], 3], [2, 2]),
  ('regression door symmetry #3', [5, [[2, 1], [4, 2]], 1], [4, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [8, [[1, 0], [1, 3], [3, 4], [4, 5], [0, 6], [7, 4], [3, 7]], 2], None)],
 [('door listed backwards #1', [2, [[1, 0]], 0], [1, 1]),
  ('fault site door symmetry #1', [4, [[0, 1], [0, 2], [0, 3], [1, 3], [2, 0]], 3], [2, 2]),
  ('regression door symmetry #1', [3, [[1, 0], [2, 1]], 0], [2, 2]),
  ('regression door symmetry #2', [4, [[1, 0], [2, 0], [3, 0]], 0], [1, 1]),
  ('regression door symmetry #3', [4, [[0, 2], [2, 1], [2, 0]], 1], [0, 2]),
  ('two leaves tie #1', [3, [[0, 2], [0, 1]], 0], [1, 1]),
  ('isolated start #1', [3, [[1, 2]], 0], None),
  ('control #1', [5, [[0, 1], [0, 2], [3, 0], [0, 3]], 4], None)]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Rooms behind doors listed backwards are never considered for the boss.

Rooms 0..n-1 joined by two-way doors [a, b]. The boss room is the reachable room (other than start) with the largest BFS door distance from start, ties to the lowest room id. Returns [room, distance] or None when no other room is reachable.

split: open-access


prompt:
The last discovered room becomes the boss even if close to start.

Rooms 0..n-1 joined by two-way doors [a, b]. The boss room is the reachable room (other than start) with the largest BFS door distance from start, ties to the lowest room id. Returns [room, distance] or None when no other room is reachable.

split: open-access


prompt:
Equal-distance candidates pick the wrong boss room.

Rooms 0..n-1 joined by two-way doors [a, b]. The boss room is the reachable room (other than start) with the largest BFS door distance from start, ties to the lowest room id. Returns [room, distance] or None when no other room is reachable.

split: open-access


prompt:
Isolated starts put the boss in the spawn room.

Rooms 0..n-1 joined by two-way doors [a, b]. The boss room is the reachable room (other than start) with the largest BFS door distance from start, ties to the lowest room id. Returns [room, distance] or None when no other room is reachable.

split: open-access


prompt:
Wall tops render as if the wall continued below.

For each '#' cell the mask sums N=1, E=2, S=4, W=8 for 4-neighbours that are '#' (row 0 is north). Out-of-bounds neighbours count as walls when same_oob. Non-wall cells get -1. Returns rows of integers.

split: open-access


prompt:
Floor cells receive the isolated-wall sprite.

For each '#' cell the mask sums N=1, E=2, S=4, W=8 for 4-neighbours that are '#' (row 0 is north). Out-of-bounds neighbours count as walls when same_oob. Non-wall cells get -1. Returns rows of integers.

split: open-access


prompt:
Wall corners use straight-wall sprites.

For each '#' cell the mask sums N=1, E=2, S=4, W=8 for 4-neighbours that are '#' (row 0 is north). Out-of-bounds neighbours count as walls when same_oob. Non-wall cells get -1. Returns rows of integers.

split: open-access


prompt:
Walls visually merge into doorways.

For each '#' cell the mask sums N=1, E=2, S=4, W=8 for 4-neighbours that are '#' (row 0 is north). Out-of-bounds neighbours count as walls when same_oob. Non-wall cells get -1. Returns rows of integers.

split: open-access


prompt:
Props cluster diagonally closer than the radius.

Candidates [x, y] (grid[y][x]) are tried in order. Accept when in bounds on '.', its quadrant (x*2//w, y*2//h) holds fewer than per_quadrant accepted props, and its squared Euclidean distance to every accepted prop is at least radius*radius. Returns accepted [x, y].

split: open-access


prompt:
Quotas are bypassed along the last column of odd-width maps.

Candidates [x, y] (grid[y][x]) are tried in order. Accept when in bounds on '.', its quadrant (x*2//w, y*2//h) holds fewer than per_quadrant accepted props, and its squared Euclidean distance to every accepted prop is at least radius*radius. Returns accepted [x, y].

split: open-access


prompt:
Each quadrant holds one more prop than configured.

Candidates [x, y] (grid[y][x]) are tried in order. Accept when in bounds on '.', its quadrant (x*2//w, y*2//h) holds fewer than per_quadrant accepted props, and its squared Euclidean distance to every accepted prop is at least radius*radius. Returns accepted [x, y].

split: open-access


prompt:
Quotas above one are ignored.

Candidates [x, y] (grid[y][x]) are tried in order. Accept when in bounds on '.', its quadrant (x*2//w, y*2//h) holds fewer than per_quadrant accepted props, and its squared Euclidean distance to every accepted prop is at least radius*radius. Returns accepted [x, y].

split: open-access


prompt:
Props appear inside walls on non-square maps.

Candidates [x, y] (grid[y][x]) are tried in order. Accept when in bounds on '.', its quadrant (x*2//w, y*2//h) holds fewer than per_quadrant accepted props, and its squared Euclidean distance to every accepted prop is at least radius*radius. Returns accepted [x, y].

split: open-access


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

N = 1
observations = []
def solve(heights, sea, mountain):
    h = len(heights)
    w = len(heights[0])
    out = []
    for r in range(h):
        row = []
        for c in range(w):
            total = 0
            cnt = 0
            for rr in range(max(0, r - 1), min(h, r + 2)):
                for cc in range(max(0, c - 1), min(w, c + 2)):
                    total += heights[rr][cc]
                    cnt += 1
            v = total // 9
            if v < sea:
                row.append('~')
            elif v < sea + 2:
                row.append('s')
            elif v < mountain:
                row.append('g')
            else:
                row.append('^')
        out.append(''.join(row))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #3', [[[9], [8]], 6, 6], ['^', '^']),
  ('control #1', [[[3], [4], [0]], 4, 10], ['~', '~', '~']),
  ('control #2', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~'])],
 [('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #3', [[[9], [8]], 6, 6], ['^', '^']),
  ('regression edge normalisation #4',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('control #1', [[[5, 3, 0, 8]], 6, 7], ['~~~~']),
  ('control #2', [[[4], [0]], 6, 11], ['~', '~'])],
 [('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('regression edge normalisation #1', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #2', [[[9], [8]], 6, 6], ['^', '^']),
  ('regression edge normalisation #3',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression edge normalisation #4', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('control #1', [[[3, 2], [6, 0], [0, 5]], 4, 7], ['~~', '~~', '~~']),
  ('control #2', [[[3], [0]], 5, 10], ['~', '~'])],
 [('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression edge normalisation #2', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('regression edge normalisation #3',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('regression edge normalisation #4', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('control #1', [[[1], [10], [0], [2]], 6, 10], ['~', '~', '~', '~']),
  ('control #2', [[[0]], 6, 9], ['~'])],
 [('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('fault site edge normalisation #1', [[[5, 5], [10, 3], [7, 0]], 2, 10], ['gg', 'gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('regression edge normalisation #3', [[[9, 7]], 2, 6], ['^^']),
  ('control #1', [[[1, 0]], 2, 8], ['~~']),
  ('control #2', [[[8], [2], [5], [2], [6]], 6, 8], ['~', '~', '~', '~', '~'])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(heights, sea, mountain):
    h = len(heights)
    w = len(heights[0])
    out = []
    for r in range(h):
        row = []
        for c in range(w):
            total = 0
            cnt = 0
            for rr in range(max(0, r - 1), min(h, r + 2)):
                for cc in range(max(0, c - 1), min(w, c + 2)):
                    total += heights[rr][cc]
                    cnt += 1
            v = total // (cnt + 1)
            if v < sea:
                row.append('~')
            elif v < sea + 2:
                row.append('s')
            elif v < mountain:
                row.append('g')
            else:
                row.append('^')
        out.append(''.join(row))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #3', [[[9], [8]], 6, 6], ['^', '^']),
  ('control #1', [[[3], [4], [0]], 4, 10], ['~', '~', '~']),
  ('control #2', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~'])],
 [('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #3', [[[9], [8]], 6, 6], ['^', '^']),
  ('regression edge normalisation #4',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('control #1', [[[5, 3, 0, 8]], 6, 7], ['~~~~']),
  ('control #2', [[[4], [0]], 6, 11], ['~', '~'])],
 [('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('regression edge normalisation #1', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression edge normalisation #2', [[[9], [8]], 6, 6], ['^', '^']),
  ('regression edge normalisation #3',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression edge normalisation #4', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('control #1', [[[3, 2], [6, 0], [0, 5]], 4, 7], ['~~', '~~', '~~']),
  ('control #2', [[[3], [0]], 5, 10], ['~', '~'])],
 [('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression edge normalisation #2', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('regression edge normalisation #3',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('regression edge normalisation #4', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('control #1', [[[1], [10], [0], [2]], 6, 10], ['~', '~', '~', '~']),
  ('control #2', [[[0]], 6, 9], ['~'])],
 [('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('regression edge normalisation #1',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('fault site edge normalisation #1', [[[5, 5], [10, 3], [7, 0]], 2, 10], ['gg', 'gg', 'gg']),
  ('regression edge normalisation #2', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('regression edge normalisation #3', [[[9, 7]], 2, 6], ['^^']),
  ('control #1', [[[1, 0]], 2, 8], ['~~']),
  ('control #2', [[[8], [2], [5], [2], [6]], 6, 8], ['~', '~', '~', '~', '~'])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Border cells are averaged as if missing neighbours were zero.

Each cell height becomes floor(mean) of the in-bounds cells in its 3x3 window (input values only). Class: '~' when v < sea, 's' beach when v < sea+2, 'g' when v < mountain, otherwise '^'. Returns strings per row.

split: open-access


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

N = 1
observations = []
def solve(heights, sea, mountain):
    h = len(heights)
    w = len(heights[0])
    out = []
    for r in range(h):
        row = []
        for c in range(w):
            total = 0
            cnt = 0
            for rr in range(max(0, r - 1), min(h, r + 2)):
                for cc in range(max(0, c - 1), min(w, c + 2)):
                    total += heights[rr][cc]
                    cnt += 1
            v = round(total / cnt)
            if v < sea:
                row.append('~')
            elif v < sea + 2:
                row.append('s')
            elif v < mountain:
                row.append('g')
            else:
                row.append('^')
        out.append(''.join(row))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression mean rounding #1', [[[3], [4], [0]], 4, 10], ['~', '~', '~']),
  ('regression mean rounding #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression mean rounding #3',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression mean rounding #4', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('control #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg'])],
 [('regression mean rounding #1',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression mean rounding #2', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('regression mean rounding #3', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~']),
  ('regression mean rounding #4',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('control #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('control #2', [[[9], [8]], 6, 6], ['^', '^'])],
 [('regression mean rounding #1', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~']),
  ('regression mean rounding #2',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('regression mean rounding #3',
   [[[2, 9, 4, 10, 11], [7, 7, 11, 1, 10], [11, 5, 12, 1, 12], [9, 4, 1, 0, 2]], 6, 8],
   ['ssss^', 'sss^s', 'ss~~~', 'ss~~~']),
  ('regression mean rounding #4', [[[0, 1], [3, 5], [10, 1]], 3, 10], ['~~', 'ss', 'ss']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('control #1', [[[9], [8]], 6, 6], ['^', '^']),
  ('control #2', [[[5, 5], [10, 3], [7, 0]], 2, 10], ['gg', 'gg', 'gg'])],
 [('regression mean rounding #1',
   [[[2, 9, 4, 10, 11], [7, 7, 11, 1, 10], [11, 5, 12, 1, 12], [9, 4, 1, 0, 2]], 6, 8],
   ['ssss^', 'sss^s', 'ss~~~', 'ss~~~']),
  ('regression mean rounding #2', [[[0, 1], [3, 5], [10, 1]], 3, 10], ['~~', 'ss', 'ss']),
  ('regression mean rounding #3',
   [[[1, 2, 0, 4], [12, 1, 9, 7], [9, 3, 6, 5]], 2, 11],
   ['ggsg', 'gggg', 'gggg']),
  ('partial repair boundary #1',
   [[[0, 3], [6, 9], [0, 3], [3, 12], [7, 10]], 5, 6],
   ['~~', '~~', 'ss', 'ss', '^^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('control #1', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('control #2', [[[9, 7]], 2, 6], ['^^'])],
 [('regression mean rounding #1',
   [[[1, 2, 0, 4], [12, 1, 9, 7], [9, 3, 6, 5]], 2, 11],
   ['ggsg', 'gggg', 'gggg']),
  ('regression mean rounding #2',
   [[[4, 3, 3, 1], [4, 1, 10, 9], [2, 2, 10, 5], [0, 0, 7, 2]], 6, 8],
   ['~~~~', '~~~s', '~~~s', '~~~s']),
  ('partial repair boundary #1',
   [[[0, 3], [6, 9], [0, 3], [3, 12], [7, 10]], 5, 6],
   ['~~', '~~', 'ss', 'ss', '^^']),
  ('regression mean rounding #3',
   [[[10, 1, 2, 12, 9], [8, 10, 5, 4, 8], [4, 3, 4, 4, 8], [2, 5, 12, 8, 7]], 5, 7],
   ['^sss^', 'ssss^', 'sssss', '~ss^s']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('control #1', [[[1, 2, 10]], 6, 9], ['~~s']),
  ('control #2', [[[11, 0, 4, 12]], 2, 7], ['ggg^'])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(heights, sea, mountain):
    h = len(heights)
    w = len(heights[0])
    out = []
    for r in range(h):
        row = []
        for c in range(w):
            total = 0
            cnt = 0
            for rr in range(max(0, r - 1), min(h, r + 2)):
                for cc in range(max(0, c - 1), min(w, c + 2)):
                    total += heights[rr][cc]
                    cnt += 1
            v = -(-total // cnt)
            if v < sea:
                row.append('~')
            elif v < sea + 2:
                row.append('s')
            elif v < mountain:
                row.append('g')
            else:
                row.append('^')
        out.append(''.join(row))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression mean rounding #1', [[[3], [4], [0]], 4, 10], ['~', '~', '~']),
  ('regression mean rounding #2', [[[10, 11, 6, 11, 0], [9, 0, 9, 4, 4]], 5, 7], ['^^ss~', '^^ss~']),
  ('regression mean rounding #3',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression mean rounding #4', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('control #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg'])],
 [('regression mean rounding #1',
   [[[5, 4, 2, 6, 4], [12, 10, 8, 2, 4], [4, 10, 11, 2, 6]], 2, 8],
   ['ggggg', 'ggggg', '^^ggs']),
  ('regression mean rounding #2', [[[6], [4], [8], [4], [8]], 5, 9], ['s', 's', 's', 's', 's']),
  ('regression mean rounding #3', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~']),
  ('regression mean rounding #4',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('control #1', [[[0, 9], [7, 2]], 2, 11], ['gg', 'gg']),
  ('control #2', [[[9], [8]], 6, 6], ['^', '^'])],
 [('regression mean rounding #1', [[[9, 5, 6], [9, 0, 4]], 6, 10], ['~~~', '~~~']),
  ('regression mean rounding #2',
   [[[8, 6, 12, 10, 8], [6, 1, 1, 7, 5], [1, 6, 12, 6, 0], [3, 8, 3, 6, 0], [1, 7, 3, 2, 0]], 6, 9],
   ['~~sss', '~~sss', '~~~~~', '~~~~~', '~~~~~']),
  ('regression mean rounding #3',
   [[[2, 9, 4, 10, 11], [7, 7, 11, 1, 10], [11, 5, 12, 1, 12], [9, 4, 1, 0, 2]], 6, 8],
   ['ssss^', 'sss^s', 'ss~~~', 'ss~~~']),
  ('regression mean rounding #4', [[[0, 1], [3, 5], [10, 1]], 3, 10], ['~~', 'ss', 'ss']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('control #1', [[[9], [8]], 6, 6], ['^', '^']),
  ('control #2', [[[5, 5], [10, 3], [7, 0]], 2, 10], ['gg', 'gg', 'gg'])],
 [('regression mean rounding #1',
   [[[2, 9, 4, 10, 11], [7, 7, 11, 1, 10], [11, 5, 12, 1, 12], [9, 4, 1, 0, 2]], 6, 8],
   ['ssss^', 'sss^s', 'ss~~~', 'ss~~~']),
  ('regression mean rounding #2', [[[0, 1], [3, 5], [10, 1]], 3, 10], ['~~', 'ss', 'ss']),
  ('regression mean rounding #3',
   [[[1, 2, 0, 4], [12, 1, 9, 7], [9, 3, 6, 5]], 2, 11],
   ['ggsg', 'gggg', 'gggg']),
  ('partial repair boundary #1',
   [[[0, 3], [6, 9], [0, 3], [3, 12], [7, 10]], 5, 6],
   ['~~', '~~', 'ss', 'ss', '^^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('beach band edge #1', [[[5]], 3, 9], ['g']),
  ('control #1', [[[10, 11], [1, 0]], 3, 9], ['gg', 'gg']),
  ('control #2', [[[9, 7]], 2, 6], ['^^'])],
 [('regression mean rounding #1',
   [[[1, 2, 0, 4], [12, 1, 9, 7], [9, 3, 6, 5]], 2, 11],
   ['ggsg', 'gggg', 'gggg']),
  ('regression mean rounding #2',
   [[[4, 3, 3, 1], [4, 1, 10, 9], [2, 2, 10, 5], [0, 0, 7, 2]], 6, 8],
   ['~~~~', '~~~s', '~~~s', '~~~s']),
  ('partial repair boundary #1',
   [[[0, 3], [6, 9], [0, 3], [3, 12], [7, 10]], 5, 6],
   ['~~', '~~', 'ss', 'ss', '^^']),
  ('regression mean rounding #3',
   [[[10, 1, 2, 12, 9], [8, 10, 5, 4, 8], [4, 3, 4, 4, 8], [2, 5, 12, 8, 7]], 5, 7],
   ['^sss^', 'ssss^', 'sssss', '~ss^s']),
  ('single row #1', [[[0, 12, 0]], 3, 6], ['^s^']),
  ('corner cell average #1', [[[9, 9], [9, 0]], 3, 8], ['gg', 'gg']),
  ('control #1', [[[1, 2, 10]], 6, 9], ['~~s']),
  ('control #2', [[[11, 0, 4, 12]], 2, 7], ['ggg^'])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Coastlines shift inland compared to the floor rule.

Each cell height becomes floor(mean) of the in-bounds cells in its 3x3 window (input values only). Class: '~' when v < sea, 's' beach when v < sea+2, 'g' when v < mountain, otherwise '^'. Returns strings per row.

split: open-access


prompt:
Smoothing is biased toward northern neighbours.

Each cell height becomes floor(mean) of the in-bounds cells in its 3x3 window (input values only). Class: '~' when v < sea, 's' beach when v < sea+2, 'g' when v < mountain, otherwise '^'. Returns strings per row.

split: open-access


prompt:
The first column is smoothed with values from the opposite side.

Each cell height becomes floor(mean) of the in-bounds cells in its 3x3 window (input values only). Class: '~' when v < sea, 's' beach when v < sea+2, 'g' when v < mountain, otherwise '^'. Returns strings per row.

split: open-access


prompt:
Grassland at sea+2 is classed as beach.

Each cell height becomes floor(mean) of the in-bounds cells in its 3x3 window (input values only). Class: '~' when v < sea, 's' beach when v < sea+2, 'g' when v < mountain, otherwise '^'. Returns strings per row.

split: open-access


prompt:
Rotated prefabs appear mirrored.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


prompt:
Counter-clockwise requests leave prefabs unrotated.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


prompt:
Prefab holes erase existing walls.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


prompt:
Non-square prefabs land rotated a quarter turn.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


prompt:
Quest-critical locked tiles get replaced by prefabs.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


prompt:
A failed placement leaves half a prefab in the level.

The prefab (rows of chars, ' ' transparent) is rotated clockwise rot times (rot taken mod 4, negative allowed) and stamped with its top-left at column ox, row oy. If any non-transparent tile would land out of bounds or on a locked 'X' tile, the stamp is rejected and the original grid returned with False; otherwise the new grid with True.

split: open-access


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

N = 1
observations = []
def solve(length, encounters, min_gap, rest_every):
    out = []
    last = 0
    for pos in encounters:
        if pos < 1 or pos > length - 2:
            continue
        if rest_every and pos % rest_every == 0:
            continue
        anchor = last
        if rest_every:
            anchor = max(anchor, pos // rest_every * rest_every)
        if pos - anchor < min_gap:
            continue
        out.append(pos)
        last = pos
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1',
   [27, [20, 6, 10, 15, 26, -2, 12, 27, -1], 0, 0],
   [6, 10, 12, 15, 20]),
  ('fault site proposal normalisation #2', [14, [4, 9, 16, 9, 16, 7, 8, 16, 0, 13], 1, 5], [4, 7, 8, 9]),
  ('regression proposal normalisation #1', [4, [1, -2, 1], 0, 7], [1]),
  ('regression proposal normalisation #2', [19, [6, 20, 0, 10, 4, 6, 2, 14, 9], 0, 7], [2, 4, 6, 9, 10]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [14, [4, 9, 16, 9, 16, 7, 8, 16, 0, 13], 1, 5], [4, 7, 8, 9]),
  ('fault site proposal normalisation #2', [40, [41, 39, 8, 9, 9, 32, 18, 41], 5, 0], [8, 18, 32]),
  ('regression proposal normalisation #1', [19, [6, 20, 0, 10, 4, 6, 2, 14, 9], 0, 7], [2, 4, 6, 9, 10]),
  ('regression proposal normalisation #2', [20, [16, 11, 18, 18, -2, 4, 21, 19, 21], 0, 0], [4, 11, 16, 18]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [39, [34, 15, 35, 19, 4], 2, 4], [15, 19, 34]),
  ('fault site proposal normalisation #2', [37, [27, 33, 11, 14, 7], 0, 7], [11, 27, 33]),
  ('regression proposal normalisation #1', [30, [4, 23, 32, 22, 22, -1, 9, 2], 0, 0], [2, 4, 9, 22, 23]),
  ('regression proposal normalisation #2', [39, [36, 36, 16, 30, 0, 39, 8], 0, 5], [8, 16, 36]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('regression proposal normalisation #1', [4, [1, -2, 1], 0, 7], [1]),
  ('fault site proposal normalisation #1', [38, [27, 16, 11, 3], 0, 7], [3, 11, 16, 27]),
  ('partial repair boundary #1', [22, [23, 22, 5, 11, 5], 0, 0], [5, 11]),
  ('partial repair boundary #2', [14, [1, 12, 0, 1], 0, 0], [1, 12]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [34, [-1, 30, 25, 20, 1, 11, 0], 5, 4], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [36, [32, 33, 13], 2, 0], [13, 32]),
  ('fault site proposal normalisation #2', [29, [-2, 26, 19], 3, 0], [19, 26]),
  ('regression proposal normalisation #1', [15, [2, 8, 8, 11], 0, 5], [2, 8, 11]),
  ('regression proposal normalisation #2', [30, [17, 13, 17, -2, -2, 9, 32, 23], 0, 7], [9, 13, 17, 23]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [40, [3, 4], 3, 0], [3])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(length, encounters, min_gap, rest_every):
    out = []
    last = 0
    for pos in sorted(encounters):
        if pos < 1 or pos > length - 2:
            continue
        if rest_every and pos % rest_every == 0:
            continue
        anchor = last
        if rest_every:
            anchor = max(anchor, pos // rest_every * rest_every)
        if pos - anchor < min_gap:
            continue
        out.append(pos)
        last = pos
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1',
   [27, [20, 6, 10, 15, 26, -2, 12, 27, -1], 0, 0],
   [6, 10, 12, 15, 20]),
  ('fault site proposal normalisation #2', [14, [4, 9, 16, 9, 16, 7, 8, 16, 0, 13], 1, 5], [4, 7, 8, 9]),
  ('regression proposal normalisation #1', [4, [1, -2, 1], 0, 7], [1]),
  ('regression proposal normalisation #2', [19, [6, 20, 0, 10, 4, 6, 2, 14, 9], 0, 7], [2, 4, 6, 9, 10]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [14, [4, 9, 16, 9, 16, 7, 8, 16, 0, 13], 1, 5], [4, 7, 8, 9]),
  ('fault site proposal normalisation #2', [40, [41, 39, 8, 9, 9, 32, 18, 41], 5, 0], [8, 18, 32]),
  ('regression proposal normalisation #1', [19, [6, 20, 0, 10, 4, 6, 2, 14, 9], 0, 7], [2, 4, 6, 9, 10]),
  ('regression proposal normalisation #2', [20, [16, 11, 18, 18, -2, 4, 21, 19, 21], 0, 0], [4, 11, 16, 18]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [39, [34, 15, 35, 19, 4], 2, 4], [15, 19, 34]),
  ('fault site proposal normalisation #2', [37, [27, 33, 11, 14, 7], 0, 7], [11, 27, 33]),
  ('regression proposal normalisation #1', [30, [4, 23, 32, 22, 22, -1, 9, 2], 0, 0], [2, 4, 9, 22, 23]),
  ('regression proposal normalisation #2', [39, [36, 36, 16, 30, 0, 39, 8], 0, 5], [8, 16, 36]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [21, [-2, 16], 2, 5], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('regression proposal normalisation #1', [4, [1, -2, 1], 0, 7], [1]),
  ('fault site proposal normalisation #1', [38, [27, 16, 11, 3], 0, 7], [3, 11, 16, 27]),
  ('partial repair boundary #1', [22, [23, 22, 5, 11, 5], 0, 0], [5, 11]),
  ('partial repair boundary #2', [14, [1, 12, 0, 1], 0, 0], [1, 12]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [34, [-1, 30, 25, 20, 1, 11, 0], 5, 4], [])],
 [('duplicate proposals #1', [10, [3, 3, 4], 0, 0], [3, 4]),
  ('fault site proposal normalisation #1', [36, [32, 33, 13], 2, 0], [13, 32]),
  ('fault site proposal normalisation #2', [29, [-2, 26, 19], 3, 0], [19, 26]),
  ('regression proposal normalisation #1', [15, [2, 8, 8, 11], 0, 5], [2, 8, 11]),
  ('regression proposal normalisation #2', [30, [17, 13, 17, -2, -2, 9, 32, 23], 0, 7], [9, 13, 17, 23]),
  ('last legal tile #1', [10, [8, 9], 1, 0], [8]),
  ('checkpoint resets gap #1', [20, [2, 6, 7], 2, 5], [2, 7]),
  ('control #1', [40, [3, 4], 3, 0], [3])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Gaps are checked against later positions, spacing encounters backwards.

Proposed positions are deduplicated and taken ascending. A position is legal when 1 <= pos <= length-2, is not a rest checkpoint (pos % rest_every == 0 when rest_every > 0), and lies at least min_gap after the anchor: the later of the last accepted encounter (initially the start, 0) and the last checkpoint at or before pos. Returns accepted positions.

split: open-access