Dustin
Dustin

Reputation: 185

Summation Puzzle instruction

I am about to start on the program send + more = money. The instructions in my book really wasn't all that clear. I'm not asking for code at all, I will do that. I just need some clarification on what is suppose to actually happen in this program. Here is the instructions straight from the book. "Using backtracking, write a program that solves summation puzzles in which each letter should be replaced by a digit, such as Send + More = Money. Other examples are "base + ball = games" and "Kyoto + Osaka = Tokyo. That's all it says, any clarification would be greatly appreciated!

Upvotes: 1

Views: 3310

Answers (3)

Simon
Simon

Reputation: 6363

I think it means that you need to find what substitutions make these equations true. So for example for a + b = b then a has to be 0 and b can be anything.

Upvotes: 1

wim
wim

Reputation: 363294

I think you have to write an algorithm to find the digits which make the sum work.

For example, send + more = money could be like 9567 + 1085 = 10652.

I have made the substitution e=5, o=0, etc.

Upvotes: 2

user555045
user555045

Reputation: 64913

Apparently this is known as verbal arithmetic.

The point is that you have three numbers, the letters form the digits in those numbers, and the sum of the first two numbers equals the third.

What has to happen to "solve" such a puzzle is that you find values for the digits such that the sum is correct. With simple backtracking, an obvious strategy is to just try choosing 0 through 9 (but a value that you haven't used yet) for every different digit, when all digits have a value you check whether the sum is correct. There are some tricks you can use to restrict your search space.

Upvotes: 4

Related Questions