Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program for solving summation puzzles by enumerating and testing all possible configurations. Using your program solve the three puzzles given in 5.3.3 3.5.3
Write a program for solving summation puzzles by enumerating and testing all possible configurations. Using your program solve the three puzzles given in 5.3.3
3.5.3 Multiple Recursion Generalizing from binary recursion, we use multiple recursion when a function may make multiple recursive calls, with that number potentially being more than two. One of the most common applications of this type of recursion is used when we want to enumerate various configurations in order to solve a combinatorial puz- zle. For example, the following are all instances of summation puzzles pot + pan bib dog+ cat = pig boy + girl = baby To solve such a puzzle, we need to assign a unique digit (that is, 0,1,..,9) to each letter in the equation, in order to make the equation true. Typically, we solve such a puzzle by using our human observations of the particular puzzle we are trying to solve to eliminate configurations (that is, possible partial assignments of digits to letters) until we can work though the feasible configurations left, testing for the correctness of each one If the number of possible configurations is not too large, however, we can use a computer employing any human observations. In addition, such an algorithm can use multiple recursion to work through the configurations in a systematic way. We show pseudo- code for such an algorithm in Code Fragment 3.44. To keep the description general enough to be used with other puzzles, the algorithm enumerates and tests all k- length sequences without repetitions of the elements of a given set U. We build the sequences of k elements by the following steps to simply enumerate all 1 the possibilities and test each one, without 1. Recursively generating the sequences of k -1 elements 2. Appending to each such sequence an element not already contained in it. Throughout the execution of the algorithm, we use the set U to keep track of the elements not contained in the current sequence, so that an element e has not been used yet if and only if e is in U. Another way to look at the algorithm of Code Fragment 3.44 is that it enumer- ates every possible size-k ordered subset of U, and tests each subset for being a possible solution to our puzzle For summation puzzles, U-0,1,2,3,4,5,6,7,8,9 and each position in the sequence corresponds to a given letter. For example, the first position could stand for b, the second for o, the third for y, and so on
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started