Question
Please help me with the following practice question that has to do with recursion : In project 0, we saw that we can check if
Please help me with the following practice question that has to do with recursion : In project 0, we saw that we can check if a solution is valid to summation puzzles. In this assignment, we're going to solve summation puzzles. In a summation puzzle, you are given three strings of the form POT + PAN = BIB. Typically each is a word, often with a theme to the three chosen. Your goal is to assign a distinct digit to each letter in the equation in order to make the resulting true. For example, if the puzzle is POT + PAN = BIB, the mapping P:2, O:3, T:1, A:7, N:4, B:5, I:0 will solve this, as 231 + 274 = 505
You are required to implement the function puzzleSolver in proj1.cpp. This function should return true if, and only if, the puzzle is solvable: that is, if there is a mapping of the letters that appear in the three strings to distinct digits such that the sum of the first two is the third. No string will have a value larger than 4,294,967,295 in its correct substitution, nor will the addition have any integer-overflow to check for. If you do not know what integer overflow is, you do not need to check during this assignment (although it's worth knowing in general). For this project, you have a few requirements: You must implement the function puzzleSolver in proj1.cpp. You may assume it is called with three valid non-empty strings as parameters and with an otherwise empty map. The strings will always consist only of all-capital letters. The puzzle solution may have a leading zero for a string. For example, in the provided test cases, we see that "UCI + ALEX = MIKE" has a solution. This corresponds to 572 + 8631 = 9203. The puzzle "KUCI + ALEX = MIKE" also has a solution with the same mapping. Your solution must explicitly use recursion in a meaningful way towards solving the problem. You may not solve this by using a function like std::next_permutation (from
#include "proj1.hpp" #include #include bool puzzleSolver(std::string s1, std::string s2, std::string s3, std::unordered_map & mapping) { return true; // This is not the correct general solution. }
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