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

N = 1
observations = []
def solve(domains, rules):
    dom = [list(d) for d in domains]
    changed = True
    while changed:
        changed = False
        for i in range(len(dom)):
            keep = []
            for t in dom[i]:
                ok_left = i == 0 or any(t in rules.get(l, []) for l in dom[i - 1])
                ok_right = i == len(dom) - 1 or any(r in rules.get(t, []) for r in dom[i + 1])
                if ok_left and ok_right:
                    keep.append(t)
            if keep != dom[i]:
                dom[i] = keep
                changed = True
    return {'domains': dom, 'contradiction': any(not d for d in dom)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['hill', 'grass', 'sand', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression domain normalisation #2',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill', 'sea'],
     ['sand', 'grass'],
     ['sea', 'hill', 'grass', 'sand']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'sand'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['grass', 'hill', 'sand', 'sea', 'sand'],
     ['sea', 'grass', 'hill', 'sand', 'hill'],
     ['sea', 'grass', 'hill', 'sand']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('regression domain normalisation #3',
   [[['sand', 'sea', 'grass'], ['sand', 'sea', 'grass'], ['hill', 'sand', 'grass', 'hill']],
    {'sea': ['grass', 'hill', 'sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand']}],
   {'domains': [['grass', 'sand', 'sea'], ['grass', 'sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sea', 'hill']],
    {'sea': ['hill'], 'sand': ['grass', 'sand', 'sea'], 'grass': ['sea'], 'hill': ['grass', 'hill']}],
   {'domains': [['hill', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['sea', 'sand', 'grass'],
     ['sea', 'sand', 'hill', 'grass'],
     ['sea', 'grass', 'hill', 'sand', 'sand'],
     ['hill', 'sand', 'sea', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('regression domain normalisation #3',
   [[['grass', 'sand'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sea', 'grass', 'sand', 'hill'],
     ['sea', 'grass', 'hill', 'sand', 'grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sand'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sea', 'grass', 'sand']],
    {'sea': ['hill'], 'sand': ['sea'], 'grass': ['grass', 'sand', 'sea'], 'hill': ['hill']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['hill', 'sea', 'grass', 'sand'], ['sea', 'grass', 'sand']],
    {'sea': ['hill', 'sand'], 'sand': ['grass', 'hill', 'sand'], 'grass': ['grass'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['grass', 'sand', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['sea', 'sea']],
    {'sea': ['grass', 'hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill'],
     'hill': ['grass', 'sand']}],
   {'domains': [['sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['hill', 'hill'], ['grass', 'sea', 'hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['sand']],
    {'sea': ['sea'],
     'sand': ['hill', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['sand']], 'contradiction': False})]]
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(domains, rules):
    dom = [sorted(d) for d in domains]
    changed = True
    while changed:
        changed = False
        for i in range(len(dom)):
            keep = []
            for t in dom[i]:
                ok_left = i == 0 or any(t in rules.get(l, []) for l in dom[i - 1])
                ok_right = i == len(dom) - 1 or any(r in rules.get(t, []) for r in dom[i + 1])
                if ok_left and ok_right:
                    keep.append(t)
            if keep != dom[i]:
                dom[i] = keep
                changed = True
    return {'domains': dom, 'contradiction': any(not d for d in dom)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['hill', 'grass', 'sand', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression domain normalisation #2',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill', 'sea'],
     ['sand', 'grass'],
     ['sea', 'hill', 'grass', 'sand']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'sand'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['grass', 'hill', 'sand', 'sea', 'sand'],
     ['sea', 'grass', 'hill', 'sand', 'hill'],
     ['sea', 'grass', 'hill', 'sand']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('regression domain normalisation #3',
   [[['sand', 'sea', 'grass'], ['sand', 'sea', 'grass'], ['hill', 'sand', 'grass', 'hill']],
    {'sea': ['grass', 'hill', 'sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand']}],
   {'domains': [['grass', 'sand', 'sea'], ['grass', 'sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['hill', 'hill'], ['grass'], ['grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass'], ['grass']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sea', 'hill']],
    {'sea': ['hill'], 'sand': ['grass', 'sand', 'sea'], 'grass': ['sea'], 'hill': ['grass', 'hill']}],
   {'domains': [['hill', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['sea', 'sand', 'grass'],
     ['sea', 'sand', 'hill', 'grass'],
     ['sea', 'grass', 'hill', 'sand', 'sand'],
     ['hill', 'sand', 'sea', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('regression domain normalisation #3',
   [[['grass', 'sand'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sea', 'grass', 'sand', 'hill'],
     ['sea', 'grass', 'hill', 'sand', 'grass']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sand'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea'],
                ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea']], 'contradiction': False})],
 [('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('fault site domain normalisation #1',
   [[['sea', 'grass', 'sand']],
    {'sea': ['hill'], 'sand': ['sea'], 'grass': ['grass', 'sand', 'sea'], 'hill': ['hill']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('fault site domain normalisation #2',
   [[['hill', 'sea', 'grass', 'sand'], ['sea', 'grass', 'sand']],
    {'sea': ['hill', 'sand'], 'sand': ['grass', 'hill', 'sand'], 'grass': ['grass'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['grass', 'sand', 'sea']], 'contradiction': False}),
  ('regression domain normalisation #1',
   [[['sea', 'sea']],
    {'sea': ['grass', 'hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill'],
     'hill': ['grass', 'sand']}],
   {'domains': [['sea']], 'contradiction': False}),
  ('regression domain normalisation #2',
   [[['hill', 'hill'], ['grass', 'sea', 'hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['hill'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('control #1',
   [[['sand']],
    {'sea': ['sea'],
     'sand': ['hill', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['sand']], 'contradiction': False})]]
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:
Duplicate tiles skew weighted collapse later.

A 1D strip of cells, each with a domain of tiles; rules[t] lists tiles allowed immediately to the right of t. Repeatedly remove tile t from cell i unless (i is first or some tile l in cell i-1 allows t on its right) and (i is last or t allows some tile in cell i+1), until stable. Domains are returned as sorted unique lists with a contradiction flag (any empty domain).

split: open-access


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

N = 1
observations = []
def solve(domains, rules):
    dom = [sorted(set(d)) for d in domains]
    changed = True
    while changed:
        changed = False
        for i in range(len(dom)):
            keep = []
            for t in dom[i]:
                ok_left = i == 0 or any(t in rules.get(l, []) for l in dom[i - 1])
                ok_right = i == len(dom) - 1 or any(r in rules.get(t, []) for r in dom[i + 1])
                if ok_left or ok_right:
                    keep.append(t)
            if keep != dom[i]:
                dom[i] = keep
                changed = True
    return {'domains': dom, 'contradiction': any(not d for d in dom)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('fault site support conjunction #1',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea']], 'contradiction': False})],
 [('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('fault site support conjunction #1',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #3',
   [[['sea', 'sand'], ['hill'], ['sand', 'sea'], ['sea', 'grass', 'hill']],
    {'sea': ['sand'], 'sand': ['grass', 'sand'], 'grass': ['sea'], 'hill': ['grass']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('regression support conjunction #1',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #2',
   [[['sea', 'sand'], ['hill'], ['sand', 'sea'], ['sea', 'grass', 'hill']],
    {'sea': ['sand'], 'sand': ['grass', 'sand'], 'grass': ['sea'], 'hill': ['grass']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('regression support conjunction #3',
   [[['sea', 'hill', 'grass', 'sand'],
     ['grass', 'sand', 'hill', 'sea'],
     ['hill'],
     ['sea', 'sand', 'sand'],
     ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #4',
   [[['sea', 'hill'], ['sea', 'hill', 'grass'], ['sea', 'sand', 'grass', 'hill']],
    {'sea': ['sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['hill', 'sand', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['hill'], ['grass', 'hill', 'sea'], ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['sand']],
    {'sea': ['sea'],
     'sand': ['hill', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['sand']], 'contradiction': False})],
 [('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('fault site support conjunction #1',
   [[['grass'], ['grass', 'sea', 'sand', 'hill']],
    {'sea': ['grass', 'sand', 'sea'],
     'sand': ['grass', 'sand'],
     'grass': ['grass', 'hill'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass'], ['grass', 'hill']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['sea', 'hill', 'grass', 'sand'],
     ['grass', 'sand', 'hill', 'sea'],
     ['hill'],
     ['sea', 'sand', 'sand'],
     ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #2',
   [[['hill', 'grass', 'sea'], ['grass']],
    {'sea': ['grass', 'sand', 'sea'], 'sand': ['grass', 'sea'], 'grass': ['sea'], 'hill': ['sand', 'sea']}],
   {'domains': [['sea'], ['grass']], 'contradiction': False}),
  ('regression support conjunction #3',
   [[['hill', 'grass', 'sand'],
     ['sand', 'sea'],
     ['sand', 'sea', 'grass', 'hill'],
     ['sea'],
     ['grass', 'sea', 'hill']],
    {'sea': ['grass'], 'sand': ['grass', 'sand'], 'grass': ['grass', 'hill', 'sea'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass'], ['sea'], ['grass']],
    'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['hill', 'grass', 'sand', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea']], 'contradiction': False})],
 [('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('regression support conjunction #1',
   [[['sea', 'hill'], ['sea', 'hill', 'grass'], ['sea', 'sand', 'grass', 'hill']],
    {'sea': ['sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['hill', 'sand', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['hill'], ['grass', 'hill', 'sea'], ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('fault site support conjunction #1',
   [[['hill', 'grass', 'sand', 'sea'],
     ['sea', 'sand', 'hill', 'grass'],
     ['sand', 'sea', 'grass', 'hill', 'sea']],
    {'sea': ['sand'], 'sand': ['hill', 'sand'], 'grass': ['sand', 'sea'], 'hill': ['sand']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['hill', 'sand', 'sea'], ['hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['sand', 'sea', 'hill', 'grass'],
     ['hill', 'sea', 'grass', 'sand'],
     ['grass', 'sand', 'sea'],
     ['grass', 'sea', 'grass'],
     ['grass', 'hill', 'sea']],
    {'sea': ['hill'], 'sand': ['hill', 'sand'], 'grass': ['hill'], 'hill': ['hill']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #3',
   [[['sea'], ['sand', 'sea'], ['hill', 'sand', 'sea'], ['sea', 'hill', 'sea']],
    {'sea': ['grass', 'hill'], 'sand': ['hill'], 'grass': ['hill', 'sea'], 'hill': ['sand', 'sea']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['sea', 'grass', 'sand']],
    {'sea': ['hill'], 'sand': ['sea'], 'grass': ['grass', 'sand', 'sea'], 'hill': ['hill']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['hill', 'sea', 'grass', 'sand'], ['sea', 'grass', 'sand']],
    {'sea': ['hill', 'sand'], 'sand': ['grass', 'hill', 'sand'], 'grass': ['grass'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['grass', 'sand', 'sea']], 'contradiction': False})]]
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(domains, rules):
    dom = [sorted(set(d)) for d in domains]
    changed = True
    while changed:
        changed = False
        for i in range(len(dom)):
            keep = []
            for t in dom[i]:
                ok_left = i == 0 or any(t in rules.get(l, []) for l in dom[i - 1])
                ok_right = i == len(dom) - 1 or any(r in rules.get(t, []) for r in dom[i + 1])
                if ok_left:
                    keep.append(t)
            if keep != dom[i]:
                dom[i] = keep
                changed = True
    return {'domains': dom, 'contradiction': any(not d for d in dom)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('fault site support conjunction #1',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'sea']], 'contradiction': False})],
 [('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('fault site support conjunction #1',
   [[['hill'], ['sand', 'hill'], ['sea'], ['grass', 'sand', 'sea', 'hill'], ['sea']],
    {'sea': ['hill', 'sea'],
     'sand': ['grass', 'hill', 'sea'],
     'grass': ['hill', 'sea'],
     'hill': ['sand', 'sea']}],
   {'domains': [['hill'], ['sand'], ['sea'], ['hill', 'sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['hill', 'sea', 'grass', 'sea'],
     ['sea', 'sand', 'grass', 'hill'],
     ['sand', 'sea'],
     ['sand', 'hill', 'sea', 'grass']],
    {'sea': ['grass', 'hill'], 'sand': ['hill', 'sand'], 'grass': ['sea'], 'hill': ['sand']}],
   {'domains': [['hill', 'sea'], ['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass', 'hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #3',
   [[['sea', 'sand'], ['hill'], ['sand', 'sea'], ['sea', 'grass', 'hill']],
    {'sea': ['sand'], 'sand': ['grass', 'sand'], 'grass': ['sea'], 'hill': ['grass']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['grass', 'sand', 'sea']],
    {'sea': ['grass', 'sand'], 'sand': ['hill'], 'grass': ['hill'], 'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False})],
 [('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('regression support conjunction #1',
   [[['hill', 'sea'], ['sea', 'hill', 'sand'], ['hill', 'sea'], ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['sea'], ['sand', 'sea'], ['sea'], ['sea']], 'contradiction': False}),
  ('regression support conjunction #2',
   [[['sea', 'sand'], ['hill'], ['sand', 'sea'], ['sea', 'grass', 'hill']],
    {'sea': ['sand'], 'sand': ['grass', 'sand'], 'grass': ['sea'], 'hill': ['grass']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('regression support conjunction #3',
   [[['sea', 'hill', 'grass', 'sand'],
     ['grass', 'sand', 'hill', 'sea'],
     ['hill'],
     ['sea', 'sand', 'sand'],
     ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #4',
   [[['sea', 'hill'], ['sea', 'hill', 'grass'], ['sea', 'sand', 'grass', 'hill']],
    {'sea': ['sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['hill', 'sand', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['hill'], ['grass', 'hill', 'sea'], ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['sand', 'hill', 'sea']],
    {'sea': ['sand', 'sea'],
     'sand': ['grass', 'hill'],
     'grass': ['grass', 'hill', 'sand'],
     'hill': ['hill', 'sand', 'sea']}],
   {'domains': [['hill', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['sand']],
    {'sea': ['sea'],
     'sand': ['hill', 'sand', 'sea'],
     'grass': ['grass', 'hill', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['sand']], 'contradiction': False})],
 [('asymmetric rule #1',
   [[['sand'], ['hill', 'grass']], {'sand': ['grass'], 'grass': ['sand'], 'hill': ['sand']}],
   {'domains': [['sand'], ['grass']], 'contradiction': False}),
  ('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('fault site support conjunction #1',
   [[['grass'], ['grass', 'sea', 'sand', 'hill']],
    {'sea': ['grass', 'sand', 'sea'],
     'sand': ['grass', 'sand'],
     'grass': ['grass', 'hill'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['grass'], ['grass', 'hill']], 'contradiction': False}),
  ('regression support conjunction #1',
   [[['sea', 'hill', 'grass', 'sand'],
     ['grass', 'sand', 'hill', 'sea'],
     ['hill'],
     ['sea', 'sand', 'sand'],
     ['hill', 'grass', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #2',
   [[['hill', 'grass', 'sea'], ['grass']],
    {'sea': ['grass', 'sand', 'sea'], 'sand': ['grass', 'sea'], 'grass': ['sea'], 'hill': ['sand', 'sea']}],
   {'domains': [['sea'], ['grass']], 'contradiction': False}),
  ('regression support conjunction #3',
   [[['hill', 'grass', 'sand'],
     ['sand', 'sea'],
     ['sand', 'sea', 'grass', 'hill'],
     ['sea'],
     ['grass', 'sea', 'hill']],
    {'sea': ['grass'], 'sand': ['grass', 'sand'], 'grass': ['grass', 'hill', 'sea'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand'], ['sand', 'sea'], ['grass'], ['sea'], ['grass']],
    'contradiction': False}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['hill', 'grass', 'sand', 'sea']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [['grass', 'hill', 'sand', 'sea']], 'contradiction': False})],
 [('coast gradient #1',
   [[['sea'], ['sea', 'sand', 'grass', 'hill'], ['hill']],
    {'sea': ['sea', 'sand'],
     'sand': ['sea', 'sand', 'grass'],
     'grass': ['sand', 'grass', 'hill'],
     'hill': ['grass']}],
   {'domains': [[], [], []], 'contradiction': True}),
  ('regression support conjunction #1',
   [[['sea', 'hill'], ['sea', 'hill', 'grass'], ['sea', 'sand', 'grass', 'hill']],
    {'sea': ['sand'],
     'sand': ['grass', 'sand', 'sea'],
     'grass': ['hill', 'sand', 'sea'],
     'hill': ['grass', 'hill', 'sea']}],
   {'domains': [['hill'], ['grass', 'hill', 'sea'], ['grass', 'hill', 'sand', 'sea']],
    'contradiction': False}),
  ('fault site support conjunction #1',
   [[['hill', 'grass', 'sand', 'sea'],
     ['sea', 'sand', 'hill', 'grass'],
     ['sand', 'sea', 'grass', 'hill', 'sea']],
    {'sea': ['sand'], 'sand': ['hill', 'sand'], 'grass': ['sand', 'sea'], 'hill': ['sand']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['hill', 'sand', 'sea'], ['hill', 'sand']],
    'contradiction': False}),
  ('regression support conjunction #2',
   [[['sand', 'sea', 'hill', 'grass'],
     ['hill', 'sea', 'grass', 'sand'],
     ['grass', 'sand', 'sea'],
     ['grass', 'sea', 'grass'],
     ['grass', 'hill', 'sea']],
    {'sea': ['hill'], 'sand': ['hill', 'sand'], 'grass': ['hill'], 'hill': ['hill']}],
   {'domains': [[], [], [], [], []], 'contradiction': True}),
  ('regression support conjunction #3',
   [[['sea'], ['sand', 'sea'], ['hill', 'sand', 'sea'], ['sea', 'hill', 'sea']],
    {'sea': ['grass', 'hill'], 'sand': ['hill'], 'grass': ['hill', 'sea'], 'hill': ['sand', 'sea']}],
   {'domains': [[], [], [], []], 'contradiction': True}),
  ('duplicate domain entries #1',
   [[['grass', 'grass', 'sand']], {'grass': []}],
   {'domains': [['grass', 'sand']], 'contradiction': False}),
  ('control #1',
   [[['sea', 'grass', 'sand']],
    {'sea': ['hill'], 'sand': ['sea'], 'grass': ['grass', 'sand', 'sea'], 'hill': ['hill']}],
   {'domains': [['grass', 'sand', 'sea']], 'contradiction': False}),
  ('control #2',
   [[['hill', 'sea', 'grass', 'sand'], ['sea', 'grass', 'sand']],
    {'sea': ['hill', 'sand'], 'sand': ['grass', 'hill', 'sand'], 'grass': ['grass'], 'hill': ['sea']}],
   {'domains': [['grass', 'hill', 'sand', 'sea'], ['grass', 'sand', 'sea']], 'contradiction': False})]]
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:
Tiles unsupported on one side survive propagation.

A 1D strip of cells, each with a domain of tiles; rules[t] lists tiles allowed immediately to the right of t. Repeatedly remove tile t from cell i unless (i is first or some tile l in cell i-1 allows t on its right) and (i is last or t allows some tile in cell i+1), until stable. Domains are returned as sorted unique lists with a contradiction flag (any empty domain).

split: open-access


prompt:
Terrain at chunk -1 repeats chunk 1.

Coordinates are zigzag encoded (v >= 0 -> 2v, v < 0 -> -2v-1). seed = (world_seed*1000003 mod 2^32) xor (zz(cx)*73856093 mod 2^32) xor (zz(cy)*19349663 mod 2^32). The generator state is seed, or 1 when seed is 0, advanced by three 32-bit xorshift rounds (<<13, >>17, <<5, each left shift masked to 32 bits). Returns [seed, state % 100].

split: open-access


prompt:
Chunk (3, 5) and (5, 3) generate identical terrain.

Coordinates are zigzag encoded (v >= 0 -> 2v, v < 0 -> -2v-1). seed = (world_seed*1000003 mod 2^32) xor (zz(cx)*73856093 mod 2^32) xor (zz(cy)*19349663 mod 2^32). The generator state is seed, or 1 when seed is 0, advanced by three 32-bit xorshift rounds (<<13, >>17, <<5, each left shift masked to 32 bits). Returns [seed, state % 100].

split: open-access


prompt:
The origin chunk rolls the same value forever.

Coordinates are zigzag encoded (v >= 0 -> 2v, v < 0 -> -2v-1). seed = (world_seed*1000003 mod 2^32) xor (zz(cx)*73856093 mod 2^32) xor (zz(cy)*19349663 mod 2^32). The generator state is seed, or 1 when seed is 0, advanced by three 32-bit xorshift rounds (<<13, >>17, <<5, each left shift masked to 32 bits). Returns [seed, state % 100].

split: open-access


prompt:
Chunk contents differ between 32-bit and arbitrary-precision builds.

Coordinates are zigzag encoded (v >= 0 -> 2v, v < 0 -> -2v-1). seed = (world_seed*1000003 mod 2^32) xor (zz(cx)*73856093 mod 2^32) xor (zz(cy)*19349663 mod 2^32). The generator state is seed, or 1 when seed is 0, advanced by three 32-bit xorshift rounds (<<13, >>17, <<5, each left shift masked to 32 bits). Returns [seed, state % 100].

split: open-access


prompt:
Seeds above 32 bits produce different chunk ids than the save format stores.

Coordinates are zigzag encoded (v >= 0 -> 2v, v < 0 -> -2v-1). seed = (world_seed*1000003 mod 2^32) xor (zz(cx)*73856093 mod 2^32) xor (zz(cy)*19349663 mod 2^32). The generator state is seed, or 1 when seed is 0, advanced by three 32-bit xorshift rounds (<<13, >>17, <<5, each left shift masked to 32 bits). Returns [seed, state % 100].

split: open-access


prompt:
Rooms of exactly twice the minimum width are never divided.

Recursively split the rectangle while depth remains. An axis can be split when that side is >= 2*min_size; if neither can, it is a leaf. Split vertically when w > h, or when w == h at even remaining depth; if the chosen axis cannot be split use the other. The first child gets floor(side/2). Returns leaves [x, y, w, h] in left/top-first order.

split: open-access


prompt:
BSP layouts are biased to vertical slices.

Recursively split the rectangle while depth remains. An axis can be split when that side is >= 2*min_size; if neither can, it is a leaf. Split vertically when w > h, or when w == h at even remaining depth; if the chosen axis cannot be split use the other. The first child gets floor(side/2). Returns leaves [x, y, w, h] in left/top-first order.

split: open-access


prompt:
Odd-width partitions leave an unassigned column.

Recursively split the rectangle while depth remains. An axis can be split when that side is >= 2*min_size; if neither can, it is a leaf. Split vertically when w > h, or when w == h at even remaining depth; if the chosen axis cannot be split use the other. The first child gets floor(side/2). Returns leaves [x, y, w, h] in left/top-first order.

split: open-access


prompt:
The bottom half of every horizontal split is over-partitioned.

Recursively split the rectangle while depth remains. An axis can be split when that side is >= 2*min_size; if neither can, it is a leaf. Split vertically when w > h, or when w == h at even remaining depth; if the chosen axis cannot be split use the other. The first child gets floor(side/2). Returns leaves [x, y, w, h] in left/top-first order.

split: open-access


prompt:
Dungeons have twice as many rooms as configured.

Recursively split the rectangle while depth remains. An axis can be split when that side is >= 2*min_size; if neither can, it is a leaf. Split vertically when w > h, or when w == h at even remaining depth; if the chosen axis cannot be split use the other. The first child gets floor(side/2). Returns leaves [x, y, w, h] in left/top-first order.

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
    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}),
  ('regression milestone bonus #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 milestone bonus #2', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression milestone bonus #3',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression milestone bonus #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}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression milestone bonus #2',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression milestone bonus #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 milestone bonus #4',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #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 milestone bonus #2',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('regression milestone bonus #3',
   [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 milestone bonus #4',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1',
   [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 milestone bonus #2',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('regression milestone bonus #3',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression milestone bonus #4', [20, [['orc', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 144}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('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})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression milestone bonus #2', [20, [['orc', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 144}),
  ('regression milestone bonus #3',
   [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 milestone bonus #4',
   [9, [['imp', 25, 3], ['bat', 5, 5]]],
   {'picks': ['imp', 'imp', 'bat', 'bat', 'bat'], 'left': 0}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', '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) * (1 + depth // 5)
    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}),
  ('regression milestone bonus #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 milestone bonus #2', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression milestone bonus #3',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression milestone bonus #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}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('regression milestone bonus #2',
   [5, [['orc', 10, 1], ['imp', 5, 10]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 15}),
  ('regression milestone bonus #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 milestone bonus #4',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #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 milestone bonus #2',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('regression milestone bonus #3',
   [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 milestone bonus #4',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1',
   [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 milestone bonus #2',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('regression milestone bonus #3',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression milestone bonus #4', [20, [['orc', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 144}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('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})],
 [('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('regression milestone bonus #1',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('regression milestone bonus #2', [20, [['orc', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 144}),
  ('regression milestone bonus #3',
   [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 milestone bonus #4',
   [9, [['imp', 25, 3], ['bat', 5, 5]]],
   {'picks': ['imp', 'imp', 'bat', 'bat', 'bat'], 'left': 0}),
  ('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('control #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', '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:
Every fifth floor is barely harder than the one before.

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 = [[('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site unlock depth #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}),
  ('partial repair boundary #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30}),
  ('partial repair boundary #2',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('control #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}),
  ('fault site unlock depth #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}),
  ('fault site unlock depth #2',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('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',
   [0, [['imp', 10, 1], ['rat', 7, 10], ['orc', 5, 10], ['ogre', 1, 1], ['wyrm', 5, 5]]],
   {'picks': [], 'left': 10}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('control #2', [5, [['orc', 10, 1], ['imp', 5, 10]]], {'picks': ['orc', 'orc', 'orc'], 'left': 15})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site unlock depth #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('fault site unlock depth #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, [['ogre', 5, 10]]], {'picks': [], 'left': 65}),
  ('partial repair boundary #2',
   [4, [['wyrm', 20, 5], ['orc', 5, 10], ['rat', 10, 10], ['bat', 15, 0]]],
   {'picks': ['bat', 'bat'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [1, [['imp', 10, 3], ['orc', 2, 0], ['rat', 10, 10], ['wyrm', 15, 5], ['bat', 15, 3]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 9}),
  ('control #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})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site unlock depth #1',
   [1, [['wyrm', 8, 10], ['ogre', 5, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0}),
  ('fault site unlock depth #2',
   [1, [['wyrm', 8, 3], ['rat', 5, 1]]],
   {'picks': ['rat', 'rat', 'rat'], 'left': 0}),
  ('partial repair boundary #1',
   [0, [['bat', 5, 3], ['orc', 1, 1], ['rat', 10, 10]]],
   {'picks': [], 'left': 10}),
  ('partial repair boundary #2', [9, [['wyrm', 2, 10]]], {'picks': [], 'left': 65}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('control #2', [0, [['bat', 18, 0]]], {'picks': [], 'left': 10})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site unlock depth #1',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('fault site unlock depth #2',
   [10, [['bat', 10, 1], ['ogre', 10, 10], ['orc', 5, 10]]],
   {'picks': ['bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre', 'orc', 'orc', 'orc'], 'left': 5}),
  ('regression unlock depth #1',
   [0, [['ogre', 2, 0], ['wyrm', 8, 1], ['rat', 5, 0], ['bat', 1, 1], ['imp', 10, 5]]],
   {'picks': ['rat', 'rat'], 'left': 0}),
  ('partial repair boundary #1',
   [9, [['wyrm', 1, 10], ['imp', 8, 5], ['rat', 8, 10]]],
   {'picks': ['imp', 'imp', 'imp'], 'left': 41}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1', [3, [['orc', 2, 0], ['wyrm', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 19}),
  ('control #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', '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 + 1 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 = [[('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site unlock depth #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}),
  ('partial repair boundary #1', [4, [['orc', 10, 10], ['wyrm', 2, 5]]], {'picks': [], 'left': 30}),
  ('partial repair boundary #2',
   [9, [['bat', 26, 5], ['rat', 11, 10], ['ogre', 5, 0], ['imp', 5, 0]]],
   {'picks': ['bat', 'bat', 'imp', 'imp'], 'left': 3}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1', [15, [['ogre', 5, 1]]], {'picks': ['ogre', 'ogre', 'ogre'], 'left': 100}),
  ('control #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}),
  ('fault site unlock depth #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}),
  ('fault site unlock depth #2',
   [1, [['imp', 10, 1], ['bat', 10, 10], ['orc', 1, 0]]],
   {'picks': ['imp', 'orc', 'orc', 'orc'], 'left': 2}),
  ('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',
   [0, [['imp', 10, 1], ['rat', 7, 10], ['orc', 5, 10], ['ogre', 1, 1], ['wyrm', 5, 5]]],
   {'picks': [], 'left': 10}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('control #2', [5, [['orc', 10, 1], ['imp', 5, 10]]], {'picks': ['orc', 'orc', 'orc'], 'left': 15})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site unlock depth #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('fault site unlock depth #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, [['ogre', 5, 10]]], {'picks': [], 'left': 65}),
  ('partial repair boundary #2',
   [4, [['wyrm', 20, 5], ['orc', 5, 10], ['rat', 10, 10], ['bat', 15, 0]]],
   {'picks': ['bat', 'bat'], 'left': 0}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [1, [['imp', 10, 3], ['orc', 2, 0], ['rat', 10, 10], ['wyrm', 15, 5], ['bat', 15, 3]]],
   {'picks': ['orc', 'orc', 'orc'], 'left': 9}),
  ('control #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})],
 [('equal cost tie #1', [0, [['orc', 5, 0], ['imp', 5, 0]]], {'picks': ['imp', 'imp'], 'left': 0}),
  ('fault site unlock depth #1',
   [1, [['wyrm', 8, 10], ['ogre', 5, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0}),
  ('fault site unlock depth #2',
   [1, [['wyrm', 8, 3], ['rat', 5, 1]]],
   {'picks': ['rat', 'rat', 'rat'], 'left': 0}),
  ('partial repair boundary #1',
   [0, [['bat', 5, 3], ['orc', 1, 1], ['rat', 10, 10]]],
   {'picks': [], 'left': 10}),
  ('partial repair boundary #2', [9, [['wyrm', 2, 10]]], {'picks': [], 'left': 65}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1',
   [9, [['rat', 7, 0], ['ogre', 1, 0]]],
   {'picks': ['rat', 'rat', 'rat', 'ogre', 'ogre', 'ogre'], 'left': 41}),
  ('control #2', [0, [['bat', 18, 0]]], {'picks': [], 'left': 10})],
 [('unlock at depth #1',
   [3, [['ogre', 10, 3], ['rat', 1, 0]]],
   {'picks': ['ogre', 'ogre', 'rat', 'rat', 'rat'], 'left': 2}),
  ('fault site unlock depth #1',
   [10, [['bat', 5, 10], ['ogre', 5, 5], ['wyrm', 10, 0]]],
   {'picks': ['wyrm', 'wyrm', 'wyrm', 'bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre'], 'left': 20}),
  ('fault site unlock depth #2',
   [10, [['bat', 10, 1], ['ogre', 10, 10], ['orc', 5, 10]]],
   {'picks': ['bat', 'bat', 'bat', 'ogre', 'ogre', 'ogre', 'orc', 'orc', 'orc'], 'left': 5}),
  ('regression unlock depth #1',
   [0, [['ogre', 2, 0], ['wyrm', 8, 1], ['rat', 5, 0], ['bat', 1, 1], ['imp', 10, 5]]],
   {'picks': ['rat', 'rat'], 'left': 0}),
  ('partial repair boundary #1',
   [9, [['wyrm', 1, 10], ['imp', 8, 5], ['rat', 8, 10]]],
   {'picks': ['imp', 'imp', 'imp'], 'left': 41}),
  ('milestone depth bonus #1', [5, [['orc', 5, 0]]], {'picks': ['orc', 'orc', 'orc'], 'left': 30}),
  ('control #1', [3, [['orc', 2, 0], ['wyrm', 2, 5]]], {'picks': ['orc', 'orc', 'orc'], 'left': 19}),
  ('control #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', '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:
New enemy types never appear on their unlock floor.

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 affordability #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}),
  ('fault site affordability #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression affordability #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}),
  ('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 affordability #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression affordability #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 affordability #2',
   [1, [['bat', 8, 3], ['rat', 5, 10], ['imp', 2, 1], ['orc', 1, 0], ['ogre', 15, 0], ['wyrm', 1, 1]]],
   {'picks': ['ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['rat', 2, 3], ['imp', 8, 0], ['orc', 10, 10], ['ogre', 5, 3], ['bat', 5, 5], ['wyrm', 26, 0]]],
   {'picks': ['imp'], 'left': 7}),
  ('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 affordability #1',
   [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}),
  ('fault site affordability #2',
   [1, [['wyrm', 8, 10], ['ogre', 5, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['rat', 2, 3], ['imp', 8, 0], ['orc', 10, 10], ['ogre', 5, 3], ['bat', 5, 5], ['wyrm', 26, 0]]],
   {'picks': ['imp'], 'left': 7}),
  ('regression affordability #1',
   [4, [['bat', 15, 3], ['wyrm', 5, 0], ['orc', 2, 3], ['rat', 5, 0], ['imp', 19, 10], ['ogre', 1, 1]]],
   {'picks': ['bat', 'bat'], '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}),
  ('fault site affordability #1',
   [1, [['wyrm', 8, 3], ['rat', 5, 1]]],
   {'picks': ['rat', 'rat', 'rat'], 'left': 0}),
  ('fault site affordability #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1', [1, [['orc', 20, 3], ['wyrm', 8, 0]]], {'picks': ['wyrm'], 'left': 7}),
  ('partial repair boundary #2',
   [1, [['bat', 2, 3], ['imp', 8, 1], ['ogre', 8, 10]]],
   {'picks': ['imp'], 'left': 7}),
  ('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 affordability #1',
   [9, [['imp', 25, 3], ['bat', 5, 5]]],
   {'picks': ['imp', 'imp', 'bat', 'bat', 'bat'], 'left': 0}),
  ('fault site affordability #2',
   [4, [['wyrm', 20, 5], ['orc', 5, 10], ['rat', 10, 10], ['bat', 15, 0]]],
   {'picks': ['bat', 'bat'], 'left': 0}),
  ('regression affordability #1',
   [4, [['bat', 1, 0], ['wyrm', 15, 5], ['rat', 20, 1], ['imp', 2, 3], ['orc', 2, 1], ['ogre', 15, 3]]],
   {'picks': ['rat', 'imp', 'imp', 'imp', 'orc', 'orc'], 'left': 0}),
  ('regression affordability #2',
   [0, [['imp', 5, 0], ['orc', 15, 10], ['ogre', 10, 10], ['wyrm', 1, 0], ['rat', 16, 1], ['bat', 5, 0]]],
   {'picks': ['bat', 'bat'], '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', [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)

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 - 1 > 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 affordability #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}),
  ('fault site affordability #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['orc', 5, 3], ['bat', 8, 1], ['wyrm', 8, 0]]],
   {'picks': ['bat'], 'left': 7}),
  ('regression affordability #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}),
  ('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 affordability #1',
   [4, [['rat', 5, 5], ['ogre', 5, 0], ['wyrm', 5, 1], ['imp', 5, 3]]],
   {'picks': ['imp', 'imp', 'imp', 'ogre', 'ogre', 'ogre'], 'left': 0}),
  ('regression affordability #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 affordability #2',
   [1, [['bat', 8, 3], ['rat', 5, 10], ['imp', 2, 1], ['orc', 1, 0], ['ogre', 15, 0], ['wyrm', 1, 1]]],
   {'picks': ['ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['rat', 2, 3], ['imp', 8, 0], ['orc', 10, 10], ['ogre', 5, 3], ['bat', 5, 5], ['wyrm', 26, 0]]],
   {'picks': ['imp'], 'left': 7}),
  ('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 affordability #1',
   [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}),
  ('fault site affordability #2',
   [1, [['wyrm', 8, 10], ['ogre', 5, 1]]],
   {'picks': ['ogre', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1',
   [1, [['rat', 2, 3], ['imp', 8, 0], ['orc', 10, 10], ['ogre', 5, 3], ['bat', 5, 5], ['wyrm', 26, 0]]],
   {'picks': ['imp'], 'left': 7}),
  ('regression affordability #1',
   [4, [['bat', 15, 3], ['wyrm', 5, 0], ['orc', 2, 3], ['rat', 5, 0], ['imp', 19, 10], ['ogre', 1, 1]]],
   {'picks': ['bat', 'bat'], '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}),
  ('fault site affordability #1',
   [1, [['wyrm', 8, 3], ['rat', 5, 1]]],
   {'picks': ['rat', 'rat', 'rat'], 'left': 0}),
  ('fault site affordability #2',
   [14, [['orc', 30, 1], ['bat', 15, 5], ['ogre', 5, 0], ['rat', 5, 5]]],
   {'picks': ['orc', 'orc', 'orc', 'ogre', 'ogre'], 'left': 0}),
  ('partial repair boundary #1', [1, [['orc', 20, 3], ['wyrm', 8, 0]]], {'picks': ['wyrm'], 'left': 7}),
  ('partial repair boundary #2',
   [1, [['bat', 2, 3], ['imp', 8, 1], ['ogre', 8, 10]]],
   {'picks': ['imp'], 'left': 7}),
  ('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 affordability #1',
   [9, [['imp', 25, 3], ['bat', 5, 5]]],
   {'picks': ['imp', 'imp', 'bat', 'bat', 'bat'], 'left': 0}),
  ('fault site affordability #2',
   [4, [['wyrm', 20, 5], ['orc', 5, 10], ['rat', 10, 10], ['bat', 15, 0]]],
   {'picks': ['bat', 'bat'], 'left': 0}),
  ('regression affordability #1',
   [4, [['bat', 1, 0], ['wyrm', 15, 5], ['rat', 20, 1], ['imp', 2, 3], ['orc', 2, 1], ['ogre', 15, 3]]],
   {'picks': ['rat', 'imp', 'imp', 'imp', 'orc', 'orc'], 'left': 0}),
  ('regression affordability #2',
   [0, [['imp', 5, 0], ['orc', 15, 10], ['ogre', 10, 10], ['wyrm', 1, 0], ['rat', 16, 1], ['bat', 5, 0]]],
   {'picks': ['bat', 'bat'], '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', [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:
An enemy costing exactly the remaining budget is skipped.

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