FA-95626 / Shipping rate zone lookup / Open access
Flat vs weight: box dims not rotated · case 01
Items that fit a flat box on their side are told the box is too small.
ROOT CAUSE
Box inner dimensions are compared in catalogue order against sorted item dims.
VERIFIED REPAIR
Sort both item and box dimensions before comparing.
Unsuccessful approach: Leaving item dims unsorted still depends on how the item was measured.
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, [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 = [[['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 3', [[12, 7, 4], 9.1, [['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]], ['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]], ['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]], ['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 7', [[1, 10, 8], 10, [['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 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 26', [[2, 7, 4], 5.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]], ['SMALL', 1045]], ['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 18', [[1, 10, 4], 70.4, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 41', [[5, 4, 2], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 55', [[8, 4, 4], 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]], ['MEDIUM', 1740]], ['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 67', [[7, 11, 2], 12, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 77', [[12, 1, 10], 10, [['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]], ['LARGE', 2395]], ['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]]], [['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 7', [[1, 10, 8], 10, [['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]], ['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]], ['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 43', [[11, 10, 8], 1.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', 1100]], ['generated mix 51', [[2, 11, 11], 12, [['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]], ['LARGE', 2395]], ['generated mix 59', [[1, 5, 11], 70.4, [['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]], ['NONE', 0]]]]
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 |
|---|---|---|---|
| flat cheaper | ['WEIGHT', 2200] | ['MEDIUM', 1740] | Failed |
| generated mix 3 | ['WEIGHT', 3400] | ['LARGE', 2395] | Failed |
| weight cheaper | ['WEIGHT', 900] | ['WEIGHT', 900] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| fraction rounds up | ['WEIGHT', 1600] | ['WEIGHT', 1600] | Passed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| generated mix 7 | ['WEIGHT', 3400] | ['MEDIUM', 1740] | Failed |
| generated mix 15 | ['WEIGHT', 3400] | ['LARGE', 2395] | Failed |
SHA-256 / 211d54dd8d7b402857357e393e98c293debf7c73f4661f6686bf5b6d6951a443
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 = list(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 = [[['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 3', [[12, 7, 4], 9.1, [['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]], ['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]], ['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]], ['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 7', [[1, 10, 8], 10, [['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 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 26', [[2, 7, 4], 5.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]], ['SMALL', 1045]], ['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 18', [[1, 10, 4], 70.4, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 41', [[5, 4, 2], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 55', [[8, 4, 4], 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]], ['MEDIUM', 1740]], ['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 67', [[7, 11, 2], 12, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 77', [[12, 1, 10], 10, [['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]], ['LARGE', 2395]], ['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]]], [['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 7', [[1, 10, 8], 10, [['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]], ['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]], ['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 43', [[11, 10, 8], 1.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', 1100]], ['generated mix 51', [[2, 11, 11], 12, [['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]], ['LARGE', 2395]], ['generated mix 59', [[1, 5, 11], 70.4, [['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]], ['NONE', 0]]]]
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 |
|---|---|---|---|
| flat cheaper | ['WEIGHT', 2200] | ['MEDIUM', 1740] | Failed |
| generated mix 3 | ['WEIGHT', 3400] | ['LARGE', 2395] | Failed |
| weight cheaper | ['WEIGHT', 900] | ['WEIGHT', 900] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| fraction rounds up | ['WEIGHT', 1600] | ['WEIGHT', 1600] | Passed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| generated mix 7 | ['LARGE', 2395] | ['MEDIUM', 1740] | Failed |
| generated mix 15 | ['LARGE', 2395] | ['LARGE', 2395] | Passed |
SHA-256 / 9c6bd604d3e46762f0fca627e0923c901ed802c08cc52254819379be377abc28
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 = [[['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 3', [[12, 7, 4], 9.1, [['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]], ['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]], ['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]], ['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 7', [[1, 10, 8], 10, [['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 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]]], [['generated mix 15', [[5, 12, 2], 9.1, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 26', [[2, 7, 4], 5.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]], ['SMALL', 1045]], ['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 18', [[1, 10, 4], 70.4, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['NONE', 0]]], [['generated mix 41', [[5, 4, 2], 5.5, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['SMALL', 1045]], ['generated mix 55', [[8, 4, 4], 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]], ['MEDIUM', 1740]], ['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 67', [[7, 11, 2], 12, [['LARGE', 12, 12, 6, 2395], ['SMALL', 8, 5, 2, 1045]], [900, 1100, 1350, 1600, 1900, 2200, 2500, 2800, 3100, 3400]], ['LARGE', 2395]], ['generated mix 77', [[12, 1, 10], 10, [['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]], ['LARGE', 2395]], ['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]]], [['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 7', [[1, 10, 8], 10, [['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]], ['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]], ['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 43', [[11, 10, 8], 1.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', 1100]], ['generated mix 51', [[2, 11, 11], 12, [['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]], ['LARGE', 2395]], ['generated mix 59', [[1, 5, 11], 70.4, [['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]], ['NONE', 0]]]]
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 |
|---|---|---|---|
| flat cheaper | ['MEDIUM', 1740] | ['MEDIUM', 1740] | Passed |
| generated mix 3 | ['LARGE', 2395] | ['LARGE', 2395] | Passed |
| weight cheaper | ['WEIGHT', 900] | ['WEIGHT', 900] | Passed |
| over 70 | ['NONE', 0] | ['NONE', 0] | Passed |
| fraction rounds up | ['WEIGHT', 1600] | ['WEIGHT', 1600] | Passed |
| 70 lb flat only | ['SMALL', 1045] | ['SMALL', 1045] | Passed |
| generated mix 7 | ['MEDIUM', 1740] | ['MEDIUM', 1740] | Passed |
| generated mix 15 | ['LARGE', 2395] | ['LARGE', 2395] | Passed |
SHA-256 / ccdcdd4ca09b2af9888a2d79eb8d70beb5378778d9afbdfcd5bb756401923a37
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.422121+00:00.
Case digest / 199b6a5f716e463e842bcf986e52d2a8a1ff24248244eac892e51cbff54ca636