Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram to optimize cost
    text
    copied!<p>This is my problem set for one of my CS class and I am kind of stuck. Here is the summary of the problem.</p> <pre><code>Create a program that will: 1) take a list of grocery stores and its available items and prices 2) take a list of required items that you need to buy 3) output a supermarket where you can get all your items with the cheapest price input: supermarkets.list, [tomato, orange, turnip] output: supermarket_1 The list looks something like supermarket_1 $2.00 tomato $3.00 orange $4.00 tomato, orange, turnip supermarket_2 $3.00 tomato $2.00 orange $3.00 turnip $15.00 tomato, orange, turnip If we want to buy tomato and orange, then the optimal solution would be buying from supermarket_1 $4.00. Note that it is possible for an item to be bough twice. So if wanted to buy 2 tomatoes, buying from supermarket_1 would be the optimal solution. </code></pre> <p>So far, I have been able to put the dataset into a data structure that I hope will allow me to easily do operations on it. I basically have a dictionary of supermarkets and the value would point to a another dictionary containing the mapping from each entry to its price.</p> <pre><code>supermarket_1 --&gt; [turnip --&gt; $2.00] [orange --&gt; $1.50] </code></pre> <p>One way is to use brute force, to get all combinations and find whichever satisfies the solution and find the one with the minimum. So far, this is what I can come up with. <strong>There is no assumption that the price of a combination of two items would be less than buying each separately.</strong></p> <p>Any suggestions hints are welcome</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload