FA-60061 / Inventory cost layering / Open access
First-expired-first-out lot picking: remaining shelf-life boundary · case 01
Lots with exactly the minimum remaining shelf life are refused at the dock.
ROOT CAUSE
Eligibility requires strictly more than the minimum shelf life.
VERIFIED REPAIR
A lot is eligible when remaining days are greater than or equal to the minimum.
Unsuccessful approach: Subtracting one day from the minimum only fixes the boundary when shelf life is counted inclusively twice.
Case contract
Input {lots:[[lot,qty,expiry_day,unit_cost]], today, order_qty, min_shelf}. A lot is eligible when expiry_day - today >= min_shelf. Eligible lots are picked by earliest expiry, ties by lot id ascending. If eligible stock < order_qty return {"error":"insufficient","available":eligible qty}. Return {picks:[[lot,qty]], cost}.
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):
today = x['today']
elig = [l for l in x['lots'] if l[2] - today > x['min_shelf']]
avail = sum(l[1] for l in elig)
if avail < x['order_qty']:
return {'error': 'insufficient', 'available': avail}
elig.sort(key=lambda l: (l[2], l[0]))
need = x['order_qty']
picks = []
cost = 0
for lot, qty, exp, unit in elig:
if need == 0:
break
take = min(need, qty)
picks.append([lot, take])
cost += take * unit
need -= take
return {'picks': picks, 'cost': cost}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 106, 10], ['B', 4, 200, 11]], 'today': 101, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 6, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 6, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 381, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 101, 4], ['U', 3, 190, 5]], 'today': 101, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 107, 10], ['B', 4, 200, 11]], 'today': 102, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 7, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 7, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 382, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 102, 4], ['U', 3, 190, 5]], 'today': 102, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 6, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 1]], 'cost': 70}], ['shelf boundary', {'lots': [['A', 4, 108, 10], ['B', 4, 200, 11]], 'today': 103, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 8, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 8, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 383, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 103, 4], ['U', 3, 190, 5]], 'today': 103, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 109, 10], ['B', 4, 200, 11]], 'today': 104, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 9, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 9, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 384, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 104, 4], ['U', 3, 190, 5]], 'today': 104, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 110, 10], ['B', 4, 200, 11]], 'today': 105, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 10, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 10, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 385, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 105, 4], ['U', 3, 190, 5]], 'today': 105, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]]]
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 |
|---|---|---|---|
| earliest expiry | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | Passed |
| shelf boundary | {'cost': 33, 'picks': [['B', 3]]} | {'cost': 30, 'picks': [['A', 3]]} | Failed |
| insufficient | {'available': 4, 'error': 'insufficient'} | {'available': 4, 'error': 'insufficient'} | Passed |
| tie by lot | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | Passed |
| expired skipped | {'cost': 8, 'picks': [['NEW', 4]]} | {'cost': 8, 'picks': [['NEW', 4]]} | Passed |
| zero order | {'cost': 0, 'picks': []} | {'cost': 0, 'picks': []} | Passed |
| big lots small order | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | Passed |
| expires today no minimum | {'cost': 10, 'picks': [['U', 2]]} | {'cost': 8, 'picks': [['T', 2]]} | Failed |
SHA-256 / 77745b78c12b219aa0062d2975f4849f1cc6c59424216fe8fa2a691c0bcd3d70
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
today = x['today']
elig = [l for l in x['lots'] if l[2] - today > x['min_shelf'] - 1 and l[2] > today + 1]
avail = sum(l[1] for l in elig)
if avail < x['order_qty']:
return {'error': 'insufficient', 'available': avail}
elig.sort(key=lambda l: (l[2], l[0]))
need = x['order_qty']
picks = []
cost = 0
for lot, qty, exp, unit in elig:
if need == 0:
break
take = min(need, qty)
picks.append([lot, take])
cost += take * unit
need -= take
return {'picks': picks, 'cost': cost}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 106, 10], ['B', 4, 200, 11]], 'today': 101, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 6, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 6, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 381, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 101, 4], ['U', 3, 190, 5]], 'today': 101, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 107, 10], ['B', 4, 200, 11]], 'today': 102, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 7, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 7, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 382, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 102, 4], ['U', 3, 190, 5]], 'today': 102, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 6, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 1]], 'cost': 70}], ['shelf boundary', {'lots': [['A', 4, 108, 10], ['B', 4, 200, 11]], 'today': 103, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 8, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 8, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 383, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 103, 4], ['U', 3, 190, 5]], 'today': 103, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 109, 10], ['B', 4, 200, 11]], 'today': 104, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 9, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 9, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 384, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 104, 4], ['U', 3, 190, 5]], 'today': 104, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 110, 10], ['B', 4, 200, 11]], 'today': 105, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 10, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 10, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 385, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 105, 4], ['U', 3, 190, 5]], 'today': 105, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]]]
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 |
|---|---|---|---|
| earliest expiry | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | Passed |
| shelf boundary | {'cost': 30, 'picks': [['A', 3]]} | {'cost': 30, 'picks': [['A', 3]]} | Passed |
| insufficient | {'available': 4, 'error': 'insufficient'} | {'available': 4, 'error': 'insufficient'} | Passed |
| tie by lot | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | Passed |
| expired skipped | {'cost': 8, 'picks': [['NEW', 4]]} | {'cost': 8, 'picks': [['NEW', 4]]} | Passed |
| zero order | {'cost': 0, 'picks': []} | {'cost': 0, 'picks': []} | Passed |
| big lots small order | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | Passed |
| expires today no minimum | {'cost': 10, 'picks': [['U', 2]]} | {'cost': 8, 'picks': [['T', 2]]} | Failed |
SHA-256 / 13037068a7130173ff548fe20d73d8f9259e2cb07ff15636b680ca417c8bd991
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
today = x['today']
elig = [l for l in x['lots'] if l[2] - today >= x['min_shelf']]
avail = sum(l[1] for l in elig)
if avail < x['order_qty']:
return {'error': 'insufficient', 'available': avail}
elig.sort(key=lambda l: (l[2], l[0]))
need = x['order_qty']
picks = []
cost = 0
for lot, qty, exp, unit in elig:
if need == 0:
break
take = min(need, qty)
picks.append([lot, take])
cost += take * unit
need -= take
return {'picks': picks, 'cost': cost}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 106, 10], ['B', 4, 200, 11]], 'today': 101, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 6, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 6, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 381, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 101, 4], ['U', 3, 190, 5]], 'today': 101, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 107, 10], ['B', 4, 200, 11]], 'today': 102, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 7, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 7, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 382, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 102, 4], ['U', 3, 190, 5]], 'today': 102, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 6, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 1]], 'cost': 70}], ['shelf boundary', {'lots': [['A', 4, 108, 10], ['B', 4, 200, 11]], 'today': 103, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 8, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 8, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 383, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 103, 4], ['U', 3, 190, 5]], 'today': 103, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 7, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 2]], 'cost': 80}], ['shelf boundary', {'lots': [['A', 4, 109, 10], ['B', 4, 200, 11]], 'today': 104, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 9, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 9, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 384, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 104, 4], ['U', 3, 190, 5]], 'today': 104, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]], [['earliest expiry', {'lots': [['L3', 5, 120, 10], ['L1', 5, 110, 12], ['L2', 5, 130, 9]], 'today': 100, 'order_qty': 8, 'min_shelf': 5}, {'picks': [['L1', 5], ['L3', 3]], 'cost': 90}], ['shelf boundary', {'lots': [['A', 4, 110, 10], ['B', 4, 200, 11]], 'today': 105, 'order_qty': 3, 'min_shelf': 5}, {'picks': [['A', 3]], 'cost': 30}], ['insufficient', {'lots': [['A', 4, 150, 10], ['B', 9, 101, 11]], 'today': 100, 'order_qty': 10, 'min_shelf': 10}, {'error': 'insufficient', 'available': 4}], ['tie by lot', {'lots': [['Z9', 2, 140, 8], ['A1', 2, 140, 7], ['M5', 9, 150, 6]], 'today': 100, 'order_qty': 3, 'min_shelf': 1}, {'picks': [['A1', 2], ['Z9', 1]], 'cost': 22}], ['expired skipped', {'lots': [['OLD', 50, 90, 1], ['NEW', 10, 300, 2]], 'today': 100, 'order_qty': 4, 'min_shelf': 0}, {'picks': [['NEW', 4]], 'cost': 8}], ['zero order', {'lots': [['A', 3, 150, 10]], 'today': 100, 'order_qty': 0, 'min_shelf': 0}, {'picks': [], 'cost': 0}], ['big lots small order', {'lots': [['B7', 100, 400, 3], ['C2', 1, 385, 5], ['A4', 2, 390, 4]], 'today': 100, 'order_qty': 2, 'min_shelf': 30}, {'picks': [['C2', 1], ['A4', 1]], 'cost': 9}], ['expires today no minimum', {'lots': [['T', 3, 105, 4], ['U', 3, 190, 5]], 'today': 105, 'order_qty': 2, 'min_shelf': 0}, {'picks': [['T', 2]], 'cost': 8}]]]
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 |
|---|---|---|---|
| earliest expiry | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | {'cost': 80, 'picks': [['L1', 5], ['L3', 2]]} | Passed |
| shelf boundary | {'cost': 30, 'picks': [['A', 3]]} | {'cost': 30, 'picks': [['A', 3]]} | Passed |
| insufficient | {'available': 4, 'error': 'insufficient'} | {'available': 4, 'error': 'insufficient'} | Passed |
| tie by lot | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | {'cost': 22, 'picks': [['A1', 2], ['Z9', 1]]} | Passed |
| expired skipped | {'cost': 8, 'picks': [['NEW', 4]]} | {'cost': 8, 'picks': [['NEW', 4]]} | Passed |
| zero order | {'cost': 0, 'picks': []} | {'cost': 0, 'picks': []} | Passed |
| big lots small order | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | {'cost': 9, 'picks': [['C2', 1], ['A4', 1]]} | Passed |
| expires today no minimum | {'cost': 8, 'picks': [['T', 2]]} | {'cost': 8, 'picks': [['T', 2]]} | Passed |
SHA-256 / 7b948c0f2fd78e94a5aa2a483a9e9ac642a55251fd7ac6640096f80e95903ca9
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:42.114046+00:00.
Case digest / 244c628c3456473f6c2eba3310900e0f8c05dfbd5dc90ac06ab26609c4bf9a34