# Number Puzzle

Discussion in 'Mathematics' started by AutumnGirlSoup, Jan 27, 2011.

1. This is bugging me now, and I was wondering whether you clever folk could give me a hint about where to start or what the puzzle is called so I can google it (I did try, but couldn't find the correct one)...

You know that number puzzle where you add two three-digit numbers together to make a third three-digit number but you have to use each of the numbers from 1 to 9 once

e.g.
238
+ 145
= 383
doesn't work because 3 appears 3 times, 8 appears twice and 4, 6, 7 and 9 don't appear at all.

but
317 + 529 = 846 does

I worked out that solution and I know you can get others by transposing digits e.g. 517 + 329, 173 + 295

but what is the mathematical reasoning/logic/process behind working out the solution (other than trying numbers) or alternatively are there any other solutions apart from rearranging the positions/order of digits (while keeping the sum of each column the same)? I know I've seen it before and I vaguely seem to remember there is a trick to it, but I can't remember what it is. Any suggestions gratefully received!
Thanks

2. This is bugging me now, and I was wondering whether you clever folk could give me a hint about where to start or what the puzzle is called so I can google it (I did try, but couldn't find the correct one)...

You know that number puzzle where you add two three-digit numbers together to make a third three-digit number but you have to use each of the numbers from 1 to 9 once

e.g.
238
+ 145
= 383
doesn't work because 3 appears 3 times, 8 appears twice and 4, 6, 7 and 9 don't appear at all.

but
317 + 529 = 846 does

I worked out that solution and I know you can get others by transposing digits e.g. 517 + 329, 173 + 295

but what is the mathematical reasoning/logic/process behind working out the solution (other than trying numbers) or alternatively are there any other solutions apart from rearranging the positions/order of digits (while keeping the sum of each column the same)? I know I've seen it before and I vaguely seem to remember there is a trick to it, but I can't remember what it is. Any suggestions gratefully received!
Thanks

3. Saw this rolling off the edge of the page so thought I'd offer some thoughts.
I doubt that any algebraic approach would be helpful as you are restricting the available digits, so trial and error seems to be the best approach. This is not so unwieldy as you might suspect, especially with a short computer program to help.
My initial approach would be to choose an ordered set of three digits from the nine for the first row of the sum. This can be done in 9x8x7 = 504 ways
Of the remaining six digits, you have just 6x5x4=120 choices, and just 6 for the final row.
Thus you only have to consider 9! = 362880 possible sums, which is easy to check on a computer.
Your thought about transposing columns is complicated by the fact that there are likely to be 'carry digits' when adding since 40 out of 72 possible digit sums are 10 or more.
I'm now going to try a 'random search approach' in Excel to see if it is worth sharing!

4. OK, the 'Random search' approach worked well and the programming was far simpler!
Of course, the problem with this is that you will never prove that you have the exhaustive list of possible solutions. It simply churns out one after another, repeats and all.
Still, it has the advantage of being very quick. Solutions are found in seconds.
Open up Excel. If you haven't done so already, Enable Macros (Google how to do that if you are not sure).
Go to Tools - Macro - Record New Macro...
Give it the name "NumberPuzzle" (without quotes)
Press Record. Press Stop. That's the easy bit!
Now go to Tools - Macro - Macros... and you should see NumberPuzzle
Click it and Edit and you will see something like:
In between the Sub NumberPuzzle() and End Sub paste the following code, so that it becomes:
Sub NumberPuzzle()

Dim A, B, C, D, E, F, G, H, I As Integer
Dim Sum As Integer
Dim Solution As Boolean

Solution = False
'Assumes we haven't found a solution yet!

Do While Solution = False
Calculate
'Shuffles the digits 1 to 9 to try again
A = Range("A1").Value
B = Range("A2").Value
C = Range("A3").Value
D = Range("A4").Value
E = Range("A5").Value
F = Range("A6").Value
G = Range("A7").Value
H = Range("A8").Value
I = Range("A9").Value

UpperAddend = 100 * A + 10 * B + 1 * C
LowerAddend = 100 * D + 10 * E + 1 * F
Sum = 100 * G + 10 * H + 1 * I
'Writes down the sum to see if it works

Solution = True
End If
'If the sum is correct then it breaks out of the loop to give you a chance to write it down

Loop
'Try again if that shuffle didn't succeed

Range("C3").Value = Sum
'A solution has ben found so it is written on the worksheet

End Sub
Close the window and return to Excel. Now when you run the macro, it will think for a second and then spit out the first solution it finds in Column C. Drag this to another part of the spreadsheet (eg Column D) and run the macro again to find another solution.
I just tried this and found the following solutions:
273
546
819

318
276
594

752
184
936

567
324
891

182
394
576

624
159
783

527
319
846

654
327
981

762
183
945

193
482
675
I hope that gives you something to play with!

5. Found this;
Baffled! Still looking for possible reasons why there are 336 possible outcomes!...

6. Just out of interest, and please bear in mind that I have no idea where I am going with this, but what you are looking for is, 3 numbers given 9 added to 3 numbers given 6, and for that to equal the final 3 numbers given 3.
So this equates to;
9C3 + 6C3 = 3C3
Which turns out to be a linear eqn;
84x + 20y = 1
The graph looks quite interesting too!
Unfortunately that does not help me answer the original question - just thought it looked intersting!

7. I can concur with the link offered by Gilbert24 which found 336 solutions.
My other program in Excel (exhaustive search) found 336 as well.
Slightly more complicated programming than the 'random search' but lists them all without repeats.
PM me if you would like the spreadsheet which contains both versions of the program and the full set of solutions.
Thanks for reminding us of this great little puzzle!

8. Thank you so much for replying to my thread and for suggestions on how to tackle the puzzle. I'll have a go with excel and see what I get - whether I can match the 336 solutions.

Many thanks!