"""Exact whole-pack cost envelope from Baymard's historical printed example.
Assumes equivalent products, no delivery/promotions, indivisible packs, required quantity known.
"""
from decimal import Decimal
from pathlib import Path
import csv
def best(q):
 q=Decimal(str(q));poss=[(17*a+25*b,a,b,Decimal('13.5')*a+Decimal('33.8')*b) for a in range(7) for b in range(4) if Decimal('13.5')*a+Decimal('33.8')*b>=q]
 return min(poss)
p=Path(__file__).parent/'data';p.mkdir(exist_ok=True)
with (p/'unit-price-discrete-packs.csv').open('w',newline='') as f:
 w=csv.writer(f);w.writerow(['required_oz','minimum_cost_usd','small_packs','large_packs','supplied_oz','surplus_oz'])
 for i in range(1,601):
  q=Decimal(i)/10;c,a,b,quantity=best(q);w.writerow([q,c,a,b,quantity,quantity-q])
assert best(10)[:3]==(17,1,0) and best(14)[:3]==(25,0,1) and best(34)[:3]==(42,1,1)
print('Whole-pack optimizer passes10oz,14oz,34oz known answers')
