Blue Ocean: Three ice water buckets challenge
Three ice water buckets challenge This problem is found here: http://learningandtheadolescentmind.org/resources_02_bucket.html I called it three "Ice Bucket Challenge" for fun. ;) Here is the problem description. There are an 8-liter bucket filled with ice water and empty 3-liter and 5-liter buckets. You solve the puzzle by using the three buckets to divide the 8 liters of water into two equal parts of 4 liters. Try to solve the puzzle in the fewest number of moves. Although to find a fewest number of moves is not easy, but I can design depth first search to find the necessary moves to distribute the waters. Here is the code The idea here is to for each possible case, we find the all possible cases which can be derived from it. For example, from 8, 0, 0, it could be 5, 0, 3 or 3, 5, 0. And we use a list keep track of the cases we already visited. Think of all possible cases as a graph, we essentially do a depth first search until we find the case contains 4.Read full article from Blue Ocean: Three ice water buckets challenge
No comments:
Post a Comment