FA-60191 / Inventory cost layering / Open access
Inter-warehouse transfer of cost layers: partial draw valuation · case 01
Transferred value is short by a few cents on every partial draw and the residue sticks in the source.
ROOT CAUSE
The partial draw truncates the unit cost before extending it by the drawn quantity.
VERIFIED REPAIR
Take floor(t * layer value / layer qty) in one step.
Unsuccessful approach: Rounding the draw up pulls residue out of the source earlier than the stipulated floor rule.
Case contract
Layers are [qty, total value]. A transfer of qty draws FIFO from src; a partial draw takes floor(t*value/qty) and leaves the residue in src; a layer is removed when its quantity reaches zero. Freight is split across the drawn pieces by quantity (floor), residual cents to the first piece, and each piece is appended to dst in draw order as the newest layers. qty<=0 or qty above src stock returns {"error"}. Return {src, dst}.
Why this case matters
Inventory valuation and cost-of-goods decisions depend on this rule.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
src = [list(l) for l in x['src']]
dst = [list(l) for l in x['dst']]
q = x['qty']
if q <= 0 or q > sum(l[0] for l in src):
return {'error': 'invalid quantity'}
pieces = []
while q > 0:
lq, lv = src[0]
t = min(q, lq)
val = lv if t == lq else t * (lv // lq)
pieces.append([t, val])
src[0] = [lq - t, lv - val]
if src[0][0] == 0:
src.pop(0)
q -= t
fr = x['freight']
tq = x['qty']
shares = [fr * p[0] // tq for p in pieces]
shares[0] += fr - sum(shares)
for p, s in zip(pieces, shares):
dst.append([p[0], p[1] + s])
return {'src': src, 'dst': dst}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 11}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 78]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 1}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 75]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 8}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 8]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 14}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 62], [3, 188]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 4, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 12]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 12]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 12}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 79]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 2}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 76]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 9}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 9]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 15}, {'src': [[2, 120]], 'dst': [[1, 53], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 5, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 13]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 13]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 13}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 80]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 3}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 77]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 10}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 10]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 16}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 6, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 14]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 14]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 14}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 81]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 4}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 78]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 11}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 11]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 17}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 7, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 15]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 15]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 15}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 82]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 5}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 79]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 12}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 12]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 18}, {'src': [[2, 120]], 'dst': [[1, 55], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 8, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 16]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 16]]}]]]
for label, args, expected in fixtures[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 |
|---|---|---|---|
| span layers | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | Passed |
| partial residue | {'dst': [[2, 77]], 'src': [[1, 35], [4, 77]]} | {'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]} | Failed |
| odd layer value | {'dst': [[3, 73]], 'src': [[1, 27], [1, 5]]} | {'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]} | Failed |
| free goods layer | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | Passed |
| uneven freight | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | Passed |
| insufficient | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| nothing requested | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| exact all | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | Passed |
SHA-256 / adad834d5c2fca71ea7ffafbcd4983738d71140e5f5e75b4082b9fb58f862579
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
src = [list(l) for l in x['src']]
dst = [list(l) for l in x['dst']]
q = x['qty']
if q <= 0 or q > sum(l[0] for l in src):
return {'error': 'invalid quantity'}
pieces = []
while q > 0:
lq, lv = src[0]
t = min(q, lq)
val = lv if t == lq else (t * lv + lq - 1) // lq
pieces.append([t, val])
src[0] = [lq - t, lv - val]
if src[0][0] == 0:
src.pop(0)
q -= t
fr = x['freight']
tq = x['qty']
shares = [fr * p[0] // tq for p in pieces]
shares[0] += fr - sum(shares)
for p, s in zip(pieces, shares):
dst.append([p[0], p[1] + s])
return {'src': src, 'dst': dst}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 11}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 78]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 1}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 75]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 8}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 8]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 14}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 62], [3, 188]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 4, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 12]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 12]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 12}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 79]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 2}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 76]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 9}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 9]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 15}, {'src': [[2, 120]], 'dst': [[1, 53], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 5, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 13]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 13]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 13}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 80]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 3}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 77]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 10}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 10]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 16}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 6, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 14]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 14]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 14}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 81]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 4}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 78]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 11}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 11]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 17}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 7, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 15]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 15]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 15}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 82]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 5}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 79]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 12}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 12]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 18}, {'src': [[2, 120]], 'dst': [[1, 55], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 8, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 16]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 16]]}]]]
for label, args, expected in fixtures[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 |
|---|---|---|---|
| span layers | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | Passed |
| partial residue | {'dst': [[2, 79]], 'src': [[1, 33], [4, 77]]} | {'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]} | Failed |
| odd layer value | {'dst': [[3, 76]], 'src': [[1, 24], [1, 5]]} | {'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]} | Failed |
| free goods layer | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | Passed |
| uneven freight | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | Passed |
| insufficient | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| nothing requested | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| exact all | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | Passed |
SHA-256 / 79143ab0648f3d692ead69be3619464eb15f22fe643a3999bbb78abb2666542a
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
src = [list(l) for l in x['src']]
dst = [list(l) for l in x['dst']]
q = x['qty']
if q <= 0 or q > sum(l[0] for l in src):
return {'error': 'invalid quantity'}
pieces = []
while q > 0:
lq, lv = src[0]
t = min(q, lq)
val = lv if t == lq else t * lv // lq
pieces.append([t, val])
src[0] = [lq - t, lv - val]
if src[0][0] == 0:
src.pop(0)
q -= t
fr = x['freight']
tq = x['qty']
shares = [fr * p[0] // tq for p in pieces]
shares[0] += fr - sum(shares)
for p, s in zip(pieces, shares):
dst.append([p[0], p[1] + s])
return {'src': src, 'dst': dst}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 11}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 78]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 1}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 75]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 8}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 8]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 14}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 62], [3, 188]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 4, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 12]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 12]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 12}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 79]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 2}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 76]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 9}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 9]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 15}, {'src': [[2, 120]], 'dst': [[1, 53], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 5, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 13]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 13]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 13}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 80]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 3}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 77]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 10}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 10]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 16}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 189]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 6, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 14]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 14]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 5, 'freight': 101}, {'src': [[3, 156]], 'dst': [[2, 90], [3, 161], [2, 144]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 14}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 81]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 4}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 78]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 11}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 11]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 17}, {'src': [[2, 120]], 'dst': [[1, 54], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 7, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 15]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 15]]}]], [['span layers', {'src': [[3, 100], [5, 260]], 'dst': [[2, 90]], 'qty': 6, 'freight': 101}, {'src': [[2, 104]], 'dst': [[2, 90], [3, 151], [3, 206]]}], ['partial residue', {'src': [[3, 101], [4, 77]], 'dst': [], 'qty': 2, 'freight': 15}, {'src': [[1, 34], [4, 77]], 'dst': [[2, 82]]}], ['odd layer value', {'src': [[4, 99], [1, 5]], 'dst': [], 'qty': 3, 'freight': 5}, {'src': [[1, 25], [1, 5]], 'dst': [[3, 79]]}], ['free goods layer', {'src': [[5, 0], [2, 40]], 'dst': [[1, 10]], 'qty': 2, 'freight': 12}, {'src': [[3, 0], [2, 40]], 'dst': [[1, 10], [2, 12]]}], ['uneven freight', {'src': [[1, 50], [1, 60], [5, 300]], 'dst': [], 'qty': 5, 'freight': 18}, {'src': [[2, 120]], 'dst': [[1, 55], [1, 63], [3, 190]]}], ['insufficient', {'src': [[2, 20]], 'dst': [], 'qty': 8, 'freight': 5}, {'error': 'invalid quantity'}], ['nothing requested', {'src': [[2, 20]], 'dst': [], 'qty': 0, 'freight': 5}, {'error': 'invalid quantity'}], ['exact all', {'src': [[2, 21], [1, 16]], 'dst': [[4, 44]], 'qty': 3, 'freight': 0}, {'src': [], 'dst': [[4, 44], [2, 21], [1, 16]]}]]]
for label, args, expected in fixtures[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 |
|---|---|---|---|
| span layers | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | Passed |
| partial residue | {'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]} | {'dst': [[2, 78]], 'src': [[1, 34], [4, 77]]} | Passed |
| odd layer value | {'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]} | {'dst': [[3, 75]], 'src': [[1, 25], [1, 5]]} | Passed |
| free goods layer | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | Passed |
| uneven freight | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | Passed |
| insufficient | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| nothing requested | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| exact all | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | Passed |
SHA-256 / e3b6414e5516d7721e932d9774191511b78f141475dcac3be8fba5675d01187e
Verification & scope
Stipulated bounded teaching model with explicit toy rules; not an accounting-standard implementation. 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:46:43.417983+00:00.
Case digest / 893af99d01a908f5233499a82338151a615b1ad07581050af866e22b631e9f8a