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) - 2)
    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 masterwork crit ceiling #1',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2', [[[64, 3], [84, 1]], 26, 0], {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4', [[[64, 1]], 150, 4], {'score': 79, '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 masterwork crit ceiling #1', [[[64, 3], [84, 1]], 26, 0], {'score': 71, 'tier': 'masterwork'}),
  ('fault site masterwork crit ceiling #1',
   [[[100, 1], [85, 3], [65, 3]], 75, 0],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3', [[[64, 1]], 150, 4], {'score': 79, '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 masterwork crit ceiling #1',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2', [[[64, 1]], 150, 4], {'score': 79, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[40, 1], [64, 0], [84, 2]], 26, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4',
   [[[27, 1], [65, 1], [84, 1]], 113, 0],
   {'score': 69, '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'}),
  ('fault site masterwork crit ceiling #1', [[[84, 0], [85, 2]], 25, 0], {'score': 87, 'tier': 'masterwork'}),
  ('fault site masterwork crit ceiling #2', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #1',
   [[[65, 3], [78, 2], [64, 0], [40, 0]], 99, 0],
   {'score': 79, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #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'}),
  ('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 masterwork crit ceiling #1',
   [[[40, 1], [64, 0], [84, 2]], 26, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2',
   [[[27, 1], [65, 1], [84, 1]], 113, 0],
   {'score': 69, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[85, 0], [84, 2], [39, 1]], 25, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4', [[[65, 2], [64, 2]], 99, 0], {'score': 73, '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 = min(100, score)
    t = sum(1 for c in cuts if score >= c)
    if skill >= 25 and crit_roll < 5:
        t = t + 1 if t < 2 else t
    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 masterwork crit ceiling #1',
   [[[100, 1], [65, 3], [40, 1], [39, 1]], 99, 4],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2', [[[64, 3], [84, 1]], 26, 0], {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4', [[[64, 1]], 150, 4], {'score': 79, '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 masterwork crit ceiling #1', [[[64, 3], [84, 1]], 26, 0], {'score': 71, 'tier': 'masterwork'}),
  ('fault site masterwork crit ceiling #1',
   [[[100, 1], [85, 3], [65, 3]], 75, 0],
   {'score': 85, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3', [[[64, 1]], 150, 4], {'score': 79, '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 masterwork crit ceiling #1',
   [[[65, 1], [65, 1], [39, 3], [88, 3]], 99, 4],
   {'score': 72, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2', [[[64, 1]], 150, 4], {'score': 79, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[40, 1], [64, 0], [84, 2]], 26, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4',
   [[[27, 1], [65, 1], [84, 1]], 113, 0],
   {'score': 69, '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'}),
  ('fault site masterwork crit ceiling #1', [[[84, 0], [85, 2]], 25, 0], {'score': 87, 'tier': 'masterwork'}),
  ('fault site masterwork crit ceiling #2', [[[100, 2]], 142, 4], {'score': 100, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #1',
   [[[65, 3], [78, 2], [64, 0], [40, 0]], 99, 0],
   {'score': 79, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #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'}),
  ('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 masterwork crit ceiling #1',
   [[[40, 1], [64, 0], [84, 2]], 26, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #2',
   [[[27, 1], [65, 1], [84, 1]], 113, 0],
   {'score': 69, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #3',
   [[[85, 0], [84, 2], [39, 1]], 25, 0],
   {'score': 71, 'tier': 'masterwork'}),
  ('regression masterwork crit ceiling #4', [[[65, 2], [64, 2]], 99, 0], {'score': 73, '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:
A critical masterwork is downgraded to superior.

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


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
Stamina regenerates slower whenever an event lands between ticks.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
A player refilled exactly to cap keeps a stale timer and regains too early after spending.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
Potions that push stamina above cap are silently lost on the next update.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
Stamina potions used near full are wasted.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
Actions costing more than the pool are accepted with negative stamina.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
Late-submitted early events regenerate backward in time.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


prompt:
Every event re-grants stamina for time already credited.

Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].

split: open-access


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

N = 1
observations = []
def solve(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity == 'rare':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'legendary', 10], ['i1', 'rare', 29], ['i2', 'common', 95]], 827, 100],
   'i0'),
  ('fault site magic find scope #2',
   [[['i0', 'rare', 2], ['i1', 'common', 10], ['i2', 'legendary', 10], ['i3', 'rare', 10]], 5000, 250],
   'i2'),
  ('partial repair boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10],
     ['i1', 'common', 0],
     ['i2', 'common', 2],
     ['i3', 'rare', 0],
     ['i4', 'common', 10]],
    5000,
    -50],
   'i4'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10],
     ['i1', 'common', 0],
     ['i2', 'common', 2],
     ['i3', 'rare', 0],
     ['i4', 'common', 10]],
    5000,
    -50],
   'i4'),
  ('fault site magic find scope #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression magic find scope #2',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression magic find scope #3',
   [[['i0', 'common', 10], ['i1', 'common', 1], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression magic find scope #1',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression magic find scope #2',
   [[['i0', 'common', 10], ['i1', 'common', 1], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, -50],
   'i2'),
  ('regression magic find scope #3',
   [[['i0', 'legendary', 10], ['i1', 'rare', 10], ['i2', 'common', 5], ['i3', 'rare', 10], ['i4', 'rare', 1]],
    5000,
    -66],
   'i2'),
  ('regression magic find scope #4', [[['i0', 'legendary', 1]], 5000, -50], None),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'legendary', 41], ['i1', 'rare', 1], ['i2', 'rare', 5], ['i3', 'common', 30]], 5000, 110],
   'i0'),
  ('fault site magic find scope #2',
   [[['i0', 'legendary', 55], ['i1', 'common', 50], ['i2', 'legendary', 2], ['i3', 'common', 55]], 5000, 100],
   'i0'),
  ('regression magic find scope #1', [[['i0', 'legendary', 1]], 5000, -50], None),
  ('regression magic find scope #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 1], ['i2', 'legendary', 50]], 1, -50],
   'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'common', 2], ['i1', 'legendary', 1], ['i2', 'legendary', 2], ['i3', 'legendary', 3]], 3114, 100],
   'i2'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10], ['i1', 'rare', 10], ['i2', 'common', 5], ['i3', 'rare', 10], ['i4', 'rare', 1]],
    5000,
    -66],
   'i2'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'legendary', 2], ['i2', 'rare', 1], ['i3', 'rare', 5], ['i4', 'common', 0]],
    5000,
    -50],
   'i0'),
  ('regression magic find scope #2',
   [[['i0', 'legendary', 1], ['i1', 'rare', 2], ['i2', 'legendary', 5], ['i3', 'rare', 5]], 0, -16],
   'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common' and magic_find > 0:
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'legendary', 10], ['i1', 'rare', 29], ['i2', 'common', 95]], 827, 100],
   'i0'),
  ('fault site magic find scope #2',
   [[['i0', 'rare', 2], ['i1', 'common', 10], ['i2', 'legendary', 10], ['i3', 'rare', 10]], 5000, 250],
   'i2'),
  ('partial repair boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10],
     ['i1', 'common', 0],
     ['i2', 'common', 2],
     ['i3', 'rare', 0],
     ['i4', 'common', 10]],
    5000,
    -50],
   'i4'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10],
     ['i1', 'common', 0],
     ['i2', 'common', 2],
     ['i3', 'rare', 0],
     ['i4', 'common', 10]],
    5000,
    -50],
   'i4'),
  ('fault site magic find scope #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression magic find scope #2',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression magic find scope #3',
   [[['i0', 'common', 10], ['i1', 'common', 1], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression magic find scope #1',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression magic find scope #2',
   [[['i0', 'common', 10], ['i1', 'common', 1], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, -50],
   'i2'),
  ('regression magic find scope #3',
   [[['i0', 'legendary', 10], ['i1', 'rare', 10], ['i2', 'common', 5], ['i3', 'rare', 10], ['i4', 'rare', 1]],
    5000,
    -66],
   'i2'),
  ('regression magic find scope #4', [[['i0', 'legendary', 1]], 5000, -50], None),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'legendary', 41], ['i1', 'rare', 1], ['i2', 'rare', 5], ['i3', 'common', 30]], 5000, 110],
   'i0'),
  ('fault site magic find scope #2',
   [[['i0', 'legendary', 55], ['i1', 'common', 50], ['i2', 'legendary', 2], ['i3', 'common', 55]], 5000, 100],
   'i0'),
  ('regression magic find scope #1', [[['i0', 'legendary', 1]], 5000, -50], None),
  ('regression magic find scope #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 1], ['i2', 'legendary', 50]], 1, -50],
   'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site magic find scope #1',
   [[['i0', 'common', 2], ['i1', 'legendary', 1], ['i2', 'legendary', 2], ['i3', 'legendary', 3]], 3114, 100],
   'i2'),
  ('regression magic find scope #1',
   [[['i0', 'legendary', 10], ['i1', 'rare', 10], ['i2', 'common', 5], ['i3', 'rare', 10], ['i4', 'rare', 1]],
    5000,
    -66],
   'i2'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'legendary', 2], ['i2', 'rare', 1], ['i3', 'rare', 5], ['i4', 'common', 0]],
    5000,
    -50],
   'i0'),
  ('regression magic find scope #2',
   [[['i0', 'legendary', 1], ['i1', 'rare', 2], ['i2', 'legendary', 5], ['i3', 'rare', 5]], 0, -16],
   'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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:
Magic find boosts rares but not legendaries.

table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.

split: open-access


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

N = 1
observations = []
def solve(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w + magic_find
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0'),
  ('regression boost arithmetic #2',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('partial repair boundary #1', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0'),
  ('regression boost arithmetic #3', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('fault site boost arithmetic #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('partial repair boundary #1', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0'),
  ('regression boost arithmetic #2', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site boost arithmetic #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('fault site boost arithmetic #2', [[['i0', 'legendary', 0]], 0, 100], None),
  ('regression boost arithmetic #1',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression boost arithmetic #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('regression boost arithmetic #2',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression boost arithmetic #3', [[['i0', 'rare', 2]], 5000, -50], 'i0'),
  ('regression boost arithmetic #4',
   [[['i0', 'common', 0], ['i1', 'legendary', 10], ['i2', 'legendary', 50]], 2138, -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('fault site boost arithmetic #1',
   [[['i0', 'rare', 50], ['i1', 'rare', 10], ['i2', 'common', 50], ['i3', 'rare', 0], ['i4', 'common', 56]],
    5000,
    250],
   'i0'),
  ('regression boost arithmetic #2',
   [[['i0', 'legendary', 5], ['i1', 'rare', 0], ['i2', 'common', 10], ['i3', 'rare', 1]], 1, -50],
   'i0'),
  ('partial repair boundary #1',
   [[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
    5000,
    -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (1 + magic_find // 100)
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0'),
  ('regression boost arithmetic #2',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('partial repair boundary #1', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0'),
  ('regression boost arithmetic #3', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('fault site boost arithmetic #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('partial repair boundary #1', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0'),
  ('regression boost arithmetic #2', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site boost arithmetic #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('fault site boost arithmetic #2', [[['i0', 'legendary', 0]], 0, 100], None),
  ('regression boost arithmetic #1',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression boost arithmetic #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('regression boost arithmetic #2',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression boost arithmetic #3', [[['i0', 'rare', 2]], 5000, -50], 'i0'),
  ('regression boost arithmetic #4',
   [[['i0', 'common', 0], ['i1', 'legendary', 10], ['i2', 'legendary', 50]], 2138, -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('regression boost arithmetic #1', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('fault site boost arithmetic #1',
   [[['i0', 'rare', 50], ['i1', 'rare', 10], ['i2', 'common', 50], ['i3', 'rare', 0], ['i4', 'common', 56]],
    5000,
    250],
   'i0'),
  ('regression boost arithmetic #2',
   [[['i0', 'legendary', 5], ['i1', 'rare', 0], ['i2', 'common', 10], ['i3', 'rare', 1]], 1, -50],
   'i0'),
  ('partial repair boundary #1',
   [[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
    5000,
    -50],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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:
Magic find overwhelms tiny weights and barely moves large ones.

table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.

split: open-access


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

N = 1
observations = []
def solve(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll % total
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('partial repair boundary #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression roll scaling #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0'),
  ('control #2',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('regression roll scaling #1',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('regression roll scaling #2',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'common', 2], ['i2', 'common', 50]], 9999, 50],
   'i2'),
  ('partial repair boundary #2', [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100], 'i1'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('control #2', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 1], ['i1', 'legendary', 0], ['i2', 'rare', 10]], 1, 50],
   'i0'),
  ('fault site roll scaling #2',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
   'i2'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('control #2', [[['i0', 'common', 50]], 1, 100], 'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 2],
     ['i1', 'legendary', 10],
     ['i2', 'common', 10],
     ['i3', 'common', 5],
     ['i4', 'rare', 10]],
    9999,
    100],
   'i4'),
  ('fault site roll scaling #1',
   [[['i0', 'legendary', 50],
     ['i1', 'common', 2],
     ['i2', 'common', 1],
     ['i3', 'common', 0],
     ['i4', 'legendary', 50]],
    5000,
    250],
   'i1'),
  ('partial repair boundary #1', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 10]], 9999, 130], 'i0'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 50], ['i1', 'legendary', 5], ['i2', 'legendary', 1]], 0, 100], 'i0'),
  ('control #2', [[['i0', 'common', 2]], 0, 0], 'i0')]]
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(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 9999
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('partial repair boundary #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression roll scaling #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0'),
  ('control #2',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('regression roll scaling #1',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('regression roll scaling #2',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'common', 2], ['i2', 'common', 50]], 9999, 50],
   'i2'),
  ('partial repair boundary #2', [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100], 'i1'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('control #2', [[['i0', 'rare', 50], ['i1', 'common', 0]], 1029, -22], 'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site roll scaling #1',
   [[['i0', 'common', 1], ['i1', 'legendary', 0], ['i2', 'rare', 10]], 1, 50],
   'i0'),
  ('fault site roll scaling #2',
   [[['i0', 'rare', 10], ['i1', 'rare', 50], ['i2', 'rare', 5], ['i3', 'common', 10]], 5000, -50],
   'i1'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('partial repair boundary #1',
   [[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
   'i2'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('control #2', [[['i0', 'common', 50]], 1, 100], 'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('regression roll scaling #1',
   [[['i0', 'rare', 2],
     ['i1', 'legendary', 10],
     ['i2', 'common', 10],
     ['i3', 'common', 5],
     ['i4', 'rare', 10]],
    9999,
    100],
   'i4'),
  ('fault site roll scaling #1',
   [[['i0', 'legendary', 50],
     ['i1', 'common', 2],
     ['i2', 'common', 1],
     ['i3', 'common', 0],
     ['i4', 'legendary', 50]],
    5000,
    250],
   'i1'),
  ('partial repair boundary #1', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 10]], 9999, 130], 'i0'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 50], ['i1', 'legendary', 5], ['i2', 'legendary', 1]], 0, 100], 'i0'),
  ('control #2', [[['i0', 'common', 2]], 0, 0], 'i0')]]
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:
Drop rates depend on how the table total divides 10000.

table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.

split: open-access


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

N = 1
observations = []
def solve(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target <= acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative boundary #3', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 1], ['i1', 'legendary', 5], ['i2', 'common', 50], ['i3', 'common', 1]], 9999, 50],
   'i3'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'common', 50], ['i2', 'rare', 5], ['i3', 'common', 0], ['i4', 'legendary', 1]],
    1,
    250],
   'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression cumulative boundary #3',
   [[['i0', 'legendary', 10], ['i1', 'legendary', 0], ['i2', 'rare', 5]], 6788, 100],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('regression cumulative boundary #1', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
  ('regression cumulative boundary #2',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative boundary #3',
   [[['i0', 'rare', 26], ['i1', 'rare', 37], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #4',
   [[['i0', 'rare', 1], ['i1', 'rare', 2], ['i2', 'common', 1], ['i3', 'common', 5], ['i4', 'common', 1]],
    9999,
    50],
   'i4'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w
        if target <= acc and w > 0:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1'),
  ('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'legendary', 0], ['i1', 'common', 5]], 1, 250], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative boundary #3', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('fault site cumulative boundary #2', [[['i0', 'legendary', 0], ['i1', 'legendary', 10]], 0, -26], 'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative boundary #2',
   [[['i0', 'legendary', 1], ['i1', 'legendary', 5], ['i2', 'common', 50], ['i3', 'common', 1]], 9999, 50],
   'i3'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('fault site cumulative boundary #1',
   [[['i0', 'rare', 0], ['i1', 'common', 50], ['i2', 'rare', 5], ['i3', 'common', 0], ['i4', 'legendary', 1]],
    1,
    250],
   'i1'),
  ('regression cumulative boundary #1',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative boundary #2',
   [[['i0', 'rare', 5], ['i1', 'rare', 5], ['i2', 'common', 1], ['i3', 'rare', 0], ['i4', 'legendary', 1]],
    9999,
    -50],
   'i2'),
  ('regression cumulative boundary #3',
   [[['i0', 'legendary', 10], ['i1', 'legendary', 0], ['i2', 'rare', 5]], 6788, 100],
   'i2'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50], 'i0')],
 [('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('regression cumulative boundary #1', [[['i0', 'common', 1], ['i1', 'rare', 1]], 5000, 0], 'i1'),
  ('regression cumulative boundary #2',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative boundary #3',
   [[['i0', 'rare', 26], ['i1', 'rare', 37], ['i2', 'legendary', 50], ['i3', 'legendary', 1]], 9999, 0],
   'i3'),
  ('regression cumulative boundary #4',
   [[['i0', 'rare', 1], ['i1', 'rare', 2], ['i2', 'common', 1], ['i3', 'common', 5], ['i4', 'common', 1]],
    9999,
    50],
   'i4'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')]]
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 exactly at an item boundary drops the earlier item.

table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.

split: open-access


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

N = 1
observations = []
def solve(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w0
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('partial repair boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 1]], 0, -50], 'i0'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('fault site cumulative weight source #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('partial repair boundary #1', [[['i0', 'common', 1]], 0, -50], 'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 0], ['i1', 'common', 5]], 9999, -50], 'i1'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1',
   [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100],
   'i1'),
  ('fault site cumulative weight source #2',
   [[['i0', 'legendary', 2], ['i1', 'legendary', 50], ['i2', 'rare', 10]], 5000, 100],
   'i1'),
  ('partial repair boundary #1',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative weight source #1',
   [[['i0', 'common', 2], ['i1', 'common', 50], ['i2', 'rare', 41], ['i3', 'rare', 50], ['i4', 'common', 2]],
    9999,
    100],
   'i4'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('control #2', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('fault site cumulative weight source #2',
   [[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
   'i2'),
  ('partial repair boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative weight source #1',
   [[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
    5000,
    -50],
   'i2'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('fault site cumulative weight source #2', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
  ('partial repair boundary #1', [[['i0', 'common', 50], ['i1', 'common', 50]], 2592, -50], 'i0'),
  ('partial repair boundary #2',
   [[['i0', 'legendary', 2], ['i1', 'legendary', 2], ['i2', 'common', 10]], 8581, -50],
   'i2'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 50]], 1, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3')]]
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(table, roll, magic_find):
    weights = []
    for item, rarity, w in table:
        if rarity != 'common':
            w = w * (100 + magic_find) // 100
        weights.append(w)
    total = sum(weights)
    if total == 0:
        return None
    target = roll * total // 10000
    acc = 0
    for (item, rarity, w0), w in zip(table, weights):
        acc += w0 * (100 + magic_find) // 100
        if target < acc:
            return item
    return None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('partial repair boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 50], ['i2', 'legendary', 50]], 793, -50],
   'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 1]], 0, -50], 'i0'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 1],
     ['i1', 'rare', 39],
     ['i2', 'legendary', 1],
     ['i3', 'rare', 50],
     ['i4', 'legendary', 5]],
    9999,
    0],
   'i4')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1', [[['i0', 'common', 10], ['i1', 'rare', 50]], 9999, 50], 'i1'),
  ('fault site cumulative weight source #2',
   [[['i0', 'legendary', 1], ['i1', 'common', 5], ['i2', 'legendary', 0], ['i3', 'legendary', 5]], 9999, 50],
   'i3'),
  ('partial repair boundary #1', [[['i0', 'common', 1]], 0, -50], 'i0'),
  ('partial repair boundary #2', [[['i0', 'common', 0], ['i1', 'common', 5]], 9999, -50], 'i1'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'rare', 1], ['i1', 'common', 10], ['i2', 'legendary', 93]], 0, 100], 'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1',
   [[['i0', 'legendary', 50], ['i1', 'rare', 35]], 9999, 100],
   'i1'),
  ('fault site cumulative weight source #2',
   [[['i0', 'legendary', 2], ['i1', 'legendary', 50], ['i2', 'rare', 10]], 5000, 100],
   'i1'),
  ('partial repair boundary #1',
   [[['i0', 'legendary', 0], ['i1', 'common', 0], ['i2', 'common', 50], ['i3', 'common', 50]], 5000, -50],
   'i3'),
  ('regression cumulative weight source #1',
   [[['i0', 'common', 2], ['i1', 'common', 50], ['i2', 'rare', 41], ['i3', 'rare', 50], ['i4', 'common', 2]],
    9999,
    100],
   'i4'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1',
   [[['i0', 'legendary', 10],
     ['i1', 'rare', 50],
     ['i2', 'legendary', 0],
     ['i3', 'common', 2],
     ['i4', 'common', 55]],
    0,
    -50],
   'i0'),
  ('control #2', [[['i0', 'rare', 0], ['i1', 'rare', 1]], 494, 100], 'i1')],
 [('curse lowers rare #1', [[['gem', 'rare', 10], ['rock', 'common', 10]], 4000, -50], 'rock'),
  ('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1',
   [[['i0', 'rare', 5],
     ['i1', 'legendary', 10],
     ['i2', 'legendary', 2],
     ['i3', 'rare', 86],
     ['i4', 'legendary', 1]],
    9999,
    100],
   'i4'),
  ('fault site cumulative weight source #2',
   [[['i0', 'common', 5], ['i1', 'rare', 1], ['i2', 'rare', 5]], 9999, 250],
   'i2'),
  ('partial repair boundary #1',
   [[['i0', 'common', 10], ['i1', 'common', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 1]], 4998, 181],
   'i1'),
  ('regression cumulative weight source #1',
   [[['i0', 'legendary', 50], ['i1', 'legendary', 83], ['i2', 'common', 78], ['i3', 'common', 95]],
    5000,
    -50],
   'i2'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1',
   [[['i0', 'rare', 2], ['i1', 'legendary', 5], ['i2', 'legendary', 2], ['i3', 'legendary', 5]], 0, -50],
   'i0')],
 [('legendary boosted #1', [[['sword', 'common', 90], ['crown', 'legendary', 10]], 9500, 100], 'crown'),
  ('fault site cumulative weight source #1', [[['i0', 'rare', 1], ['i1', 'rare', 2]], 1, -50], 'i1'),
  ('fault site cumulative weight source #2', [[['i0', 'rare', 5]], 9999, 100], 'i0'),
  ('partial repair boundary #1', [[['i0', 'common', 50], ['i1', 'common', 50]], 2592, -50], 'i0'),
  ('partial repair boundary #2',
   [[['i0', 'legendary', 2], ['i1', 'legendary', 2], ['i2', 'common', 10]], 8581, -50],
   'i2'),
  ('zero weight entry skipped #1',
   [[['a', 'common', 1], ['b', 'rare', 0], ['c', 'common', 1]], 5000, 0],
   'c'),
  ('control #1', [[['i0', 'common', 50]], 1, 100], 'i0'),
  ('control #2',
   [[['i0', 'rare', 0], ['i1', 'legendary', 2], ['i2', 'common', 2], ['i3', 'common', 1]], 9999, 0],
   'i3')]]
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:
Magic find changes the total but not which item is chosen.

table = [[item, rarity, weight], ...]. Non-common weights become floor(w*(100+mf)/100) (mf may be negative). With total boosted weight T (None if 0), target = floor(roll*T/10000) for roll 0..9999; return the first item whose cumulative boosted weight exceeds target.

split: open-access


prompt:
Turning quests in one by one keeps paying full rewards all day.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access


prompt:
The first diminished completion pays full reward.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access


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

N = 1
observations = []
def solve(done_today, count, base, player_level, quest_level):
    if player_level - quest_level >= 5:
        gap = 20
    elif player_level - quest_level >= 3:
        gap = 60
    else:
        gap = 100
    out = []
    for k in range(done_today, done_today + count):
        if k < 5:
            tier = 100
        elif k < 15:
            tier = 50
        else:
            tier = 0
        out.append(base * tier * gap // 10000)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [6, 6, 215, 11, 12], [107, 107, 107, 107, 0, 0]),
  ('regression half tier boundary #2', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('regression half tier boundary #3', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('regression half tier boundary #4', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('regression half tier boundary #2', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('regression half tier boundary #4', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('fault site half tier boundary #1', [12, 2, 107, 5, -1], [0, 0]),
  ('regression half tier boundary #1', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('regression half tier boundary #2', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('regression half tier boundary #3', [9, 5, 101, 15, 10], [10, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('regression half tier boundary #2', [9, 5, 101, 15, 10], [10, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [10, 2, 7, 12, 14], [0, 0]),
  ('regression half tier boundary #4', [10, 5, 467, 9, 16], [0, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [10, 2, 7, 12, 14], [0, 0]),
  ('fault site half tier boundary #1', [12, 5, 7, 23, 22], [0, 0, 0, 0, 0]),
  ('regression half tier boundary #2', [10, 5, 467, 9, 16], [0, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [9, 4, 132, 55, 59], [66, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 6, 99, 59, 64], [99, 99, 49, 49, 49, 49])]]
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(done_today, count, base, player_level, quest_level):
    if player_level - quest_level >= 5:
        gap = 20
    elif player_level - quest_level >= 3:
        gap = 60
    else:
        gap = 100
    out = []
    for k in range(done_today, done_today + count):
        if k < 5:
            tier = 100
        elif k <= 10:
            tier = 50
        else:
            tier = 0
        out.append(base * tier * gap // 10000)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [6, 6, 215, 11, 12], [107, 107, 107, 107, 0, 0]),
  ('regression half tier boundary #2', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('regression half tier boundary #3', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('regression half tier boundary #4', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('regression half tier boundary #2', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('regression half tier boundary #4', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('fault site half tier boundary #1', [12, 2, 107, 5, -1], [0, 0]),
  ('regression half tier boundary #1', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('regression half tier boundary #2', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('regression half tier boundary #3', [9, 5, 101, 15, 10], [10, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 4, 101, 31, 28], [60, 60, 30, 30])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [8, 4, 99, 29, 33], [49, 49, 0, 0]),
  ('regression half tier boundary #2', [9, 5, 101, 15, 10], [10, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [10, 2, 7, 12, 14], [0, 0]),
  ('regression half tier boundary #4', [10, 5, 467, 9, 16], [0, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('regression half tier boundary #1', [10, 2, 7, 12, 14], [0, 0]),
  ('fault site half tier boundary #1', [12, 5, 7, 23, 22], [0, 0, 0, 0, 0]),
  ('regression half tier boundary #2', [10, 5, 467, 9, 16], [0, 0, 0, 0, 0]),
  ('regression half tier boundary #3', [9, 4, 132, 55, 59], [66, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('control #1', [3, 6, 99, 59, 64], [99, 99, 49, 49, 49, 49])]]
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:
Players farm five extra half-reward completions.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access


prompt:
Quests far above the player pay the gray-quest penalty.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access


prompt:
Gray quests pay the 60% green reward.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access


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

N = 1
observations = []
def solve(done_today, count, base, player_level, quest_level):
    if player_level - quest_level >= 5:
        gap = 20
    elif player_level - quest_level >= 3:
        gap = 60
    else:
        gap = 100
    out = []
    for k in range(done_today, done_today + count):
        if k < 5:
            tier = 100
        elif k < 10:
            tier = 50
        else:
            tier = 0
        out.append(base * tier // 100 * gap // 100)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [2, 4, 7, 16, 12], [4, 4, 4, 2]),
  ('fault site reward rounding stage #2', [2, 5, 7, 20, 16], [4, 4, 4, 2, 2]),
  ('partial repair boundary #1', [6, 6, 215, 11, 12], [107, 107, 107, 107, 0, 0]),
  ('partial repair boundary #2', [3, 4, 101, 31, 28], [60, 60, 30, 30]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [8, 6, 7, 23, 19], [2, 2, 0, 0, 0, 0]),
  ('fault site reward rounding stage #2', [3, 6, 7, 49, 46], [4, 4, 2, 2, 2, 2]),
  ('partial repair boundary #1', [3, 4, 101, 31, 28], [60, 60, 30, 30]),
  ('partial repair boundary #2', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [7, 4, 7, 51, 48], [2, 2, 2, 0]),
  ('fault site reward rounding stage #2', [1, 6, 7, 18, 14], [4, 4, 4, 4, 2, 2]),
  ('partial repair boundary #1', [3, 6, 99, 59, 64], [99, 99, 49, 49, 49, 49]),
  ('partial repair boundary #2', [7, 1, 7, 40, 47], [3]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [9, 4, 267, 56, 53], [80, 0, 0, 0]),
  ('fault site reward rounding stage #2', [2, 4, 7, 16, 12], [4, 4, 4, 2]),
  ('partial repair boundary #1', [1, 6, 7, 45, 37], [1, 1, 1, 1, 0, 0]),
  ('partial repair boundary #2', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [11, 1, 1, 10, 16], [0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [2, 5, 7, 20, 16], [4, 4, 4, 2, 2]),
  ('fault site reward rounding stage #2', [8, 6, 7, 23, 19], [2, 2, 0, 0, 0, 0]),
  ('partial repair boundary #1', [2, 6, 99, 10, 9], [99, 99, 99, 49, 49, 49]),
  ('partial repair boundary #2', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [12, 2, 107, 5, -1], [0, 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(done_today, count, base, player_level, quest_level):
    if player_level - quest_level >= 5:
        gap = 20
    elif player_level - quest_level >= 3:
        gap = 60
    else:
        gap = 100
    out = []
    for k in range(done_today, done_today + count):
        if k < 5:
            tier = 100
        elif k < 10:
            tier = 50
        else:
            tier = 0
        out.append(round(base * tier * gap / 10000))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [2, 4, 7, 16, 12], [4, 4, 4, 2]),
  ('fault site reward rounding stage #2', [2, 5, 7, 20, 16], [4, 4, 4, 2, 2]),
  ('partial repair boundary #1', [6, 6, 215, 11, 12], [107, 107, 107, 107, 0, 0]),
  ('partial repair boundary #2', [3, 4, 101, 31, 28], [60, 60, 30, 30]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [8, 6, 7, 23, 19], [2, 2, 0, 0, 0, 0]),
  ('fault site reward rounding stage #2', [3, 6, 7, 49, 46], [4, 4, 2, 2, 2, 2]),
  ('partial repair boundary #1', [3, 4, 101, 31, 28], [60, 60, 30, 30]),
  ('partial repair boundary #2', [9, 4, 3, 24, 23], [1, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [7, 4, 7, 51, 48], [2, 2, 2, 0]),
  ('fault site reward rounding stage #2', [1, 6, 7, 18, 14], [4, 4, 4, 4, 2, 2]),
  ('partial repair boundary #1', [3, 6, 99, 59, 64], [99, 99, 49, 49, 49, 49]),
  ('partial repair boundary #2', [7, 1, 7, 40, 47], [3]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [8, 2, 1, 33, 25], [0, 0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [9, 4, 267, 56, 53], [80, 0, 0, 0]),
  ('fault site reward rounding stage #2', [2, 4, 7, 16, 12], [4, 4, 4, 2]),
  ('partial repair boundary #1', [1, 6, 7, 45, 37], [1, 1, 1, 1, 0, 0]),
  ('partial repair boundary #2', [8, 6, 99, 11, 18], [49, 49, 0, 0, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [11, 1, 1, 10, 16], [0])],
 [('gray quest #1', [0, 2, 99, 30, 25], [19, 19]),
  ('fault site reward rounding stage #1', [2, 5, 7, 20, 16], [4, 4, 4, 2, 2]),
  ('fault site reward rounding stage #2', [8, 6, 7, 23, 19], [2, 2, 0, 0, 0, 0]),
  ('partial repair boundary #1', [2, 6, 99, 10, 9], [99, 99, 99, 49, 49, 49]),
  ('partial repair boundary #2', [8, 4, 99, 8, 6], [49, 49, 0, 0]),
  ('crossing into half tier #1', [3, 4, 101, 20, 20], [101, 101, 50, 50]),
  ('harder quest no penalty #1', [8, 3, 50, 10, 18], [25, 25, 0]),
  ('control #1', [12, 2, 107, 5, -1], [0, 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:
Odd base rewards lose a coin on diminished gray quests.

Completion k (0-based across the day, starting at done_today) pays tier 100% for k < 5, 50% for 5 <= k < 10, 0 after. Gap = player_level - quest_level: >= 5 pays 20%, >= 3 pays 60%, otherwise 100% (higher level quests are never penalized). Each reward = floor(base*tier*gap/10000). Returns the list of the next count rewards.

split: open-access