Comments on: The Math of Optimal Shopping Sprees
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees/
Comments on Ask MetaFilter post The Math of Optimal Shopping SpreesSun, 16 Apr 2006 14:37:16 -0800Sun, 16 Apr 2006 14:37:16 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: The Math of Optimal Shopping Sprees
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees
I need to spend at least $25 at the grocery store to claim a discount. I want to minimize how much I go over $25.
I have a list of a half a dozen items I want and their prices.
Is there a program that can generate shopping lists that would meet the criteria? I want more than just the optimal list because I can get this discount repeatedly and I don't want to buy the same thing each time.post:ask.metafilter.com,2006:site.36435Sun, 16 Apr 2006 14:28:27 -0800storyboredmathgroceryshoppingBy: jamescridland
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565532
I'd have thought that an Excel sheet could produce something for you; but a bit of programming would be required. But, probably better, why not just carry a calculator (or use your cellfone's) while you wander round the store? That way you buy what you want, AND make sure you only just go above $25.comment:ask.metafilter.com,2006:site.36435-565532Sun, 16 Apr 2006 14:37:16 -0800jamescridlandBy: zpousman
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565537
This is a trivial problem to solve if you're a programmer. But it's so specific that there is probably not an existing program to do exactly this (especially since there has to be some way to enter the products you (may) want into the system.<br>
<br>
You might be able to get excel to spit out a list like this, if you knew some VB (or VB.net). If you're not a programmer then you may want to just work up 4 or 5 different grocery lists that meet your criteria and leave it at that. This may be even better than a computer program, because the program won't know things like "almost never buy mustard, since it lasts months" and so a program might spit out hundreds of shopping lists that, while they accomplish the mathematical goals (being over $25 but less than $26) will have lots of sub-optimal lists in them. Just sayin'.comment:ask.metafilter.com,2006:site.36435-565537Sun, 16 Apr 2006 14:48:55 -0800zpousmanBy: frogan
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565538
Suggestion: Don't worry about optimal lists. Instead, buy multiple units of easy-to-store, non-perishable items you will <em>always </em>need. Cans of soup, cans of soda, toilet paper, shaving cream, bars of soap, etc.comment:ask.metafilter.com,2006:site.36435-565538Sun, 16 Apr 2006 14:49:56 -0800froganBy: juv3nal
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565543
Is the grocery store thing a metaphor for some other type of situation?<br>
A program seems a bit overkill if there are only 6 items with known prices. <br>
<br>
If you really wanted to, you can just tabulate.<br>
What combination gives you close to but at least $1, $2, $3 etc? You do this recursively of course: If you have an item that's priced at say $5 then to discover what combinations will give you $25, you can use one of that $5 item plus any of the combinations that work for $20.comment:ask.metafilter.com,2006:site.36435-565543Sun, 16 Apr 2006 14:54:22 -0800juv3nalBy: joeblough
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565549
isnt this 1d bin-packing? and as such is NP-hard? IIRC then there is no polynomial-time algorithm that can optimally solve the problem, just approximations. i was really bad at computational theory though...comment:ask.metafilter.com,2006:site.36435-565549Sun, 16 Apr 2006 15:12:56 -0800joebloughBy: weapons-grade pandemonium
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565555
Isn't this like a <a href="http://www.cs.arizona.edu/icon/oddsends/bpack/bpack.htm">packing problem?</a> I would order all the relatively inexpensive products (e.g., under five dollars) that you would consider buying into ascending order of price. Carry that list with you to the supermarket. Go and shop for whatever you want, keeping the total a few bucks under $25. Then select an item or two from your list that will take you over the top. This way you won't be a slave to the list, since most of your items will be chosen according to your needs or appetite.comment:ask.metafilter.com,2006:site.36435-565555Sun, 16 Apr 2006 15:21:47 -0800weapons-grade pandemoniumBy: delmoi
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565556
<i>isnt this 1d bin-packing? and as such is NP-hard? IIRC then there is no polynomial-time algorithm that can optimally solve the problem, just approximations. i was really bad at computational theory though...</i><br>
<br>
Hmm, I think it may be, however there are only six items and $25 total, so you could still search exhaustively. <br>
<br>
The NP-ness, however, would make it impossible to do by hand.comment:ask.metafilter.com,2006:site.36435-565556Sun, 16 Apr 2006 15:23:42 -0800delmoiBy: Kwantsar
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565567
Perhaps I'm missing the point, but isn't this the exact problem that <a href="http://www.econ.ucla.edu/riley/104/LPSolver(IE).htm">solver </a>was built for?<br>
<br>
If I understand the question correctly, I think I could do this in under 2 minutes without touching VBA. All you need to do is change a constraint (say, buy no more than three cans of spinach, then buy no more than two cans, etc)comment:ask.metafilter.com,2006:site.36435-565567Sun, 16 Apr 2006 16:01:10 -0800KwantsarBy: devilsbrigade
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565572
This is exactly the packing problem. Excel can do this; a perl script can do this; you can do this by hand (and you can approximate fairly easily, especially if you know the distribution of prices of your items).comment:ask.metafilter.com,2006:site.36435-565572Sun, 16 Apr 2006 16:07:39 -0800devilsbrigadeBy: juv3nal
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565582
<em>The NP-ness, however, would make it impossible to do by hand.</em><br>
<br>
The general problem is impossible, but with 6 items/$25?<br>
A <a href="http://www.macs.hw.ac.uk/~alison/ds98/node122.html">dynamic programming approach</a> gives you something in O(NxM), and assuming "to within a dollar" is good enough for you, that should yield a table with only 150 elements unless I'm missing something.comment:ask.metafilter.com,2006:site.36435-565582Sun, 16 Apr 2006 16:22:57 -0800juv3nalBy: Frank Grimes
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565665
I second the Excel solver. <br>
<br>
Is this coupon available to others? On the Internet? How can I get one of these coupons?comment:ask.metafilter.com,2006:site.36435-565665Sun, 16 Apr 2006 19:29:41 -0800Frank GrimesBy: joeblough
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565667
yeah, i guess i didnt even read the OP well enough to see that it was a trivial # of goods. i just got went all academic on everyone's ass for no good reason :)comment:ask.metafilter.com,2006:site.36435-565667Sun, 16 Apr 2006 19:30:13 -0800joebloughBy: Sharcho
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565837
I just do what frogan said -- buy non-perishable items.<br>
<br>
Before they pass the least important items through the barcode reader, just ask "how much does this total to?" and leave the extra items you don't need.comment:ask.metafilter.com,2006:site.36435-565837Mon, 17 Apr 2006 05:52:14 -0800SharchoBy: Robert Angelo
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#565890
Backing up a bit... If you want to use this program repeatedly, how are you going to keep track of price changes? You can't just set everything up in your Excel spreadsheet and assume that you're ready to go, since prices are changing every week, sometimes faster. I agree that it's more practical to just keep track of the total as you're shopping (with calculator) or else ask at the checkout what is the total and then leave the items you don't want.comment:ask.metafilter.com,2006:site.36435-565890Mon, 17 Apr 2006 07:24:03 -0800Robert AngeloBy: storybored
http://ask.metafilter.com/36435/The-Math-of-Optimal-Shopping-Sprees#566175
Thanks for the answers everyone. I basically took the manual approach and figured out three options on paper using a calculator. I was curious to know if there was a website/utility that did this with minimal learning curve but after checking out the suggestions, the calculator was just plain faster. <br>
<br>
But it was so cool to tie this to packing problems and NP completeness! That is very neat.<br>
<br>
Frank, the coupon's only available here in Ottawa, Can. at a particular store, today.comment:ask.metafilter.com,2006:site.36435-566175Mon, 17 Apr 2006 12:07:13 -0800storybored