Part 1
Description
The elves bought too much eggnog again -150
liters this
time. To fit it all into your refrigerator, you'll need to move it
into smaller containers. You take an inventory of the capacities of the
available containers.For example, suppose you have containers of size
20
, 15
, 10
, 5
, and 5
liters. If you need to store 25
liters, there are four ways to do it:15
and10
20
and5
(the first5
)20
and5
(the second5
)15
,5
, and5
150
liters of eggnog?Input
Solution
For this problem, I decided to put all possible combinations and filtered them out. And, since there are 20 containers (my input), there are2^20 = 1048576
possible combinations. Here is my Excel sheet:I put this formula in AO1:
=SUMPRODUCT(U1:AN1,A$3:T$3)
and the similar formula for the rest of the cells. For solution, I counted only cells with sum of 150.
Part 2
Description
While playing with all the containers in the kitchen, another load of eggnog arrives! The shipping and receiving department is requesting as many containers as you can spare.Find the minimum number of containers that can exactly fit all
150
liters of eggnog. How many different ways can you fill that number of containers and still hold exactly 150
litres?In the example above, the minimum number of containers was two. There were three ways to use that many containers, and so the answer there would be
3
.Solution
To find the solution for part 2, I put this formula in AP1:=IF(AO1=150,SUM(U1:AN1),"")
and count the smallest number among them using:
=SMALL(AP:AP,1)
and finally, another formula to find how many times it appeared:
=COUNTIF(AP:AP,4)
0 komentar:
Post a Comment