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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = listing['price'] * 5 // 100
        net = listing['price'] - cut
    elif status == 'cancelled':
        net = -deposit - outcome.get('bid', 0) * 5 // 100
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('partial repair boundary #1',
   [{'price': 1, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 1}),
  ('partial repair boundary #2',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('fault site cut rounding #2',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('partial repair boundary #1',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('partial repair boundary #2',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('fault site cut rounding #2',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('partial repair boundary #1',
   [{'price': 72766, 'hours': 24, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 2, 'net': 69128}),
  ('partial repair boundary #2',
   [{'price': 9, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 190, 'hours': 12, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('partial repair boundary #1',
   [{'price': 9, 'hours': 48, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('partial repair boundary #2',
   [{'price': 74548, 'hours': 48, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 4, 'net': 70821}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 12, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 70012, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 66511}),
  ('partial repair boundary #1',
   [{'price': 9, 'hours': 48, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('partial repair boundary #2',
   [{'price': 1, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 1}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = (listing['price'] * 5 + 99) // 100
        net = listing['price'] - cut
    elif status == 'cancelled':
        net = -deposit - outcome.get('bid', 0) * 5 // 100
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('partial repair boundary #1',
   [{'price': 1, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 1}),
  ('partial repair boundary #2',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('fault site cut rounding #2',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('partial repair boundary #1',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('partial repair boundary #2',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('fault site cut rounding #2',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('partial repair boundary #1',
   [{'price': 72766, 'hours': 24, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 2, 'net': 69128}),
  ('partial repair boundary #2',
   [{'price': 9, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 190, 'hours': 12, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('partial repair boundary #1',
   [{'price': 9, 'hours': 48, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('partial repair boundary #2',
   [{'price': 74548, 'hours': 48, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 4, 'net': 70821}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('fault site cut rounding #1',
   [{'price': 30, 'hours': 12, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('fault site cut rounding #2',
   [{'price': 70012, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 66511}),
  ('partial repair boundary #1',
   [{'price': 9, 'hours': 48, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('partial repair boundary #2',
   [{'price': 1, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 1}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Sales exactly on a half-copper cut pay too little fee.

Deposit = per_block * (hours//12) where per_block = max(1, floor(stack_value*15/100)). Sold: net = price - cut with cut = 5% of price rounded half up (deposit refunded). Expired: net = -deposit. Cancelled: net = -deposit - floor(bid*5/100) (bid defaults to 0). Returns {deposit, net} in copper.

split: open-access


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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = (listing['price'] * 5 + 50) // 100
        net = listing['price'] - cut - deposit
    elif status == 'cancelled':
        net = -deposit - outcome.get('bid', 0) * 5 // 100
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 1, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 1}),
  ('regression deposit refund on sale #2',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('regression deposit refund on sale #3',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('regression deposit refund on sale #4',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('regression deposit refund on sale #2',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('regression deposit refund on sale #3',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('regression deposit refund on sale #4',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('regression deposit refund on sale #2',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('regression deposit refund on sale #3',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('regression deposit refund on sale #4',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('regression deposit refund on sale #2',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('regression deposit refund on sale #3',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('regression deposit refund on sale #4',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('regression deposit refund on sale #2',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('regression deposit refund on sale #3',
   [{'price': 72766, 'hours': 24, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 2, 'net': 69128}),
  ('regression deposit refund on sale #4',
   [{'price': 30, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = (listing['price'] * 5 + 50) // 100
        net = listing['price'] - cut - per_block
    elif status == 'cancelled':
        net = -deposit - outcome.get('bid', 0) * 5 // 100
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 1, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 1}),
  ('regression deposit refund on sale #2',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('regression deposit refund on sale #3',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('regression deposit refund on sale #4',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 30, 'hours': 12, 'stack_value': 6}, {'status': 'sold'}],
   {'deposit': 1, 'net': 28}),
  ('regression deposit refund on sale #2',
   [{'price': 190, 'hours': 12, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 1, 'net': 180}),
  ('regression deposit refund on sale #3',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('regression deposit refund on sale #4',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 30, 'hours': 24, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('regression deposit refund on sale #2',
   [{'price': 5141, 'hours': 12, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 1, 'net': 4884}),
  ('regression deposit refund on sale #3',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('regression deposit refund on sale #4',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 34146, 'hours': 48, 'stack_value': 3106}, {'status': 'sold'}],
   {'deposit': 1860, 'net': 32439}),
  ('regression deposit refund on sale #2',
   [{'price': 10, 'hours': 24, 'stack_value': 0}, {'status': 'sold'}],
   {'deposit': 2, 'net': 9}),
  ('regression deposit refund on sale #3',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('regression deposit refund on sale #4',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('regression deposit refund on sale #1',
   [{'price': 9, 'hours': 48, 'stack_value': 1}, {'status': 'sold'}],
   {'deposit': 4, 'net': 9}),
  ('regression deposit refund on sale #2',
   [{'price': 91070, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 86516}),
  ('regression deposit refund on sale #3',
   [{'price': 72766, 'hours': 24, 'stack_value': 13}, {'status': 'sold'}],
   {'deposit': 2, 'net': 69128}),
  ('regression deposit refund on sale #4',
   [{'price': 30, 'hours': 24, 'stack_value': 7}, {'status': 'sold'}],
   {'deposit': 2, 'net': 28}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Successful sellers lose their deposit as if the listing expired.

Deposit = per_block * (hours//12) where per_block = max(1, floor(stack_value*15/100)). Sold: net = price - cut with cut = 5% of price rounded half up (deposit refunded). Expired: net = -deposit. Cancelled: net = -deposit - floor(bid*5/100) (bid defaults to 0). Returns {deposit, net} in copper.

split: open-access


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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = (listing['price'] * 5 + 50) // 100
        net = listing['price'] - cut
    elif status == 'cancelled':
        net = -deposit
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('fault site cancellation penalty #1',
   [{'price': 10, 'hours': 12, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('partial repair boundary #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2}),
  ('partial repair boundary #2',
   [{'price': 1, 'hours': 12, 'stack_value': 4743}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 711, 'net': -711}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('fault site cancellation penalty #1',
   [{'price': 10, 'hours': 12, 'stack_value': 13}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('partial repair boundary #1',
   [{'price': 1, 'hours': 12, 'stack_value': 4743}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 711, 'net': -711}),
  ('partial repair boundary #2',
   [{'price': 190, 'hours': 12, 'stack_value': 13}, {'status': 'cancelled'}],
   {'deposit': 1, 'net': -1}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 323}],
   {'deposit': 2, 'net': -18}),
  ('regression cancellation penalty #2',
   [{'price': 11, 'hours': 12, 'stack_value': 6}, {'status': 'cancelled', 'bid': 20}],
   {'deposit': 1, 'net': -2}),
  ('partial repair boundary #1',
   [{'price': 912, 'hours': 24, 'stack_value': 0}, {'status': 'cancelled'}],
   {'deposit': 2, 'net': -2}),
  ('regression cancellation penalty #3',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 24, 'stack_value': 1}, {'status': 'cancelled', 'bid': 2339}],
   {'deposit': 2, 'net': -118}),
  ('regression cancellation penalty #2',
   [{'price': 1, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 2, 'net': -6}),
  ('regression cancellation penalty #3',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 323}],
   {'deposit': 2, 'net': -18}),
  ('regression cancellation penalty #4',
   [{'price': 11, 'hours': 12, 'stack_value': 6}, {'status': 'cancelled', 'bid': 20}],
   {'deposit': 1, 'net': -2}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('fault site cancellation penalty #1',
   [{'price': 1, 'hours': 12, 'stack_value': 1}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('fault site cancellation penalty #2',
   [{'price': 50, 'hours': 12, 'stack_value': 1}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('partial repair boundary #1',
   [{'price': 30, 'hours': 48, 'stack_value': 2507}, {'status': 'cancelled', 'bid': 19}],
   {'deposit': 1504, 'net': -1504}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 24, 'stack_value': 1}, {'status': 'cancelled', 'bid': 2339}],
   {'deposit': 2, 'net': -118}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 11, 'hours': 12, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 1, 'net': -1})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(listing, outcome):
    blocks = listing['hours'] // 12
    per_block = max(1, listing['stack_value'] * 15 // 100)
    deposit = per_block * blocks
    status = outcome['status']
    if status == 'sold':
        cut = (listing['price'] * 5 + 50) // 100
        net = listing['price'] - cut
    elif status == 'cancelled':
        net = -outcome.get('bid', 0) * 5 // 100
    else:
        net = -deposit
    return {'deposit': deposit, 'net': net}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('fault site cancellation penalty #1',
   [{'price': 10, 'hours': 12, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('partial repair boundary #1',
   [{'price': 11, 'hours': 24, 'stack_value': 13}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 2, 'net': -2}),
  ('partial repair boundary #2',
   [{'price': 1, 'hours': 12, 'stack_value': 4743}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 711, 'net': -711}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('fault site cancellation penalty #1',
   [{'price': 10, 'hours': 12, 'stack_value': 13}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('partial repair boundary #1',
   [{'price': 1, 'hours': 12, 'stack_value': 4743}, {'status': 'cancelled', 'bid': 0}],
   {'deposit': 711, 'net': -711}),
  ('partial repair boundary #2',
   [{'price': 190, 'hours': 12, 'stack_value': 13}, {'status': 'cancelled'}],
   {'deposit': 1, 'net': -1}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 323}],
   {'deposit': 2, 'net': -18}),
  ('regression cancellation penalty #2',
   [{'price': 11, 'hours': 12, 'stack_value': 6}, {'status': 'cancelled', 'bid': 20}],
   {'deposit': 1, 'net': -2}),
  ('partial repair boundary #1',
   [{'price': 912, 'hours': 24, 'stack_value': 0}, {'status': 'cancelled'}],
   {'deposit': 2, 'net': -2}),
  ('regression cancellation penalty #3',
   [{'price': 190, 'hours': 48, 'stack_value': 0}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 4, 'net': -8}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 10, 'hours': 48, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 24, 'stack_value': 1}, {'status': 'cancelled', 'bid': 2339}],
   {'deposit': 2, 'net': -118}),
  ('regression cancellation penalty #2',
   [{'price': 1, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 2, 'net': -6}),
  ('regression cancellation penalty #3',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'cancelled', 'bid': 323}],
   {'deposit': 2, 'net': -18}),
  ('regression cancellation penalty #4',
   [{'price': 11, 'hours': 12, 'stack_value': 6}, {'status': 'cancelled', 'bid': 20}],
   {'deposit': 1, 'net': -2}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 50, 'hours': 24, 'stack_value': 6}, {'status': 'expired'}],
   {'deposit': 2, 'net': -2})],
 [('cancel with bid #1',
   [{'price': 500, 'hours': 24, 'stack_value': 40}, {'status': 'cancelled', 'bid': 390}],
   {'deposit': 12, 'net': -31}),
  ('fault site cancellation penalty #1',
   [{'price': 1, 'hours': 12, 'stack_value': 1}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('fault site cancellation penalty #2',
   [{'price': 50, 'hours': 12, 'stack_value': 1}, {'status': 'cancelled', 'bid': 99}],
   {'deposit': 1, 'net': -5}),
  ('partial repair boundary #1',
   [{'price': 30, 'hours': 48, 'stack_value': 2507}, {'status': 'cancelled', 'bid': 19}],
   {'deposit': 1504, 'net': -1504}),
  ('regression cancellation penalty #1',
   [{'price': 190, 'hours': 24, 'stack_value': 1}, {'status': 'cancelled', 'bid': 2339}],
   {'deposit': 2, 'net': -118}),
  ('long cheap listing #1',
   [{'price': 10, 'hours': 48, 'stack_value': 3}, {'status': 'expired'}],
   {'deposit': 4, 'net': -4}),
  ('half-up cut boundary #1',
   [{'price': 10, 'hours': 12, 'stack_value': 100}, {'status': 'sold'}],
   {'deposit': 15, 'net': 9}),
  ('control #1',
   [{'price': 11, 'hours': 12, 'stack_value': 0}, {'status': 'expired'}],
   {'deposit': 1, 'net': -1})]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Sellers cancel listings with bids without the bid penalty.

Deposit = per_block * (hours//12) where per_block = max(1, floor(stack_value*15/100)). Sold: net = price - cut with cut = 5% of price rounded half up (deposit refunded). Expired: net = -deposit. Cancelled: net = -deposit - floor(bid*5/100) (bid defaults to 0). Returns {deposit, net} in copper.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = it['max'] - it['dur']
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) / 100
    cost = math.ceil(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0]),
  ('regression missing durability clamp #2', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 113, 'dur': 123, 'max': 120}, {'ilvl': 8, 'dur': 103, 'max': 100}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 0, 0]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 113, 'dur': 123, 'max': 120}, {'ilvl': 8, 'dur': 103, 'max': 100}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 1, 'dur': 123, 'max': 120},
     {'ilvl': 7, 'dur': 61, 'max': 120},
     {'ilvl': 3, 'dur': 120, 'max': 120},
     {'ilvl': 374, 'dur': 38, 'max': 100}],
    []],
   [0, 59, 46]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 1, 'dur': 123, 'max': 120},
     {'ilvl': 7, 'dur': 61, 'max': 120},
     {'ilvl': 3, 'dur': 120, 'max': 120},
     {'ilvl': 374, 'dur': 38, 'max': 100}],
    []],
   [0, 59, 46]),
  ('regression missing durability clamp #3', [[{'ilvl': 1, 'dur': 63, 'max': 60}], []], [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 8, 'dur': 103, 'max': 100}, {'ilvl': 204, 'dur': 26, 'max': 60}], []],
   [0, 17, 68]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1', [[{'ilvl': 1, 'dur': 63, 'max': 60}], []], [0, 0, 0]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 8, 'dur': 103, 'max': 100}, {'ilvl': 204, 'dur': 26, 'max': 60}], []],
   [0, 17, 68]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 1, 'dur': 123, 'max': 120}, {'ilvl': 1, 'dur': 123, 'max': 120}], [15]],
   [0, 0, 0]),
  ('regression missing durability clamp #4', [[{'ilvl': 1, 'dur': 123, 'max': 120}], [25, 20]], [0, 0, 0]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 8, 'dur': 18, 'max': 120}, {'ilvl': 3, 'dur': 41, 'max': 60}], [20]],
   [0, 2, 60])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 1, 'dur': 123, 'max': 120}, {'ilvl': 1, 'dur': 123, 'max': 120}], [15]],
   [0, 0, 0]),
  ('regression missing durability clamp #2', [[{'ilvl': 1, 'dur': 123, 'max': 120}], [25, 20]], [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 8, 'dur': 63, 'max': 60}, {'ilvl': 3, 'dur': 43, 'max': 40}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 346, 'dur': 120, 'max': 120},
     {'ilvl': 3, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 43, 'max': 40}],
    []],
   [0, 0, 0]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92])]]
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = abs(it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) / 100
    cost = math.ceil(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0]),
  ('regression missing durability clamp #2', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 113, 'dur': 123, 'max': 120}, {'ilvl': 8, 'dur': 103, 'max': 100}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 0, 0]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 113, 'dur': 123, 'max': 120}, {'ilvl': 8, 'dur': 103, 'max': 100}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 1, 'dur': 123, 'max': 120},
     {'ilvl': 7, 'dur': 61, 'max': 120},
     {'ilvl': 3, 'dur': 120, 'max': 120},
     {'ilvl': 374, 'dur': 38, 'max': 100}],
    []],
   [0, 59, 46]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 1, 'dur': 123, 'max': 120},
     {'ilvl': 7, 'dur': 61, 'max': 120},
     {'ilvl': 3, 'dur': 120, 'max': 120},
     {'ilvl': 374, 'dur': 38, 'max': 100}],
    []],
   [0, 59, 46]),
  ('regression missing durability clamp #3', [[{'ilvl': 1, 'dur': 63, 'max': 60}], []], [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 8, 'dur': 103, 'max': 100}, {'ilvl': 204, 'dur': 26, 'max': 60}], []],
   [0, 17, 68]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1', [[{'ilvl': 1, 'dur': 63, 'max': 60}], []], [0, 0, 0]),
  ('regression missing durability clamp #2',
   [[{'ilvl': 8, 'dur': 103, 'max': 100}, {'ilvl': 204, 'dur': 26, 'max': 60}], []],
   [0, 17, 68]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 1, 'dur': 123, 'max': 120}, {'ilvl': 1, 'dur': 123, 'max': 120}], [15]],
   [0, 0, 0]),
  ('regression missing durability clamp #4', [[{'ilvl': 1, 'dur': 123, 'max': 120}], [25, 20]], [0, 0, 0]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 8, 'dur': 18, 'max': 120}, {'ilvl': 3, 'dur': 41, 'max': 60}], [20]],
   [0, 2, 60])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression missing durability clamp #1',
   [[{'ilvl': 1, 'dur': 123, 'max': 120}, {'ilvl': 1, 'dur': 123, 'max': 120}], [15]],
   [0, 0, 0]),
  ('regression missing durability clamp #2', [[{'ilvl': 1, 'dur': 123, 'max': 120}], [25, 20]], [0, 0, 0]),
  ('regression missing durability clamp #3',
   [[{'ilvl': 8, 'dur': 63, 'max': 60}, {'ilvl': 3, 'dur': 43, 'max': 40}], []],
   [0, 0, 0]),
  ('regression missing durability clamp #4',
   [[{'ilvl': 346, 'dur': 120, 'max': 120},
     {'ilvl': 3, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 43, 'max': 40}],
    []],
   [0, 0, 0]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92])]]
for label, args, expected in cases[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Items above maximum durability reduce the cost of other repairs.

Per item cost = max(0, max-dur) * (ilvl//4 + 1) copper. Discount percentages stack multiplicatively on the exact total; the result is rounded up once to copper. Return [gold, silver, copper] with 100 copper per silver and 100 silver per gold.

split: open-access


prompt:
Items below item level 4 cost nothing to repair.

Per item cost = max(0, max-dur) * (ilvl//4 + 1) copper. Discount percentages stack multiplicatively on the exact total; the result is rounded up once to copper. Return [gold, silver, copper] with 100 copper per silver and 100 silver per gold.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = max(0, it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price - Fraction(total) * pct / 100
    cost = math.ceil(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('regression discount stacking #2',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('partial repair boundary #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('partial repair boundary #2',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('regression discount stacking #2',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('partial repair boundary #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('partial repair boundary #2',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('regression discount stacking #2',
   [[{'ilvl': 3, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 7, 'dur': 13, 'max': 100},
     {'ilvl': 3, 'dur': 0, 'max': 100}],
    [10, 15]],
   [0, 2, 10]),
  ('partial repair boundary #1',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('regression discount stacking #3',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1', [[{'ilvl': 3, 'dur': 0, 'max': 120}], [15, 15, 15]], [0, 0, 74]),
  ('regression discount stacking #2',
   [[{'ilvl': 14, 'dur': 0, 'max': 40}, {'ilvl': 4, 'dur': 43, 'max': 40}], [25, 10, 15]],
   [0, 0, 92]),
  ('regression discount stacking #3',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('partial repair boundary #1', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 8, 'dur': 0, 'max': 100},
     {'ilvl': 3, 'dur': 0, 'max': 100},
     {'ilvl': 8, 'dur': 100, 'max': 100}],
    [10, 10, 10]],
   [0, 2, 92]),
  ('regression discount stacking #2',
   [[{'ilvl': 8, 'dur': 0, 'max': 120}, {'ilvl': 4, 'dur': 63, 'max': 60}, {'ilvl': 7, 'dur': 60, 'max': 60}],
    [10, 33]],
   [0, 2, 18]),
  ('regression discount stacking #3',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('partial repair boundary #1',
   [[{'ilvl': 7, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 37, 'max': 40},
     {'ilvl': 7, 'dur': 103, 'max': 100}],
    [25, 15]],
   [0, 0, 2]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 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
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = max(0, it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) // 100
    cost = math.ceil(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('regression discount stacking #2',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('partial repair boundary #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('partial repair boundary #2',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('regression discount stacking #2',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('partial repair boundary #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('partial repair boundary #2',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('regression discount stacking #2',
   [[{'ilvl': 3, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 7, 'dur': 13, 'max': 100},
     {'ilvl': 3, 'dur': 0, 'max': 100}],
    [10, 15]],
   [0, 2, 10]),
  ('partial repair boundary #1',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('regression discount stacking #3',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1', [[{'ilvl': 3, 'dur': 0, 'max': 120}], [15, 15, 15]], [0, 0, 74]),
  ('regression discount stacking #2',
   [[{'ilvl': 14, 'dur': 0, 'max': 40}, {'ilvl': 4, 'dur': 43, 'max': 40}], [25, 10, 15]],
   [0, 0, 92]),
  ('regression discount stacking #3',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('partial repair boundary #1', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression discount stacking #1',
   [[{'ilvl': 8, 'dur': 0, 'max': 100},
     {'ilvl': 3, 'dur': 0, 'max': 100},
     {'ilvl': 8, 'dur': 100, 'max': 100}],
    [10, 10, 10]],
   [0, 2, 92]),
  ('regression discount stacking #2',
   [[{'ilvl': 8, 'dur': 0, 'max': 120}, {'ilvl': 4, 'dur': 63, 'max': 60}, {'ilvl': 7, 'dur': 60, 'max': 60}],
    [10, 33]],
   [0, 2, 18]),
  ('regression discount stacking #3',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('partial repair boundary #1',
   [[{'ilvl': 7, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 37, 'max': 40},
     {'ilvl': 7, 'dur': 103, 'max': 100}],
    [25, 15]],
   [0, 0, 2]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 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:
Two discounts together are worth more than applying them in turn.

Per item cost = max(0, max-dur) * (ilvl//4 + 1) copper. Discount percentages stack multiplicatively on the exact total; the result is rounded up once to copper. Return [gold, silver, copper] with 100 copper per silver and 100 silver per gold.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = max(0, it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) / 100
    cost = int(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('fault site final rounding #2',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression final rounding #1',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('regression final rounding #2',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression final rounding #1',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('regression final rounding #2',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('regression final rounding #3',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression final rounding #1',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('fault site final rounding #1',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('regression final rounding #2', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('regression final rounding #3',
   [[{'ilvl': 1, 'dur': 69, 'max': 120},
     {'ilvl': 254, 'dur': 20, 'max': 60},
     {'ilvl': 7, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 103, 'max': 100}],
    [33]],
   [0, 19, 11]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression final rounding #1',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('regression final rounding #2', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('regression final rounding #3',
   [[{'ilvl': 8, 'dur': 0, 'max': 120}, {'ilvl': 4, 'dur': 63, 'max': 60}, {'ilvl': 7, 'dur': 60, 'max': 60}],
    [10, 33]],
   [0, 2, 18]),
  ('regression final rounding #4',
   [[{'ilvl': 7, 'dur': 44, 'max': 120}, {'ilvl': 8, 'dur': 60, 'max': 60}], [5, 15, 10]],
   [0, 1, 11]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('fault site final rounding #2',
   [[{'ilvl': 7, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 37, 'max': 40},
     {'ilvl': 7, 'dur': 103, 'max': 100}],
    [25, 15]],
   [0, 0, 2]),
  ('regression final rounding #1',
   [[{'ilvl': 7, 'dur': 0, 'max': 100}, {'ilvl': 4, 'dur': 44, 'max': 60}], [20, 20]],
   [0, 1, 49]),
  ('regression final rounding #2',
   [[{'ilvl': 8, 'dur': 120, 'max': 120},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 8, 'dur': 16, 'max': 40},
     {'ilvl': 1, 'dur': 120, 'max': 120}],
    [5, 25, 20]],
   [0, 0, 99]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 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
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = max(0, it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) / 100
    cost = round(price)
    return [cost // 10000, cost // 100 % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('fault site final rounding #2',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression final rounding #1',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('regression final rounding #2',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('regression final rounding #1',
   [[{'ilvl': 113, 'dur': 4, 'max': 40},
     {'ilvl': 84, 'dur': 100, 'max': 100},
     {'ilvl': 276, 'dur': 62, 'max': 100},
     {'ilvl': 4, 'dur': 0, 'max': 120}],
    [33]],
   [0, 26, 43]),
  ('regression final rounding #2',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('regression final rounding #3',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression final rounding #1',
   [[{'ilvl': 1, 'dur': 47, 'max': 60},
     {'ilvl': 3, 'dur': 97, 'max': 120},
     {'ilvl': 4, 'dur': 103, 'max': 100}],
    [10]],
   [0, 0, 33]),
  ('fault site final rounding #1',
   [[{'ilvl': 377, 'dur': 103, 'max': 100},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 1, 'dur': 5, 'max': 60}],
    [15, 10]],
   [0, 1, 19]),
  ('regression final rounding #2', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('regression final rounding #3',
   [[{'ilvl': 1, 'dur': 69, 'max': 120},
     {'ilvl': 254, 'dur': 20, 'max': 60},
     {'ilvl': 7, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 103, 'max': 100}],
    [33]],
   [0, 19, 11]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('regression final rounding #1',
   [[{'ilvl': 4, 'dur': 29, 'max': 100}, {'ilvl': 7, 'dur': 0, 'max': 100}], [20, 10]],
   [0, 2, 47]),
  ('regression final rounding #2', [[{'ilvl': 1, 'dur': 89, 'max': 100}], [33]], [0, 0, 8]),
  ('regression final rounding #3',
   [[{'ilvl': 8, 'dur': 0, 'max': 120}, {'ilvl': 4, 'dur': 63, 'max': 60}, {'ilvl': 7, 'dur': 60, 'max': 60}],
    [10, 33]],
   [0, 2, 18]),
  ('regression final rounding #4',
   [[{'ilvl': 7, 'dur': 44, 'max': 120}, {'ilvl': 8, 'dur': 60, 'max': 60}], [5, 15, 10]],
   [0, 1, 11]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('fault site final rounding #1',
   [[{'ilvl': 8, 'dur': 43, 'max': 40},
     {'ilvl': 7, 'dur': 0, 'max': 40},
     {'ilvl': 316, 'dur': 123, 'max': 120}],
    [15, 25, 10]],
   [0, 0, 46]),
  ('fault site final rounding #2',
   [[{'ilvl': 7, 'dur': 100, 'max': 100},
     {'ilvl': 1, 'dur': 37, 'max': 40},
     {'ilvl': 7, 'dur': 103, 'max': 100}],
    [25, 15]],
   [0, 0, 2]),
  ('regression final rounding #1',
   [[{'ilvl': 7, 'dur': 0, 'max': 100}, {'ilvl': 4, 'dur': 44, 'max': 60}], [20, 20]],
   [0, 1, 49]),
  ('regression final rounding #2',
   [[{'ilvl': 8, 'dur': 120, 'max': 120},
     {'ilvl': 1, 'dur': 0, 'max': 100},
     {'ilvl': 8, 'dur': 16, 'max': 40},
     {'ilvl': 1, 'dur': 120, 'max': 120}],
    [5, 25, 20]],
   [0, 0, 99]),
  ('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 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:
Discounted repairs are a copper cheaper than the ceiling rule.

Per item cost = max(0, max-dur) * (ilvl//4 + 1) copper. Discount percentages stack multiplicatively on the exact total; the result is rounded up once to copper. Return [gold, silver, copper] with 100 copper per silver and 100 silver per gold.

split: open-access


source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(items, discounts):
    total = 0
    for it in items:
        missing = max(0, it['max'] - it['dur'])
        total += missing * (it['ilvl'] // 4 + 1)
    price = Fraction(total)
    for pct in discounts:
        price = price * (100 - pct) / 100
    cost = math.ceil(price)
    return [cost // 10000, round(cost / 100) % 100, cost % 100]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression silver denomination #1',
   [[{'ilvl': 367, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 41, 'max': 120},
     {'ilvl': 7, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 100, 'max': 100}],
    [5]],
   [1, 5, 64]),
  ('partial repair boundary #1',
   [[{'ilvl': 8, 'dur': 18, 'max': 120}, {'ilvl': 3, 'dur': 41, 'max': 60}], [20]],
   [0, 2, 60]),
  ('partial repair boundary #2',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0]),
  ('control #2',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression silver denomination #1',
   [[{'ilvl': 367, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 41, 'max': 120},
     {'ilvl': 7, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 100, 'max': 100}],
    [5]],
   [1, 5, 64]),
  ('partial repair boundary #1',
   [[{'ilvl': 1, 'dur': 120, 'max': 120},
     {'ilvl': 4, 'dur': 84, 'max': 100},
     {'ilvl': 3, 'dur': 40, 'max': 40},
     {'ilvl': 3, 'dur': 0, 'max': 120}],
    [10, 33]],
   [0, 0, 92]),
  ('partial repair boundary #2',
   [[{'ilvl': 69, 'dur': 5, 'max': 40},
     {'ilvl': 3, 'dur': 49, 'max': 120},
     {'ilvl': 139, 'dur': 63, 'max': 60}],
    [15]],
   [0, 5, 96]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 40, 'max': 40}], [20]], [0, 0, 0]),
  ('control #2',
   [[{'ilvl': 4, 'dur': 63, 'max': 60},
     {'ilvl': 130, 'dur': 63, 'max': 60},
     {'ilvl': 3, 'dur': 60, 'max': 60}],
    [25, 25]],
   [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression silver denomination #1',
   [[{'ilvl': 367, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 41, 'max': 120},
     {'ilvl': 7, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 100, 'max': 100}],
    [5]],
   [1, 5, 64]),
  ('partial repair boundary #1', [[{'ilvl': 4, 'dur': 0, 'max': 60}], [25]], [0, 0, 90]),
  ('partial repair boundary #2',
   [[{'ilvl': 8, 'dur': 103, 'max': 100}, {'ilvl': 204, 'dur': 26, 'max': 60}], []],
   [0, 17, 68]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 111, 'dur': 123, 'max': 120}], []], [0, 0, 0]),
  ('control #2',
   [[{'ilvl': 113, 'dur': 123, 'max': 120}, {'ilvl': 8, 'dur': 103, 'max': 100}], []],
   [0, 0, 0])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression silver denomination #1',
   [[{'ilvl': 367, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 41, 'max': 120},
     {'ilvl': 7, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 100, 'max': 100}],
    [5]],
   [1, 5, 64]),
  ('partial repair boundary #1', [[{'ilvl': 7, 'dur': 0, 'max': 40}], []], [0, 0, 80]),
  ('partial repair boundary #2', [[{'ilvl': 3, 'dur': 0, 'max': 120}], [15, 15, 15]], [0, 0, 74]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[{'ilvl': 7, 'dur': 0, 'max': 100}, {'ilvl': 3, 'dur': 78, 'max': 120}], []], [0, 2, 42]),
  ('control #2',
   [[{'ilvl': 1, 'dur': 123, 'max': 120},
     {'ilvl': 7, 'dur': 61, 'max': 120},
     {'ilvl': 3, 'dur': 120, 'max': 120},
     {'ilvl': 374, 'dur': 38, 'max': 100}],
    []],
   [0, 59, 46])],
 [('over-repaired piece #1',
   [[{'ilvl': 20, 'dur': 105, 'max': 100}, {'ilvl': 20, 'dur': 90, 'max': 100}], []],
   [0, 0, 60]),
  ('regression silver denomination #1',
   [[{'ilvl': 367, 'dur': 0, 'max': 120},
     {'ilvl': 1, 'dur': 41, 'max': 120},
     {'ilvl': 7, 'dur': 103, 'max': 100},
     {'ilvl': 7, 'dur': 100, 'max': 100}],
    [5]],
   [1, 5, 64]),
  ('partial repair boundary #1',
   [[{'ilvl': 14, 'dur': 0, 'max': 40}, {'ilvl': 4, 'dur': 43, 'max': 40}], [25, 10, 15]],
   [0, 0, 92]),
  ('partial repair boundary #2',
   [[{'ilvl': 1, 'dur': 100, 'max': 100},
     {'ilvl': 3, 'dur': 123, 'max': 120},
     {'ilvl': 1, 'dur': 1, 'max': 60}],
    []],
   [0, 0, 59]),
  ('two stacked discounts #1', [[{'ilvl': 100, 'dur': 0, 'max': 120}], [10, 20]], [0, 22, 47]),
  ('nothing to repair #1', [[], [15]], [0, 0, 0]),
  ('control #1', [[], [25, 33]], [0, 0, 0]),
  ('control #2', [[{'ilvl': 1, 'dur': 63, 'max': 60}], []], [0, 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:
Bills above one gold show silver counts over 99.

Per item cost = max(0, max-dur) * (ilvl//4 + 1) copper. Discount percentages stack multiplicatively on the exact total; the result is rounded up once to copper. Return [gold, silver, copper] with 100 copper per silver and 100 silver per gold.

split: open-access


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

N = 1
observations = []
def solve(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r <= chance[level]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site success comparison #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8}),
  ('regression success comparison #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('fault site success comparison #2',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('partial repair boundary #1',
   [0, [29, 91, 60, 89, 60, 39, 49], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('regression success comparison #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('regression success comparison #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('fault site success comparison #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('partial repair boundary #2',
   [3, [90, 89], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 2}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('regression success comparison #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('partial repair boundary #1',
   [0, [90, 29, 59, 30, 59, 39, 50], 1],
   {'level': 7, 'broken': False, 'protections': 1, 'used': 7}),
  ('partial repair boundary #2',
   [6, [50, 90, 30, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('regression success comparison #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site success comparison #1',
   [3, [90], 1],
   {'level': 3, 'broken': False, 'protections': 1, 'used': 1}),
  ('partial repair boundary #1',
   [3, [89, 89, 0], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [10, [90, 49, 29], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 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(level, rolls, protections):
    chance = [100, 100, 100, 90, 80, 70, 60, 50, 40, 30]
    used = 0
    broken = False
    for r in rolls:
        if level >= 10 or broken:
            break
        used += 1
        if r < chance[min(level + 1, 9)]:
            level += 1
        elif level >= 6:
            if protections > 0:
                protections -= 1
            elif level >= 8:
                broken = True
            else:
                level -= 1
    return {'level': level, 'broken': broken, 'protections': protections, 'used': used}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [9, [39, 30, 99, 29, 59, 99, 0], 1],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 2}),
  ('fault site success comparison #2',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('partial repair boundary #1',
   [0, [0, 30, 89, 99, 60, 0, 59, 59], 2],
   {'level': 7, 'broken': False, 'protections': 2, 'used': 8}),
  ('regression success comparison #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [8, [49, 40, 59], 2],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 3}),
  ('fault site success comparison #2',
   [6, [59, 50, 99, 50], 0],
   {'level': 6, 'broken': False, 'protections': 0, 'used': 4}),
  ('partial repair boundary #1',
   [0, [29, 91, 60, 89, 60, 39, 49], 0],
   {'level': 7, 'broken': False, 'protections': 0, 'used': 7}),
  ('regression success comparison #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('regression success comparison #1',
   [6, [40, 99, 50, 50, 29, 60], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 6}),
  ('fault site success comparison #1',
   [9, [30, 90, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1}),
  ('partial repair boundary #1',
   [6, [47, 29, 60, 59, 39, 49, 59, 30], 2],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 6}),
  ('partial repair boundary #2',
   [3, [90, 89], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 2}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [9, [99, 30], 0], {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('fault site success comparison #1',
   [3, [49, 0, 0, 99, 50, 60], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 6}),
  ('regression success comparison #1',
   [7, [50, 39, 49, 90], 0],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('partial repair boundary #1',
   [0, [90, 29, 59, 30, 59, 39, 50], 1],
   {'level': 7, 'broken': False, 'protections': 1, 'used': 7}),
  ('partial repair boundary #2',
   [6, [50, 90, 30, 89], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 4}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1',
   [9, [50, 40, 50, 0, 40, 29, 0], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 1})],
 [('boundary roll equals chance #1',
   [4, [80], 0],
   {'level': 4, 'broken': False, 'protections': 0, 'used': 1}),
  ('regression success comparison #1',
   [6, [29, 50, 99, 60, 0, 50, 29, 99], 1],
   {'level': 8, 'broken': True, 'protections': 0, 'used': 8}),
  ('fault site success comparison #1',
   [3, [90], 1],
   {'level': 3, 'broken': False, 'protections': 1, 'used': 1}),
  ('partial repair boundary #1',
   [3, [89, 89, 0], 0],
   {'level': 5, 'broken': False, 'protections': 0, 'used': 3}),
  ('partial repair boundary #2',
   [6, [90, 59, 30, 90, 29, 40, 29, 40], 0],
   {'level': 9, 'broken': True, 'protections': 0, 'used': 8}),
  ('break at eight #1', [8, [95, 0], 0], {'level': 8, 'broken': True, 'protections': 0, 'used': 1}),
  ('protected downgrade #1', [6, [70, 70], 1], {'level': 5, 'broken': False, 'protections': 0, 'used': 2}),
  ('control #1', [10, [90, 49, 29], 0], {'level': 10, 'broken': False, 'protections': 0, 'used': 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:
Upgrades succeed one percentage point more often than published.

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

split: open-access