FA-60206 / Inventory cost layering / Open access
Inter-warehouse transfer of cost layers: destination layer placement · case 01
Transferred stock becomes the oldest stock at the destination and ships before local receipts.
ROOT CAUSE
Pieces are inserted at the head of the destination layers.
VERIFIED REPAIR
Append pieces after existing destination layers, preserving draw order.
Unsuccessful approach: Appending the pieces in reverse order puts newer source costs ahead of older ones.
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.insert(0, [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': [[3, 206], [3, 151], [2, 90]], 'src': [[2, 104]]} | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | Failed |
| 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': [[2, 8], [1, 10]], 'src': [[3, 0], [2, 40]]} | {'dst': [[1, 10], [2, 8]], 'src': [[3, 0], [2, 40]]} | Failed |
| uneven freight | {'dst': [[3, 188], [1, 62], [1, 54]], 'src': [[2, 120]]} | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | Failed |
| insufficient | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| nothing requested | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| exact all | {'dst': [[1, 12], [2, 21], [4, 44]], 'src': []} | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | Failed |
SHA-256 / a0fccd94147375b44ed09c820c56401412b0fcc6bda524c6d91ce1b2aa2aabe9
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
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 list(zip(pieces, shares))[::-1]:
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, 206], [3, 151]], 'src': [[2, 104]]} | {'dst': [[2, 90], [3, 151], [3, 206]], 'src': [[2, 104]]} | Failed |
| 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': [[3, 188], [1, 62], [1, 54]], 'src': [[2, 120]]} | {'dst': [[1, 54], [1, 62], [3, 188]], 'src': [[2, 120]]} | Failed |
| insufficient | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| nothing requested | {'error': 'invalid quantity'} | {'error': 'invalid quantity'} | Passed |
| exact all | {'dst': [[4, 44], [1, 12], [2, 21]], 'src': []} | {'dst': [[4, 44], [2, 21], [1, 12]], 'src': []} | Failed |
SHA-256 / 3d56ee6f8b8d9c91c3a956b7fa0a2f3c8383399151e9eade3b08792d087e9c92
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.450602+00:00.
Case digest / 74422478ddeed953f88a24b66e817b7d622f3c964a2a2dd63e93cd18b5662968