this is not about getting an answer for this problem, but to create models for solve them, below I will show a simple puzzle in order to demonstrate what I mean:
Lets say two friends just left a bar with 8 liters of alcohol in an weird bottle with 8 liters. You on the other hand want half of this amount, and he is willing to give it to you based on your friendship. However you have two bottles one with 5 liters and the other one with 3. And you want to divide it the in a half while keeping your own bottles.
Things that must assume as true: 1. You won't be able to calculate the volume of any bottle based on its shape (not even with surface integrals, weird theorems from vector calculus, etc) 2. You don't have anything to measure any volume despite of the bottles.
So to make it simpler to understand:
three bottles:
-> 8 liters (full)
-> 5 liters
-> 3 liters
And each person must have 4 liters
(at the end of changing fluids from one bottle to another one)
One solution:
Fill the 3 one with the 8.
Then, move from 3 to five.
Then, fill again the 3 one.
Fill the 5 one (and there will be one liter left in the 3)
then fill the 8, with the 5, move the one liter to the 5 and finally fill the 3.
There you'll have:
-> 8 (filled with 4)
-> 5 (filled with 1)
-> 3 (full)
My question:
This kind of problem is not so hard to solve, but how to create models to solve them ? Or perhaps an algorithm to do this kind of task ?
Often, the stupid straightforward thing works very well.
You can model the current distribution of alcohol as simply being a triple of numbers saying how much is contained in each bottle.
e.g. you start at
(8,0,0)Then, you simply go over each possible distribution of alcohol and try everything you can do from that state.
e.g. from
(8,0,0)you can go to(3,5,0)or(5,0,3)If you only consider distributions that can be reached in your search (e.g. you wouldn't consider the distribution
(3,2,3)until you've already shown you can reach it), and take care not to duplicate work (e.g. you remember that you've considered(3,2,3), so if you see it a second time, you don't spend more time considering it again), then you will have a rather efficient algorithm.Following this algorithm:
And stop. The path 15 <- 13 <- 11 <- 9 <- 7 <- 5 <- 2 <- 1 lets us wind up with a desired solution. By the way I've ordered the search, I think we're even guaranteed that there cannot be any shorter strategies. (Yours, I'm guessing, would be #16 on my list if I kept going, and has the same length)
The hardest part, when doing this by hand, is that it's often easy to overlook a move. A computer has no trouble with this algorithm, of course.