Newspapers and magazines often have crypt-arithmetic puzzles of the form:
Input : s1 = SEND, s2 = "MORE", s3 = "MONEY" Output : One of the possible solution is: D=1 E=5 M=0 N=3 O=8 R=2 S=7 Y=6 Explanation: The above values satisfy below equation : SEND + MORE -------- MONEY --------
It is strongly recommended to refer Backtracking | Set 8 (Solving Cryptarithmetic Puzzles) for approach of this problem.
The idea is to assign each letter a digit from 0 to 9 so that the arithmetic works out correctly. A permutation is a recursive function which calls a check function for every possible permutation of integers.
Check function checks whether the sum of first two numbers corresponding to first two string is equal to the third number corresponding to third string. If the solution is found then print the solution.
Solution found: D=1 E=5 M=0 N=3 O=8 R=2 S=7 Y=6
- Solving Cryptarithmetic Puzzles | Backtracking-8
- C++ Program for ShellSort
- Program for n-th even number
- C++ Program for QuickSort
- C Program for ID3 Tagging
- Wishing your Valentine with a Program!!
- C++ Program for Pigeonhole Sort
- C++ Program for Cocktail Sort
- C++ Program for Cycle Sort
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- C++ Program for Stooge Sort
- C++ Program for Comb Sort
- C++ Program to find whether a no is power of two
- C++ Program for Topological Sorting
- Program to print the given H Pattern
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.