The thinking game Petals around the Rose is played with five dice. It is played by a computer program or with real dice that are thrown by a Potentate of the Rose, a person who knows the secret behind the game. For each roll of the dice, there is a unique numerical solution. The players have to try to figure out the right solution through inductive reasoning. If they fail to guess the right solution, the correct solution is communicated by the Potentate of the Rose, and they must try to guess the right solution at the next throw.
The game has only three rules:The name of the game is Petals around the Rose, and this name is important.
The answer is always a non-negative even integer.
Anyone who knows the secret of the game, is allowed to give the right solution that corresponds to a particular throw, but the secret must never be revealed.
In order not to reveal the secret of the game we have stored the correct answer to the question how many petals there are around the rose in the flowerpetals.txt file. Each line of this file contains six integers, which are separated by a single space from each other. The first five integers each time indicate the number of eyes for a possible roll of five dice, while the sixth number indicates to how many petals this throw corresponds. Because the number of petals is independent of the order of the dice (oops, now we have already revealed a part of the solution) we have sorted the first five numbers each in ascending order, so that we only need to include a single line in the file if the order of the dice is the only thing that differs.
Write a function readSolutions reads the solutions for the different combinations from a text file, and uses them to construct a dictionary that is returned by the function. The location of the text file must be passed as an argument to the function. For each line of the file, the first five numbers form the elements of a tuple that is used as the key in the dictionary that is to be returned by the function as a result, and is the sixth number the value that corresponds to this key.
Write a function potentate that for a given roll of five dice indicates to how many petals around the rose the throw corresponds. Two arguments must be passed to this function. The first argument is a list of five integers between 1 and 6 (limits included). The elements of this list correspond to the number of eyes for a roll of five dice and are listed in random order. The second argument is a dictionary that contains the solution for every possible throw of five dice (such as those returned by the function readSolutions).
>>> solutions = readSolutions('flowerpetals.txt')
>>> solutions
{(1, 1, 1, 2, 3): 2, (5, 5, 5, 5, 6): 16, ..., (1, 3, 4, 4, 4): 2}
>>> potentate([3, 5, 5, 4, 3], solutions)
12
>>> potentate([6, 5, 3, 4, 2], solutions)
6