First puzzle
This puzzle looks like a classic optimization problem. We have a set of buckets, and we need to find all the combinations where we could fit a volume of 150 liters. The solution is how many combination exists. On the example from the puzzle description, we have the following buckets: 20, 15, 10, 5 and 5 and we need to fit 25 liters. The combinations are:
- 15 and 10.
- 20 and 5 (first 5)
- 20 and 5 (second 5)
- 15, 5, and 5
In this example, the solution is 4.
The input parsing is minimum here, but there is some:
To find all the combinations we could a recursive function taking the first bucket and executing the function on the tail with a volume decrease of that bucket capacity:
Second puzzle
The second puzzle is to find all the combinations where the minimum number of buckets are used:
You can find this code along with my input and puzzle answers at here.