Intelligence test questions often encounter similar logic questions, giving you several cups with different capacities and asking you to pour out how much water.
There is a game on Android called Water Logic.
I installed this game and played through dozens of levels. I feel that the level design of this game is very poor. The difficulty of the levels does not increase incrementally. Many later levels are quite mentally retarded and lack high-difficulty levels.
As programmers, we should have no problem solving this type of problem. We can easily solve problems within 10 steps. We can also solve problems with more than 10 steps, but we may not be able to easily reach the minimum number of steps.
A player and programmer with 3 stars of obsessive-compulsive disorder has written such a small automatic solution program, and this problem will no longer be a problem in the future.
Click here to try to automatically solve the cup pouring problem
Basic logic of algorithm:
Each cup has the operations of filling, emptying, and pouring into other cups, so the total is: Number of cups * (Number of cups - 1 2)
For 3 cups, there are 12 optional operations for each step. If there are 2 cups, there are 6 optional operations for each step.
Traverse each operation, record the amount of water in each cup after the operation is completed, and calculate a key based on the amount of water to create a map.
During the process of traversing various pouring operations, if the key already exists and the current number of steps is greater than the number of previously recorded steps, the operation will be discarded.
This small program can only solve the problem of pouring water into 2 or 3 cups. It is not written to be universal for N cups. The code has a lot of hard code.