FA-86166 / Game economy crafting balance / Open access
Inventory stack insertion: Overfull legacy stacks are drained · case 01
Adding items to an inventory with a legacy overfull stack destroys items.
ROOT CAUSE
The top-up test only excludes exactly full stacks, so overfull stacks receive negative additions.
VERIFIED REPAIR
Restore `s[1] < max_stack` at the partial stack test step.
Unsuccessful approach: Also excluding empty placeholders stops reserved zero-count stacks from being topped up.
Case contract
slots = list of None or [name, count]; names are case sensitive. First top up partial stacks (count < max_stack) of the same item in slot order, then fill empty slots in order with new stacks of at most max_stack. Reserved placeholders [name, 0] count as partial stacks. Legacy stacks above max_stack are left untouched. Returns {slots, leftover}.
Why this case matters
Game economies leak or destroy currency when one crafting or pricing rule is off by one boundary, rounding stage or state update; the defect is observable in exact integer outcomes.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(slots, item, qty, max_stack):
slots = [s if s is None else list(s) for s in slots]
left = qty
for s in slots:
if left == 0:
break
if s is not None and s[0] == item and s[1] != max_stack:
add = min(left, max_stack - s[1])
s[1] += add
left -= add
for i in range(len(slots)):
if left == 0:
break
if slots[i] is None:
add = min(left, max_stack)
slots[i] = [item, add]
left -= add
return {'slots': slots, 'leftover': left}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Potion', 20], None, ['Arrow', 13], ['arrow', 20]], 'Potion', 20, 5],
{'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]], 'leftover': 15}),
('fault site partial stack test #2',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('partial repair boundary #1',
[[['Arrow', 0], ['Arrow', 1], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]], 'Arrow', 39, 20],
{'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]],
'leftover': 0}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('fault site partial stack test #2',
[[None, ['arrow', 1], ['Arrow', 19], ['arrow', 10], None], 'arrow', 20, 5],
{'slots': [['arrow', 5], ['arrow', 5], ['Arrow', 19], ['arrow', 10], ['arrow', 5]], 'leftover': 6}),
('partial repair boundary #1',
[[None, ['Arrow', 0], ['Potion', 0]], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 0], ['Potion', 10]], 'leftover': 0}),
('partial repair boundary #2',
[[['arrow', 20], ['Arrow', 0], ['Potion', 19]], 'Arrow', 7, 10],
{'slots': [['arrow', 20], ['Arrow', 7], ['Potion', 19]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 20], None, ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'arrow', 45, 10],
{'slots': [['arrow', 20], ['arrow', 10], ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'leftover': 35}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('partial repair boundary #1',
[[['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 0]], 'Potion', 1, 20],
{'slots': [['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 1]], 'leftover': 0}),
('partial repair boundary #2',
[[None, ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 0]], 'Arrow', 20, 5],
{'slots': [['Arrow', 5], ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 5]], 'leftover': 10}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[None, ['Potion', 5], ['Potion', 0], None, ['arrow', 20], ['Arrow', 17]], 'Arrow', 7, 5],
{'slots': [['Arrow', 5], ['Potion', 5], ['Potion', 0], ['Arrow', 2], ['arrow', 20], ['Arrow', 17]],
'leftover': 0}),
('fault site partial stack test #2',
[[['arrow', 1], ['Potion', 19]], 'Potion', 20, 10],
{'slots': [['arrow', 1], ['Potion', 19]], 'leftover': 20}),
('partial repair boundary #1',
[[['Potion', 0], ['Arrow', 0], ['Arrow', 1]], 'Arrow', 45, 10],
{'slots': [['Potion', 0], ['Arrow', 10], ['Arrow', 10]], 'leftover': 26}),
('partial repair boundary #2',
[[['Arrow', 5], None, ['Arrow', 20], ['arrow', 0], ['Potion', 0]], 'arrow', 7, 20],
{'slots': [['Arrow', 5], None, ['Arrow', 20], ['arrow', 7], ['Potion', 0]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[None, ['Arrow', 16], ['arrow', 20], None, ['Arrow', 25], None], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 16], ['arrow', 20], ['Potion', 10], ['Arrow', 25], None],
'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Arrow', 25], ['arrow', 19], None], 'Arrow', 1, 10],
{'slots': [['Arrow', 25], ['arrow', 19], ['Arrow', 1]], 'leftover': 0}),
('fault site partial stack test #2',
[[['Arrow', 20], ['Arrow', 25], None, ['arrow', 19]], 'arrow', 1, 10],
{'slots': [['Arrow', 20], ['Arrow', 25], ['arrow', 1], ['arrow', 19]], 'leftover': 0}),
('partial repair boundary #1',
[[None, None, ['arrow', 1], ['Potion', 0]], 'Potion', 45, 10],
{'slots': [['Potion', 10], ['Potion', 10], ['arrow', 1], ['Potion', 10]], 'leftover': 15}),
('partial repair boundary #2',
[[None, None, ['arrow', 14], ['Arrow', 0], None, None], 'Arrow', 1, 5],
{'slots': [None, None, ['arrow', 14], ['Arrow', 1], None, None], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1', [[['Potion', 0]], 'Arrow', 45, 5], {'slots': [['Potion', 0]], 'leftover': 45})]]
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legacy overfull stack #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 8]]} | {'leftover': 0, 'slots': [['Arrow', 25], ['Arrow', 3]]} | Failed |
| fault site partial stack test #1 | {'leftover': 30, 'slots': [['Potion', 5], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | {'leftover': 15, 'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | Failed |
| fault site partial stack test #2 | {'leftover': 58, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 5]]} | {'leftover': 45, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]]} | Failed |
| partial repair boundary #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]]} | Passed |
| regression partial stack test #1 | {'leftover': 43, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 5], ['Arrow', 19], ['arrow', 18]]} | {'leftover': 30, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]]} | Failed |
| two partial stacks #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | Passed |
| case distinct item #1 | {'leftover': 2, 'slots': [['arrow', 3]]} | {'leftover': 2, 'slots': [['arrow', 3]]} | Passed |
| control #1 | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | Passed |
SHA-256 / c9230757390f71b96e8d414a56f7d2c55ba3457238ed1051e7ac0e678bfcb2de
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(slots, item, qty, max_stack):
slots = [s if s is None else list(s) for s in slots]
left = qty
for s in slots:
if left == 0:
break
if s is not None and s[0] == item and s[1] < max_stack and s[1] > 0:
add = min(left, max_stack - s[1])
s[1] += add
left -= add
for i in range(len(slots)):
if left == 0:
break
if slots[i] is None:
add = min(left, max_stack)
slots[i] = [item, add]
left -= add
return {'slots': slots, 'leftover': left}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Potion', 20], None, ['Arrow', 13], ['arrow', 20]], 'Potion', 20, 5],
{'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]], 'leftover': 15}),
('fault site partial stack test #2',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('partial repair boundary #1',
[[['Arrow', 0], ['Arrow', 1], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]], 'Arrow', 39, 20],
{'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]],
'leftover': 0}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('fault site partial stack test #2',
[[None, ['arrow', 1], ['Arrow', 19], ['arrow', 10], None], 'arrow', 20, 5],
{'slots': [['arrow', 5], ['arrow', 5], ['Arrow', 19], ['arrow', 10], ['arrow', 5]], 'leftover': 6}),
('partial repair boundary #1',
[[None, ['Arrow', 0], ['Potion', 0]], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 0], ['Potion', 10]], 'leftover': 0}),
('partial repair boundary #2',
[[['arrow', 20], ['Arrow', 0], ['Potion', 19]], 'Arrow', 7, 10],
{'slots': [['arrow', 20], ['Arrow', 7], ['Potion', 19]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 20], None, ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'arrow', 45, 10],
{'slots': [['arrow', 20], ['arrow', 10], ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'leftover': 35}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('partial repair boundary #1',
[[['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 0]], 'Potion', 1, 20],
{'slots': [['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 1]], 'leftover': 0}),
('partial repair boundary #2',
[[None, ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 0]], 'Arrow', 20, 5],
{'slots': [['Arrow', 5], ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 5]], 'leftover': 10}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[None, ['Potion', 5], ['Potion', 0], None, ['arrow', 20], ['Arrow', 17]], 'Arrow', 7, 5],
{'slots': [['Arrow', 5], ['Potion', 5], ['Potion', 0], ['Arrow', 2], ['arrow', 20], ['Arrow', 17]],
'leftover': 0}),
('fault site partial stack test #2',
[[['arrow', 1], ['Potion', 19]], 'Potion', 20, 10],
{'slots': [['arrow', 1], ['Potion', 19]], 'leftover': 20}),
('partial repair boundary #1',
[[['Potion', 0], ['Arrow', 0], ['Arrow', 1]], 'Arrow', 45, 10],
{'slots': [['Potion', 0], ['Arrow', 10], ['Arrow', 10]], 'leftover': 26}),
('partial repair boundary #2',
[[['Arrow', 5], None, ['Arrow', 20], ['arrow', 0], ['Potion', 0]], 'arrow', 7, 20],
{'slots': [['Arrow', 5], None, ['Arrow', 20], ['arrow', 7], ['Potion', 0]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[None, ['Arrow', 16], ['arrow', 20], None, ['Arrow', 25], None], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 16], ['arrow', 20], ['Potion', 10], ['Arrow', 25], None],
'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Arrow', 25], ['arrow', 19], None], 'Arrow', 1, 10],
{'slots': [['Arrow', 25], ['arrow', 19], ['Arrow', 1]], 'leftover': 0}),
('fault site partial stack test #2',
[[['Arrow', 20], ['Arrow', 25], None, ['arrow', 19]], 'arrow', 1, 10],
{'slots': [['Arrow', 20], ['Arrow', 25], ['arrow', 1], ['arrow', 19]], 'leftover': 0}),
('partial repair boundary #1',
[[None, None, ['arrow', 1], ['Potion', 0]], 'Potion', 45, 10],
{'slots': [['Potion', 10], ['Potion', 10], ['arrow', 1], ['Potion', 10]], 'leftover': 15}),
('partial repair boundary #2',
[[None, None, ['arrow', 14], ['Arrow', 0], None, None], 'Arrow', 1, 5],
{'slots': [None, None, ['arrow', 14], ['Arrow', 1], None, None], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1', [[['Potion', 0]], 'Arrow', 45, 5], {'slots': [['Potion', 0]], 'leftover': 45})]]
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legacy overfull stack #1 | {'leftover': 0, 'slots': [['Arrow', 25], ['Arrow', 3]]} | {'leftover': 0, 'slots': [['Arrow', 25], ['Arrow', 3]]} | Passed |
| fault site partial stack test #1 | {'leftover': 15, 'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | {'leftover': 15, 'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | Passed |
| fault site partial stack test #2 | {'leftover': 45, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]]} | {'leftover': 45, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]]} | Passed |
| partial repair boundary #1 | {'leftover': 0, 'slots': [['Arrow', 0], ['Arrow', 20], ['arrow', 5], ['Arrow', 20], ['arrow', 19], ['Potion', 0]]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]]} | Failed |
| regression partial stack test #1 | {'leftover': 35, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]]} | {'leftover': 30, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]]} | Failed |
| two partial stacks #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | Passed |
| case distinct item #1 | {'leftover': 2, 'slots': [['arrow', 3]]} | {'leftover': 2, 'slots': [['arrow', 3]]} | Passed |
| control #1 | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | Passed |
SHA-256 / 3a66785e523c18cdaf3fcbb76916d4689218505846fd6f45d021c0f416492029
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(slots, item, qty, max_stack):
slots = [s if s is None else list(s) for s in slots]
left = qty
for s in slots:
if left == 0:
break
if s is not None and s[0] == item and s[1] < max_stack:
add = min(left, max_stack - s[1])
s[1] += add
left -= add
for i in range(len(slots)):
if left == 0:
break
if slots[i] is None:
add = min(left, max_stack)
slots[i] = [item, add]
left -= add
return {'slots': slots, 'leftover': left}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Potion', 20], None, ['Arrow', 13], ['arrow', 20]], 'Potion', 20, 5],
{'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]], 'leftover': 15}),
('fault site partial stack test #2',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('partial repair boundary #1',
[[['Arrow', 0], ['Arrow', 1], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]], 'Arrow', 39, 20],
{'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]],
'leftover': 0}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 0], ['arrow', 5], ['Potion', 18]], 'Potion', 45, 5],
{'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]], 'leftover': 45}),
('fault site partial stack test #2',
[[None, ['arrow', 1], ['Arrow', 19], ['arrow', 10], None], 'arrow', 20, 5],
{'slots': [['arrow', 5], ['arrow', 5], ['Arrow', 19], ['arrow', 10], ['arrow', 5]], 'leftover': 6}),
('partial repair boundary #1',
[[None, ['Arrow', 0], ['Potion', 0]], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 0], ['Potion', 10]], 'leftover': 0}),
('partial repair boundary #2',
[[['arrow', 20], ['Arrow', 0], ['Potion', 19]], 'Arrow', 7, 10],
{'slots': [['arrow', 20], ['Arrow', 7], ['Potion', 19]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['arrow', 20], None, ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'arrow', 45, 10],
{'slots': [['arrow', 20], ['arrow', 10], ['Potion', 4], ['Arrow', 20], ['arrow', 19]], 'leftover': 35}),
('regression partial stack test #1',
[[None, None, ['Potion', 0], ['Potion', 18], ['Arrow', 19], ['arrow', 18]], 'Potion', 45, 5],
{'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]],
'leftover': 30}),
('partial repair boundary #1',
[[['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 0]], 'Potion', 1, 20],
{'slots': [['arrow', 20], ['Arrow', 16], ['arrow', 20], None, None, ['Potion', 1]], 'leftover': 0}),
('partial repair boundary #2',
[[None, ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 0]], 'Arrow', 20, 5],
{'slots': [['Arrow', 5], ['Potion', 1], ['Potion', 20], ['Potion', 19], ['Arrow', 5]], 'leftover': 10}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[['Arrow', 6], None, ['arrow', 5]], 'Potion', 0, 20],
{'slots': [['Arrow', 6], None, ['arrow', 5]], 'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[None, ['Potion', 5], ['Potion', 0], None, ['arrow', 20], ['Arrow', 17]], 'Arrow', 7, 5],
{'slots': [['Arrow', 5], ['Potion', 5], ['Potion', 0], ['Arrow', 2], ['arrow', 20], ['Arrow', 17]],
'leftover': 0}),
('fault site partial stack test #2',
[[['arrow', 1], ['Potion', 19]], 'Potion', 20, 10],
{'slots': [['arrow', 1], ['Potion', 19]], 'leftover': 20}),
('partial repair boundary #1',
[[['Potion', 0], ['Arrow', 0], ['Arrow', 1]], 'Arrow', 45, 10],
{'slots': [['Potion', 0], ['Arrow', 10], ['Arrow', 10]], 'leftover': 26}),
('partial repair boundary #2',
[[['Arrow', 5], None, ['Arrow', 20], ['arrow', 0], ['Potion', 0]], 'arrow', 7, 20],
{'slots': [['Arrow', 5], None, ['Arrow', 20], ['arrow', 7], ['Potion', 0]], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1',
[[None, ['Arrow', 16], ['arrow', 20], None, ['Arrow', 25], None], 'Potion', 20, 10],
{'slots': [['Potion', 10], ['Arrow', 16], ['arrow', 20], ['Potion', 10], ['Arrow', 25], None],
'leftover': 0})],
[('legacy overfull stack #1',
[[['Arrow', 25], None], 'Arrow', 3, 20],
{'slots': [['Arrow', 25], ['Arrow', 3]], 'leftover': 0}),
('fault site partial stack test #1',
[[['Arrow', 25], ['arrow', 19], None], 'Arrow', 1, 10],
{'slots': [['Arrow', 25], ['arrow', 19], ['Arrow', 1]], 'leftover': 0}),
('fault site partial stack test #2',
[[['Arrow', 20], ['Arrow', 25], None, ['arrow', 19]], 'arrow', 1, 10],
{'slots': [['Arrow', 20], ['Arrow', 25], ['arrow', 1], ['arrow', 19]], 'leftover': 0}),
('partial repair boundary #1',
[[None, None, ['arrow', 1], ['Potion', 0]], 'Potion', 45, 10],
{'slots': [['Potion', 10], ['Potion', 10], ['arrow', 1], ['Potion', 10]], 'leftover': 15}),
('partial repair boundary #2',
[[None, None, ['arrow', 14], ['Arrow', 0], None, None], 'Arrow', 1, 5],
{'slots': [None, None, ['arrow', 14], ['Arrow', 1], None, None], 'leftover': 0}),
('two partial stacks #1',
[[['Arrow', 18], ['Arrow', 15], None], 'Arrow', 4, 20],
{'slots': [['Arrow', 20], ['Arrow', 17], None], 'leftover': 0}),
('case distinct item #1', [[['arrow', 3]], 'Arrow', 2, 20], {'slots': [['arrow', 3]], 'leftover': 2}),
('control #1', [[['Potion', 0]], 'Arrow', 45, 5], {'slots': [['Potion', 0]], 'leftover': 45})]]
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| legacy overfull stack #1 | {'leftover': 0, 'slots': [['Arrow', 25], ['Arrow', 3]]} | {'leftover': 0, 'slots': [['Arrow', 25], ['Arrow', 3]]} | Passed |
| fault site partial stack test #1 | {'leftover': 15, 'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | {'leftover': 15, 'slots': [['Potion', 20], ['Potion', 5], ['Arrow', 13], ['arrow', 20]]} | Passed |
| fault site partial stack test #2 | {'leftover': 45, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]]} | {'leftover': 45, 'slots': [['arrow', 0], ['arrow', 5], ['Potion', 18]]} | Passed |
| partial repair boundary #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 20], ['arrow', 5], None, ['arrow', 19], ['Potion', 0]]} | Passed |
| regression partial stack test #1 | {'leftover': 30, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]]} | {'leftover': 30, 'slots': [['Potion', 5], ['Potion', 5], ['Potion', 5], ['Potion', 18], ['Arrow', 19], ['arrow', 18]]} | Passed |
| two partial stacks #1 | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | {'leftover': 0, 'slots': [['Arrow', 20], ['Arrow', 17], None]} | Passed |
| case distinct item #1 | {'leftover': 2, 'slots': [['arrow', 3]]} | {'leftover': 2, 'slots': [['arrow', 3]]} | Passed |
| control #1 | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | {'leftover': 0, 'slots': [['Arrow', 6], None, ['arrow', 5]]} | Passed |
SHA-256 / c2e34dd334ea3930b55dc3629af3dc841e15eba8c227f996121d0265b83c2339
Verification & scope
Deterministic toy contract stipulated for this model; integer or exact arithmetic only, not a reproduction of any specific game engine. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:50:46.989130+00:00.
Case digest / 39174f93c8965f560caebe5a4b98f28aaa315694d87866e982473f559460e63c