FA-95636 / Shipping rate zone lookup / Open access
Flat vs weight: first eligible option taken · case 01
The first box in the catalogue is used even when a cheaper box or weight price exists.
ROOT CAUSE
The option list is not minimized by price.
VERIFIED REPAIR
Choose the minimum price, preferring flat boxes on ties.
Unsuccessful approach: Minimizing on the flat flag first always prefers a flat box over a cheaper weight price.
Case contract
boxes [[name, L, W, H, price]] inner dims; an item fits a flat box in any orientation and flat boxes accept up to 70 lb. Weight price = weight_rates[lb-1] with lb = ceil(weight) (min 1) when lb is within the table. Choose the cheapest option; on equal price prefer flat boxes, then name. Return [option, price] or ["NONE", 0].
Why this case matters
Shippers compare flat-rate packaging with zone weight pricing.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(dims, weight, boxes, weight_rates):
need = sorted(dims)
opts = []
for name, L, W, H, price in boxes:
if weight <= 70 and all(a <= b for a, b in zip(need, sorted([L, W, H]))):
opts.append((price, 0, name))
lb = max(1, math.ceil(weight))
if lb <= len(weight_rates):
opts.append((weight_rates[lb - 1], 1, 'WEIGHT'))
if not opts:
return ['NONE', 0]
p, _, name = opts[0]
return [name, p]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 8', [[2, 10, 11], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]]], [['generated mix 10', [[12, 4, 4], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 2200]], ['generated mix 17', [[4, 5, 10], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 9', [[5, 4, 11], 9.1, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 19', [[4, 7, 10], 70, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 34', [[11, 4, 1], 0.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 20', [[8, 7, 10], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['generated mix 28', [[12, 10, 5], 70.4, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 47', [[4, 8, 8], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 39', [[10, 1, 11], 10, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 48', [[8, 1, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]]], [['generated mix 61', [[11, 4, 12], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['generated mix 58', [[7, 8, 5], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 42', [[4, 1, 12], 1.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1100]], ['generated mix 50', [[7, 1, 11], 70, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]]]]
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 |
|---|---|---|---|
| weight cheaper | ['SMALL', 1045] | ['WEIGHT', 900] | Failed |
| fraction rounds up | ['MEDIUM', 1740] | ['WEIGHT', 1600] | Failed |
| flat cheaper | ['MEDIUM', 1740] | ['MEDIUM', 1740] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| expensive box listed first | ['LARGE', 2395] | ['SMALL', 1045] | Failed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| tie prefers flat | ['PADDED', 2200] | ['PADDED', 2200] | Passed |
| generated mix 8 | ['LARGE', 2395] | ['WEIGHT', 900] | Failed |
SHA-256 / 9d419bd880cbd78d670a880405747c709236ab3b96f3627094d4a2f533fcdc13
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(dims, weight, boxes, weight_rates):
need = sorted(dims)
opts = []
for name, L, W, H, price in boxes:
if weight <= 70 and all(a <= b for a, b in zip(need, sorted([L, W, H]))):
opts.append((price, 0, name))
lb = max(1, math.ceil(weight))
if lb <= len(weight_rates):
opts.append((weight_rates[lb - 1], 1, 'WEIGHT'))
if not opts:
return ['NONE', 0]
p, _, name = min(opts, key=lambda o: (o[1], o[0]))
return [name, p]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 8', [[2, 10, 11], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]]], [['generated mix 10', [[12, 4, 4], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 2200]], ['generated mix 17', [[4, 5, 10], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 9', [[5, 4, 11], 9.1, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 19', [[4, 7, 10], 70, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 34', [[11, 4, 1], 0.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 20', [[8, 7, 10], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['generated mix 28', [[12, 10, 5], 70.4, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 47', [[4, 8, 8], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 39', [[10, 1, 11], 10, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 48', [[8, 1, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]]], [['generated mix 61', [[11, 4, 12], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['generated mix 58', [[7, 8, 5], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 42', [[4, 1, 12], 1.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1100]], ['generated mix 50', [[7, 1, 11], 70, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]]]]
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 |
|---|---|---|---|
| weight cheaper | ['SMALL', 1045] | ['WEIGHT', 900] | Failed |
| fraction rounds up | ['MEDIUM', 1740] | ['WEIGHT', 1600] | Failed |
| flat cheaper | ['MEDIUM', 1740] | ['MEDIUM', 1740] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| expensive box listed first | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| tie prefers flat | ['PADDED', 2200] | ['PADDED', 2200] | Passed |
| generated mix 8 | ['LARGE', 2395] | ['WEIGHT', 900] | Failed |
SHA-256 / da0881e2cf5f531019c6c244145f347bb869ab7cbc22945d6ffb24b7bd51f63f
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(dims, weight, boxes, weight_rates):
need = sorted(dims)
opts = []
for name, L, W, H, price in boxes:
if weight <= 70 and all(a <= b for a, b in zip(need, sorted([L, W, H]))):
opts.append((price, 0, name))
lb = max(1, math.ceil(weight))
if lb <= len(weight_rates):
opts.append((weight_rates[lb - 1], 1, 'WEIGHT'))
if not opts:
return ['NONE', 0]
p, _, name = min(opts)
return [name, p]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 8', [[2, 10, 11], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]]], [['generated mix 10', [[12, 4, 4], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 2200]], ['generated mix 17', [[4, 5, 10], 0.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 9', [[5, 4, 11], 9.1, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 19', [[4, 7, 10], 70, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 34', [[11, 4, 1], 0.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['over 70', [[1, 1, 1], 70.5, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 20', [[8, 7, 10], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]], ['generated mix 28', [[12, 10, 5], 70.4, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 47', [[4, 8, 8], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['expensive box listed first', [[1, 1, 1], 30, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['flat cheaper', [[4, 10, 7], 6, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]], ['generated mix 31', [[5, 4, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['generated mix 39', [[10, 1, 11], 10, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 48', [[8, 1, 7], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]]], [['generated mix 61', [[11, 4, 12], 0.5, [['LARGE', 12, 12, 6, 2395], ['MEDIUM', 11, 8, 5, 1740], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['generated mix 58', [[7, 8, 5], 3.2, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['fraction rounds up', [[11, 8, 5], 3.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1600]], ['weight cheaper', [[2, 8, 5], 1, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 900]], ['70 lb flat only', [[1, 1, 1], 70, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['tie prefers flat', [[1, 1, 1], 5.5, [['PADDED', 12, 9, 1, 2200]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['PADDED', 2200]], ['generated mix 42', [[4, 1, 12], 1.2, [['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['WEIGHT', 1100]], ['generated mix 50', [[7, 1, 11], 70, [['PADDED', 12, 9, 1, 2200], ['SMALL', 8, 5, 2, 1045], ['MEDIUM', 11, 8, 5, 1740], ['LARGE', 12, 12, 6, 2395]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['MEDIUM', 1740]]]]
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 |
|---|---|---|---|
| weight cheaper | ['WEIGHT', 900] | ['WEIGHT', 900] | Passed |
| fraction rounds up | ['WEIGHT', 1600] | ['WEIGHT', 1600] | Passed |
| flat cheaper | ['MEDIUM', 1740] | ['MEDIUM', 1740] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| expensive box listed first | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| tie prefers flat | ['PADDED', 2200] | ['PADDED', 2200] | Passed |
| generated mix 8 | ['WEIGHT', 900] | ['WEIGHT', 900] | Passed |
SHA-256 / d4cba0c719c73639f3be07900aa341292c1f10b460198bd8b6e2b7afcb61ff9a
Verification & scope
Single zone weight table; stipulated flat box catalogue. 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:52:15.537256+00:00.
Case digest / eef1c2d405516a06092560a18b054c827361548595376e1e55e48f3d9b05463f