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

N = 1
observations = []
def solve(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level > 6:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('fault site risk tier start #2',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1',
   [3, [0, 40, 99, 29, 39], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 5}),
  ('regression risk tier start #1',
   [5, [99, 60, 89, 0, 59, 39, 50, 39], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 7}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('fault site risk tier start #2',
   [6, [90, 30, 29, 99, 0, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('regression risk tier start #1',
   [5, [89, 59, 99], 1],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 3}),
  ('regression risk tier start #2',
   [6, [60, 90, 59, 99, 89, 30], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site risk tier start #2', [6, [99], 0], {'level': 5, 'broken': False, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [3, [39, 29, 89], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [3, [59, 49, 89, 40, 29], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 5}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site risk tier start #2',
   [5, [90, 50, 60, 39, 99, 99, 30], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 7}),
  ('partial repair boundary #1',
   [5, [90, 30, 59, 60, 90, 50, 0], 2],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('regression risk tier start #1',
   [3, [60, 49, 80, 29, 89, 39], 1],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression risk tier start #1',
   [5, [99, 60, 89, 0, 59, 39, 50, 39], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 7}),
  ('regression risk tier start #2',
   [5, [89, 59, 99], 1],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 3}),
  ('regression risk tier start #3',
   [5, [90, 50, 82, 89, 57, 59], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1', [5, [99], 0], {'level': 5, 'broken': False, 'protections': 0, 'used': 1}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})]]
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(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 5:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('fault site risk tier start #2',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1',
   [3, [0, 40, 99, 29, 39], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 5}),
  ('regression risk tier start #1',
   [5, [99, 60, 89, 0, 59, 39, 50, 39], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 7}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('fault site risk tier start #2',
   [6, [90, 30, 29, 99, 0, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('regression risk tier start #1',
   [5, [89, 59, 99], 1],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 3}),
  ('regression risk tier start #2',
   [6, [60, 90, 59, 99, 89, 30], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site risk tier start #2', [6, [99], 0], {'level': 5, 'broken': False, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [3, [39, 29, 89], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [3, [59, 49, 89, 40, 29], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 5}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site risk tier start #1',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site risk tier start #2',
   [5, [90, 50, 60, 39, 99, 99, 30], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 7}),
  ('partial repair boundary #1',
   [5, [90, 30, 59, 60, 90, 50, 0], 2],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('regression risk tier start #1',
   [3, [60, 49, 80, 29, 89, 39], 1],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression risk tier start #1',
   [5, [99, 60, 89, 0, 59, 39, 50, 39], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 7}),
  ('regression risk tier start #2',
   [5, [89, 59, 99], 1],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 3}),
  ('regression risk tier start #3',
   [5, [90, 50, 82, 89, 57, 59], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1', [5, [99], 0], {'level': 5, 'broken': False, 'protections': 0, 'used': 1}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})]]
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:
Failing at level six neither downgrades nor consumes protection.

Success chance (percent) from level L: [100,100,100,90,80,70,60,50,40,30][L]; max level 10. A roll r (0..99) succeeds when r < chance. Failure at L <= 5 keeps the level; at L >= 6 consumes a protection if one is left (level kept); otherwise L 6..7 downgrades by one and L >= 8 breaks the item. Rolls stop being consumed once the item is at max level or broken; used counts consumed rolls.

split: open-access


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

N = 1
observations = []
def solve(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections >= 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #3',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [10, [90, 49, 29], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 0})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #3',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8}),
  ('control #2',
   [10, [34, 29, 90, 63, 0, 60, 59], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #2',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('regression protection availability #3',
   [8, [49, 29, 59, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 3}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression protection availability #2',
   [9, [89, 89, 89, 60, 0, 30, 40, 90], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression protection availability #3',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [0, [39, 49, 29, 0, 89], 0], {'level': 4, 'broken': False, 'protections': 0, 'used': 5}),
  ('control #2', [10, [29], 2], {'level': 10, 'broken': False, 'protections': 2, 'used': 0})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('fault site protection availability #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [8, [90, 90, 29, 29, 50, 99, 60, 60], 2],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression protection availability #2',
   [8, [49, 89, 60, 90, 39, 0, 89, 90], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [0, 0, 99, 40, 89], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 2})]]
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(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections > 1:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #3',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [10, [90, 49, 29], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 0})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #3',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8}),
  ('control #2',
   [10, [34, 29, 90, 63, 0, 60, 59], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression protection availability #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression protection availability #2',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('regression protection availability #3',
   [8, [49, 29, 59, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 3}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [8, [89, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site protection availability #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression protection availability #2',
   [9, [89, 89, 89, 60, 0, 30, 40, 90], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression protection availability #3',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [0, [39, 49, 29, 0, 89], 0], {'level': 4, 'broken': False, 'protections': 0, 'used': 5}),
  ('control #2', [10, [29], 2], {'level': 10, 'broken': False, 'protections': 2, 'used': 0})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('regression protection availability #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('fault site protection availability #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [8, [90, 90, 29, 29, 50, 99, 60, 60], 2],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression protection availability #2',
   [8, [49, 89, 60, 90, 39, 0, 89, 90], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [0, 0, 99, 40, 89], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 2})]]
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:
Items are protected by a phantom scroll and protection count goes negative.

Success chance (percent) from level L: [100,100,100,90,80,70,60,50,40,30][L]; max level 10. A roll r (0..99) succeeds when r < chance. Failure at L <= 5 keeps the level; at L >= 6 consumes a protection if one is left (level kept); otherwise L 6..7 downgrades by one and L >= 8 breaks the item. Rolls stop being consumed once the item is at max level or broken; used counts consumed rolls.

split: open-access


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

N = 1
observations = []
def solve(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 7:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site break tier start #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression break tier start #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('regression break tier start #2',
   [6, [29, 59, 40, 29, 49, 99, 89], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('partial repair boundary #1', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression break tier start #3',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site break tier start #1',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('partial repair boundary #1',
   [6, [40, 30, 89, 10, 29, 40, 60], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression break tier start #2',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [6, [50, 90, 59, 29, 49, 89, 99], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('fault site break tier start #1',
   [6, [50, 90], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 2}),
  ('partial repair boundary #1',
   [6, [40, 30, 64, 40, 59, 89, 29], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression break tier start #2',
   [6, [29, 59, 40, 29, 49, 99, 89], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site break tier start #1',
   [6, [59, 65], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site break tier start #2',
   [5, [90, 30, 59, 60, 90, 50, 0], 2],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('partial repair boundary #1',
   [6, [39, 29, 89, 60, 50, 50], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [6, [49, 30, 50, 33, 50], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})]]
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(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 9:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site break tier start #1',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('regression break tier start #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('partial repair boundary #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('regression break tier start #2',
   [6, [29, 59, 40, 29, 49, 99, 89], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('partial repair boundary #1', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression break tier start #3',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site break tier start #1',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('partial repair boundary #1',
   [6, [40, 30, 89, 10, 29, 40, 60], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression break tier start #2',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression break tier start #1',
   [6, [50, 90, 59, 29, 49, 89, 99], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('fault site break tier start #1',
   [6, [50, 90], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 2}),
  ('partial repair boundary #1',
   [6, [40, 30, 64, 40, 59, 89, 29], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression break tier start #2',
   [6, [29, 59, 40, 29, 49, 99, 89], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 5}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site break tier start #1',
   [6, [59, 65], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site break tier start #2',
   [5, [90, 30, 59, 60, 90, 50, 0], 2],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('partial repair boundary #1',
   [6, [39, 29, 89, 60, 50, 50], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [6, [49, 30, 50, 33, 50], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})]]
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:
Unprotected level seven failures destroy the item instead of downgrading.

Success chance (percent) from level L: [100,100,100,90,80,70,60,50,40,30][L]; max level 10. A roll r (0..99) succeeds when r < chance. Failure at L <= 5 keeps the level; at L >= 6 consumes a protection if one is left (level kept); otherwise L 6..7 downgrades by one and L >= 8 breaks the item. Rolls stop being consumed once the item is at max level or broken; used counts consumed rolls.

split: open-access


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

N = 1
observations = []
def solve(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        used += 1
        if level >= 10 or broken:
            break
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression roll consumption order #2',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #3',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #4',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #2',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #3',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #4',
   [9, [90, 59, 50], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [10, [90, 49, 29], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('fault site roll consumption order #2',
   [10, [34, 29, 90, 63, 0, 60, 59], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('regression roll consumption order #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #2',
   [9, [90, 59, 50], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [8, [0, 0, 99, 40, 89], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site roll consumption order #2',
   [10, [29, 60, 40, 59], 2],
   {'level': 10, 'broken': False, 'protections': 2, 'used': 0}),
  ('regression roll consumption order #1',
   [6, [40, 30, 89, 10, 29, 40, 60], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression roll consumption order #2',
   [8, [49, 29, 59, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 3}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [49, 40, 59], 2], {'level': 8, 'broken': True, 'protections': 0, 'used': 3})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [10, [29], 2],
   {'level': 10, 'broken': False, 'protections': 2, 'used': 0}),
  ('fault site roll consumption order #2',
   [10, [29, 29, 30, 90], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('regression roll consumption order #1',
   [9, [89, 89, 89, 60, 0, 30, 40, 90], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression roll consumption order #2',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2})]]
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(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10:
            break
        used += 1
        if r < chance[level]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression roll consumption order #2',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #3',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #4',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #1',
   [9, [99, 30], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #2',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #3',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #4',
   [9, [90, 59, 50], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [10, [90, 49, 29], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('fault site roll consumption order #2',
   [10, [34, 29, 90, 63, 0, 60, 59], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('regression roll consumption order #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('regression roll consumption order #2',
   [9, [90, 59, 50], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [8, [0, 0, 99, 40, 89], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 2}),
  ('fault site roll consumption order #2',
   [10, [29, 60, 40, 59], 2],
   {'level': 10, 'broken': False, 'protections': 2, 'used': 0}),
  ('regression roll consumption order #1',
   [6, [40, 30, 89, 10, 29, 40, 60], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('regression roll consumption order #2',
   [8, [49, 29, 59, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 3}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [49, 40, 59], 2], {'level': 8, 'broken': True, 'protections': 0, 'used': 3})],
 [('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('fault site roll consumption order #1',
   [10, [29], 2],
   {'level': 10, 'broken': False, 'protections': 2, 'used': 0}),
  ('fault site roll consumption order #2',
   [10, [29, 29, 30, 90], 0],
   {'level': 10, 'broken': False, 'protections': 0, 'used': 0}),
  ('regression roll consumption order #1',
   [9, [89, 89, 89, 60, 0, 30, 40, 90], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('regression roll consumption order #2',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('control #1', [8, [89, 89], 1], {'level': 8, 'broken': True, 'protections': 0, 'used': 2})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A roll is charged after the item maxed out or broke.

Success chance (percent) from level L: [100,100,100,90,80,70,60,50,40,30][L]; max level 10. A roll r (0..99) succeeds when r < chance. Failure at L <= 5 keeps the level; at L >= 6 consumes a protection if one is left (level kept); otherwise L 6..7 downgrades by one and L >= 8 breaks the item. Rolls stop being consumed once the item is at max level or broken; used counts consumed rolls.

split: open-access


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

N = 1
observations = []
def solve(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q for q, w in materials) // len(materials) + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score >= c)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[39, 1], [100, 3], [85, 1]], 26, 5],
   {'score': 86, 'tier': 'masterwork'}),
  ('regression material weighting #2', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'}),
  ('regression material weighting #3',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression material weighting #4', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'}),
  ('regression material weighting #2',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression material weighting #3', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #4', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #2', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('regression material weighting #3',
   [[[65, 1], [65, 0], [39, 1], [64, 1]], 25, 16],
   {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #4', [[[39, 2], [0, 1], [65, 2]], 25, 5], {'score': 43, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[65, 1], [65, 0], [39, 1], [64, 1]], 25, 16],
   {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #2', [[[39, 2], [0, 1], [65, 2]], 25, 5], {'score': 43, 'tier': 'fine'}),
  ('regression material weighting #3',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression material weighting #4',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression material weighting #2',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('regression material weighting #3', [[[100, 0], [40, 3]], 150, 50], {'score': 55, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[100, 0], [100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 0]], 24, 28], {'score': 0, 'tier': 'failed'})]]
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(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // len(materials) + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score >= c)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[39, 1], [100, 3], [85, 1]], 26, 5],
   {'score': 86, 'tier': 'masterwork'}),
  ('regression material weighting #2', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'}),
  ('regression material weighting #3',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression material weighting #4', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'}),
  ('regression material weighting #2',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression material weighting #3', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #4', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #2', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('regression material weighting #3',
   [[[65, 1], [65, 0], [39, 1], [64, 1]], 25, 16],
   {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #4', [[[39, 2], [0, 1], [65, 2]], 25, 5], {'score': 43, 'tier': 'fine'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[65, 1], [65, 0], [39, 1], [64, 1]], 25, 16],
   {'score': 58, 'tier': 'fine'}),
  ('regression material weighting #2', [[[39, 2], [0, 1], [65, 2]], 25, 5], {'score': 43, 'tier': 'fine'}),
  ('regression material weighting #3',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression material weighting #4',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'})],
 [('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('regression material weighting #1',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression material weighting #2',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('regression material weighting #3', [[[100, 0], [40, 3]], 150, 50], {'score': 55, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[100, 0], [100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 0]], 24, 28], {'score': 0, 'tier': 'failed'})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A small pinch of a rare reagent counts as much as the bulk material.

materials = [[quality, weight], ...]. If total weight <= 0 the craft fails (score 0, tier "failed"). score = floor(sum(q*w)/sum(w)) + skill//10, capped at 100. Tier index = number of cutoffs [40, 65, 85] with score >= cutoff over [common, fine, superior, masterwork]. A critical craft (skill >= 25 and crit_roll < 5) raises the tier by one, never above masterwork.

split: open-access


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

N = 1
observations = []
def solve(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = min(99, score)
    t = sum(1 for c in cuts if score >= c)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[100, 0], [100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[84, 0], [100, 3]], 24, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[84, 0], [100, 3]], 24, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[84, 3], [100, 2], [100, 3]], 100, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[84, 3], [100, 2], [100, 3]], 100, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[64, 0], [100, 3]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[64, 0], [100, 3]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3',
   [[[0, 0], [0, 0], [84, 1], [92, 3]], 150, 50],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[100, 3], [53, 1]], 150, 4], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1',
   [[[0, 0], [0, 0], [84, 1], [92, 3]], 150, 50],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 3], [53, 1]], 150, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3',
   [[[100, 2], [65, 1], [100, 1], [0, 0]], 150, 4],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[85, 0], [100, 1]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})]]
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(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = max(0, score)
    t = sum(1 for c in cuts if score >= c)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[100, 0], [100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[84, 0], [100, 3]], 24, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[84, 0], [100, 3]], 24, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[84, 3], [100, 2], [100, 3]], 100, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[85, 0], [100, 1]], 150, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[84, 3], [100, 2], [100, 3]], 100, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3', [[[64, 0], [100, 3]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1', [[[64, 0], [100, 3]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 1]], 24, 50], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3',
   [[[0, 0], [0, 0], [84, 1], [92, 3]], 150, 50],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[100, 3], [53, 1]], 150, 4], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #1',
   [[[0, 0], [0, 0], [84, 1], [92, 3]], 150, 50],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #2', [[[100, 3], [53, 1]], 150, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #3',
   [[[100, 2], [65, 1], [100, 1], [0, 0]], 150, 4],
   {'score': 100, 'tier': 'masterwork'}),
  ('regression score cap #4', [[[85, 0], [100, 1]], 24, 4], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})]]
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:
Perfect crafts report 99 and the displayed score never reaches 100.

materials = [[quality, weight], ...]. If total weight <= 0 the craft fails (score 0, tier "failed"). score = floor(sum(q*w)/sum(w)) + skill//10, capped at 100. Tier index = number of cutoffs [40, 65, 85] with score >= cutoff over [common, fine, superior, masterwork]. A critical craft (skill >= 25 and crit_roll < 5) raises the tier by one, never above masterwork.

split: open-access


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

N = 1
observations = []
def solve(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score > c)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #2',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('partial repair boundary #1', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('partial repair boundary #2', [[[30, 1], [0, 1], [84, 1]], 10, 4], {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('fault site tier cutoff inclusion #2',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[40, 3], [100, 0], [0, 1], [65, 1]], 25, 50],
   {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2', [[[39, 1]], 6, 19], {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[64, 3], [65, 2]], 10, 5], {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2', [[[64, 3]], 10, 5], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[100, 1], [84, 3], [8, 0], [39, 1]], 64, 50],
   {'score': 84, 'tier': 'superior'}),
  ('partial repair boundary #2', [[[100, 1], [65, 1]], 25, 5], {'score': 84, 'tier': 'superior'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1',
   [[[0, 0], [100, 2], [39, 3]], 24, 5],
   {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2',
   [[[86, 1], [85, 0], [64, 1], [64, 0]], 100, 5],
   {'score': 85, 'tier': 'masterwork'}),
  ('partial repair boundary #1', [[[85, 0], [39, 2], [39, 3]], 0, 4], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2', [[[64, 3]], 0, 50], {'score': 64, 'tier': 'fine'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[65, 1]], 0, 0], {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2', [[[65, 3]], 0, 5], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1', [[[40, 3], [39, 2], [64, 0]], 0, 5], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2',
   [[[0, 0], [78, 1], [40, 2], [0, 1]], 9, 89],
   {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'})]]
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(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score >= c - 1)
    if skill >= 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #2',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('partial repair boundary #1', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('partial repair boundary #2', [[[30, 1], [0, 1], [84, 1]], 10, 4], {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1',
   [[[40, 0], [65, 0], [84, 1], [100, 0]], 17, 4],
   {'score': 85, 'tier': 'masterwork'}),
  ('fault site tier cutoff inclusion #2',
   [[[0, 1], [65, 3], [0, 0], [64, 3]], 103, 10],
   {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[40, 3], [100, 0], [0, 1], [65, 1]], 25, 50],
   {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2', [[[39, 1]], 6, 19], {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[64, 3], [65, 2]], 10, 5], {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2', [[[64, 3]], 10, 5], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[100, 1], [84, 3], [8, 0], [39, 1]], 64, 50],
   {'score': 84, 'tier': 'superior'}),
  ('partial repair boundary #2', [[[100, 1], [65, 1]], 25, 5], {'score': 84, 'tier': 'superior'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1',
   [[[0, 0], [100, 2], [39, 3]], 24, 5],
   {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2',
   [[[86, 1], [85, 0], [64, 1], [64, 0]], 100, 5],
   {'score': 85, 'tier': 'masterwork'}),
  ('partial repair boundary #1', [[[85, 0], [39, 2], [39, 3]], 0, 4], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2', [[[64, 3]], 0, 50], {'score': 64, 'tier': 'fine'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})],
 [('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('fault site tier cutoff inclusion #1', [[[65, 1]], 0, 0], {'score': 65, 'tier': 'superior'}),
  ('fault site tier cutoff inclusion #2', [[[65, 3]], 0, 5], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1', [[[40, 3], [39, 2], [64, 0]], 0, 5], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #2',
   [[[0, 0], [78, 1], [40, 2], [0, 1]], 9, 89],
   {'score': 39, 'tier': 'common'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A craft exactly on a tier cutoff is graded one tier lower.

materials = [[quality, weight], ...]. If total weight <= 0 the craft fails (score 0, tier "failed"). score = floor(sum(q*w)/sum(w)) + skill//10, capped at 100. Tier index = number of cutoffs [40, 65, 85] with score >= cutoff over [common, fine, superior, masterwork]. A critical craft (skill >= 25 and crit_roll < 5) raises the tier by one, never above masterwork.

split: open-access


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

N = 1
observations = []
def solve(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score >= c)
    if crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('fault site critical skill gate #1', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[0, 1], [0, 3], [40, 0]], 25, 0], {'score': 2, 'tier': 'fine'}),
  ('partial repair boundary #2', [[[65, 3], [39, 0]], 25, 4], {'score': 67, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('fault site critical skill gate #1', [[[30, 1], [0, 1], [84, 1]], 10, 4], {'score': 39, 'tier': 'common'}),
  ('fault site critical skill gate #2',
   [[[64, 2], [69, 2], [65, 2], [89, 1]], 9, 4],
   {'score': 69, 'tier': 'superior'}),
  ('partial repair boundary #1', [[[85, 0], [84, 2], [39, 1]], 25, 0], {'score': 71, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[0, 3], [39, 1]], 25, 0], {'score': 11, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'}),
  ('control #2', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('fault site critical skill gate #1',
   [[[91, 0], [100, 1], [85, 1], [39, 3]], 10, 0],
   {'score': 61, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[40, 2], [84, 1]], 24, 0], {'score': 56, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[64, 1], [100, 0], [79, 1]], 25, 0], {'score': 73, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[84, 1], [65, 2]], 25, 0], {'score': 73, 'tier': 'masterwork'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'}),
  ('control #2', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})],
 [('fault site critical skill gate #1', [[[64, 3]], 24, 4], {'score': 66, 'tier': 'superior'}),
  ('fault site critical skill gate #2', [[[85, 0], [39, 2], [39, 3]], 0, 4], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #1', [[[100, 1], [85, 0], [65, 3]], 25, 4], {'score': 75, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[0, 2]], 25, 0], {'score': 2, 'tier': 'fine'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'}),
  ('control #2', [[[39, 0]], 24, 28], {'score': 0, 'tier': 'failed'})],
 [('fault site critical skill gate #1',
   [[[39, 3], [40, 1], [84, 1], [85, 1]], 24, 0],
   {'score': 56, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[65, 1]], 0, 0], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[64, 1], [84, 0], [100, 1], [65, 1]], 25, 0],
   {'score': 78, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[64, 1], [65, 0], [0, 3], [64, 0]], 25, 0], {'score': 18, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('control #1', [[[0, 3]], 25, 5], {'score': 2, 'tier': 'common'}),
  ('control #2', [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4], {'score': 71, 'tier': 'masterwork'})]]
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(materials, skill, crit_roll):
    tiers = ['common', 'fine', 'superior', 'masterwork']
    cuts = [40, 65, 85]
    total_w = sum(w for q, w in materials)
    if total_w <= 0:
        return {'score': 0, 'tier': 'failed'}
    score = sum(q * w for q, w in materials) // total_w + skill // 10
    score = min(100, score)
    t = sum(1 for c in cuts if score >= c)
    if skill > 25 and crit_roll < 5:
        t = min(t + 1, len(tiers) - 1)
    return {'score': score, 'tier': tiers[t]}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('fault site critical skill gate #1', [[[58, 0], [40, 0], [58, 1]], 9, 0], {'score': 58, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[0, 0], [64, 3]], 0, 0], {'score': 64, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[0, 1], [0, 3], [40, 0]], 25, 0], {'score': 2, 'tier': 'fine'}),
  ('partial repair boundary #2', [[[65, 3], [39, 0]], 25, 4], {'score': 67, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'})],
 [('fault site critical skill gate #1', [[[30, 1], [0, 1], [84, 1]], 10, 4], {'score': 39, 'tier': 'common'}),
  ('fault site critical skill gate #2',
   [[[64, 2], [69, 2], [65, 2], [89, 1]], 9, 4],
   {'score': 69, 'tier': 'superior'}),
  ('partial repair boundary #1', [[[85, 0], [84, 2], [39, 1]], 25, 0], {'score': 71, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[0, 3], [39, 1]], 25, 0], {'score': 11, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('control #1', [[[39, 1]], 10, 50], {'score': 40, 'tier': 'fine'}),
  ('control #2', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'})],
 [('fault site critical skill gate #1',
   [[[91, 0], [100, 1], [85, 1], [39, 3]], 10, 0],
   {'score': 61, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[40, 2], [84, 1]], 24, 0], {'score': 56, 'tier': 'fine'}),
  ('partial repair boundary #1', [[[64, 1], [100, 0], [79, 1]], 25, 0], {'score': 73, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[84, 1], [65, 2]], 25, 0], {'score': 73, 'tier': 'masterwork'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('control #1', [[[39, 1], [100, 3], [85, 1]], 26, 5], {'score': 86, 'tier': 'masterwork'}),
  ('control #2', [[[39, 3], [85, 0]], 52, 0], {'score': 44, 'tier': 'superior'})],
 [('fault site critical skill gate #1', [[[64, 3]], 24, 4], {'score': 66, 'tier': 'superior'}),
  ('fault site critical skill gate #2', [[[85, 0], [39, 2], [39, 3]], 0, 4], {'score': 39, 'tier': 'common'}),
  ('partial repair boundary #1', [[[100, 1], [85, 0], [65, 3]], 25, 4], {'score': 75, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[0, 2]], 25, 0], {'score': 2, 'tier': 'fine'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('score exactly fine cutoff #1', [[[40, 1]], 0, 99], {'score': 40, 'tier': 'fine'}),
  ('control #1', [[[39, 1]], 25, 5], {'score': 41, 'tier': 'fine'}),
  ('control #2', [[[39, 0]], 24, 28], {'score': 0, 'tier': 'failed'})],
 [('fault site critical skill gate #1',
   [[[39, 3], [40, 1], [84, 1], [85, 1]], 24, 0],
   {'score': 56, 'tier': 'fine'}),
  ('fault site critical skill gate #2', [[[65, 1]], 0, 0], {'score': 65, 'tier': 'superior'}),
  ('partial repair boundary #1',
   [[[64, 1], [84, 0], [100, 1], [65, 1]], 25, 0],
   {'score': 78, 'tier': 'masterwork'}),
  ('partial repair boundary #2', [[[64, 1], [65, 0], [0, 3], [64, 0]], 25, 0], {'score': 18, 'tier': 'fine'}),
  ('masterwork crit #1', [[[100, 2]], 50, 0], {'score': 100, 'tier': 'masterwork'}),
  ('heavy rare material #1', [[[90, 3], [30, 1]], 0, 50], {'score': 75, 'tier': 'superior'}),
  ('control #1', [[[0, 3]], 25, 5], {'score': 2, 'tier': 'common'}),
  ('control #2', [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4], {'score': 71, 'tier': 'masterwork'})]]
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:
Crafters below skill 25 still get critical upgrades.

materials = [[quality, weight], ...]. If total weight <= 0 the craft fails (score 0, tier "failed"). score = floor(sum(q*w)/sum(w)) + skill//10, capped at 100. Tier index = number of cutoffs [40, 65, 85] with score >= cutoff over [common, fine, superior, masterwork]. A critical craft (skill >= 25 and crit_roll < 5) raises the tier by one, never above masterwork.

split: open-access