1. ## Xmas Sum Puzzle

Hi Everyone,

See if you can solve this problem.

Its XMAS SUM PUZZLE
In the sum below each letter stand for a different single digit number

Work out which number each letter stands for

Code:
```AXSM
MSXA (-)
--------
XMAS```

Basically what are the value for X,M,A and S?

Happy Solving and New Year...

2. ## The equation is wrong.

Hmmm. Don't you think there is a mistake in that equation? Here's the logic as I see it:
Code:
```+a - m = x
-a + m = s
----------
0   0 = ?```
In the above, x-s has to be zero, but it is not. It is m.

Check your equation. There is something wrong with it (or PM me the answer ).

3. x=0
m=0
a=0
s=0
Code:
```0000
0000-
0000```
Sketch

4. Originally posted by Sketch
x=0
m=0
a=0
s=0
Code:
```0000
0000-
0000```
Sketch
True, but the original question says that all numbers are different (x != m != a !=s )

5. I even looked to see if it said that and I could have swore it didn't. Now I see it though. Oh well.

Sketch

6. I don't think there is an answer to it.

I created a program that should have found the answer and it failed but my programming usually fails anyway hehehe

7. Originally posted by jkcity
I don't think there is an answer to it.

I created a program that should have found the answer and it failed but my programming usually fails anyway hehehe
You too! Even I created a Java program and I am sure mine works. It tried out all the 130321 possible combinations and none of them matched the equation!

8. 49 :-D

9. Originally posted by husain
You too! Even I created a Java program and I am sure mine works. It tried out all the 130321 possible combinations and none of them matched the equation!
Must have been my programming then as I worked out that there was less than 9000 combinations it could possibly be following the rules and only 9999 possible combinations if any letter could be any number.

just to add I used VB, I would post the souce for you all to check but i crashed VB when I was testing the program and I forgot to save it.

10. Originally posted by jkcity
Must have been my programming then as I worked out that there was less than 9000 combinations it could possibly be following the rules and only 9999 possible combinations if any letter could be any number.
Your program might be correct. When I wrote the code, I assumed that any number from -9 to +9 was accepted. But even taking negative numbers into consideration did not help. Refer to my first post for the reason.

Should I post my code here?

11. It might be in hex and not deciminal, there is no way I can be bothered to right another program though to see if it is though, as its a long shot.

12. I decided to do something useful with my programming "skills", I wrote a program in pascal, which failed to find a number as well...

V. weird...

13. Yes there is a solution

There are only 5040 different possibilities for a four-digit number with all digits different. (10 possible digits to choose from, 4 to choose, therefore total is 10!/(10-4)! = 10x9x8x7 = 5040).

14. Originally posted by Daniel
Yes there is a solution

There are only 5040 different possibilities for a four-digit number with all digits different. (10 possible digits to choose from, 4 to choose, therefore total is 10!/(10-4)! = 10x9x8x7 = 5040).
Thats not the answer to the puzzle though?

15. Well if you insist...

X=6, M=1, A=7, S=4.

I have to admit I did cheat and I wrote a PHP script to do it for me. I tried to work it out using algebra but it got very complicated and hence I gave up.

16. ## The solution is wrong!

Originally posted by Daniel
Well if you insist...

X=6, M=1, A=7, S=4.

I have to admit I did cheat and I wrote a PHP script to do it for me. I tried to work it out using algebra but it got very complicated and hence I gave up.
I am afraid your solution is wrong!

Code:
```x - s = m (according to the original equation)
6 - 4 = 2 (m according to your answer is 1)

s - x = a (according to the original equation)
4 - 6 = -2

The other two equations are correct.```

17. He's right husain....

Replacing the letters with the numbers you get the sum...
Code:
``` 7 6 4 1
-1 4 6 7
---------
6 1 7 4```
You can't subtract 7 from 1 so you have to take one from the 10's column, making that 3 and giving you:
11 - 7 = 4 for the units.

You then can't subtract 6 from 3, so you have to take one from the 100's column, making that 5 and giving you:
13 - 6 = 7 for the tens.

That then leaves:
5 - 4 = 1

and:
7 - 1 = 6

18. X=6, M=1, A=7, S=4

You got it correct, good programming.

The funny thing is my program should have found that it cycled through them numbers definatly I think I know what went wrong though, My program will have taken away two numbers and did somthing like e.g 13 - 6 = 7.00000000001 which happens alot in VB if you don't declare your vairables liek I did not, Guess it teaches me not to be to lazy in future.

19. Could someone post the source of a script that works please?

I'm very interested in seeing it...

20. Originally posted by jkcity
The funny thing is my program should have found that it cycled through them numbers definatly I think I know what went wrong though.
I think we missed out programming the borrowing business from the units and tens.

Plus, I completely overlooked the borrowing and assumed that 1 - 7 was -6. I tried to act over-smart

I would also like to see the PHP code that Daniel has written.

21. PHP Code:
``` <? /* AXSM MSXA (-) -------- XMAS */ for (\$x = 0; \$x <= 9; \$x++) {    for (\$m = 0; \$m <= 9; \$m++) {       for (\$a = 0; \$a <= 9; \$a++) {          for (\$s = 0; \$s <= 9; \$s++) {             if (\$x != \$m && \$x != \$a && \$x != \$s && \$m != \$a && \$m != \$s && \$a != \$s)             {                /* the numbers are all different, so check if the sum works */                \$axsm = (\$a * 1000) + (\$x * 100) + (\$s * 10) + \$m;                \$msxa = (\$m * 1000) + (\$s * 100) + (\$x * 10) + \$a;                \$xmas = (\$x * 1000) + (\$m * 100) + (\$a * 10) + \$s;                if (\$axsm - \$msxa == \$xmas) { echo "x = \$x, m = \$m, a = \$a, s = \$s"; exit; }             }          }       }    } } ?> ```
I am not sure if this is the most efficient way to do this. I'd be interested to know if anybody has a better way.

Regards,
Daniel Irvine

22. Thanks to daniel's program I managed to fix mine, and it now works, and here it is:

(It's in pascal )

PHP Code:
``` program xmaspuzzle; var    x,m,a,s,axsm,msxa,xmas:integer; begin      for x:=0 to 9 do          for m:=0 to 9 do              for a:=0 to 9 do                  for s:=0 to 9 do                      begin                           axsm:=(a * 1000) + (x * 100) + (s * 10) + m;                           msxa:=(m * 1000) + (s * 100) + (x * 10) + a;                           xmas:=(x * 1000) + (m * 100) + (a * 10) + s;                           if (x<>m) and (x<>a)and (x<>s) and (m<>a) and (m<>s) and (s<>a) then                              if (axsm-msxa=xmas) then                              begin                                   write(x,m,a,s);                                   writeln;                              end;                      end;      readln; end.  ```
Enjoy.

23. Originally posted by husain
I think we missed out programming the borrowing business from the units and tens.
Nah I know mine cycled through them numbers as

x, m, a, s, were all incremented one at a time and went through all possible variousations.

It will have been the two numbers producing a real long decimal number which is a problem in VB somtimes, I was going to stop this from happening but I tried to slow down my program to see if this was actually happening and thats why I crashed it

24. ## I never thought it generate that many replies

OK I am not a hardcore Java or PHP programmer.

I did not use Java or VB or any conventional procedurial/serial programming Language.

I've used Higer level programming even then it failed.

I've used Prolog here is the code:

Prolog:
Code:
```solve(A,B,C):-
between(0,9,A),
between(0,9,B),
between(0,9,C),
A + B + C =:= 13,
B - A - C =:= 1,
A + B - C =:= 11.

/*****************************************************************************/
/* XMAS SUM PUZZLE                                                           */
/*                                                                           */
/* In the sum below each letter stand for a different single digit number    */
/*                                                                           */
/* Whork out which number each letter stands for                             */
/*                                                                           */
/*   A X S M                                                                 */
/*   M S X A  -                                                              */
/*  ___________                                                              */
/*   X M A S                                                                 */
/*                                                                           */
/*****************************************************************************/

solve_xmas_sum(X,M,A,S):-
% Range of single digits
between(0,9,X),
between(0,9,M),
between(0,9,A),
between(0,9,S),

% To make the programm efficient check for enaquality before doing the sum
X =\= M, X =\= A, X =\= S,
M =\= A, M =\= S,
A =\= S,

% Do the Sum
M - A =:= S,
S - X =:= A,
X - S =:= M,
A - M =:= X.```
OK, those of you are used to work with Logic and possibly prolog will understand the code, but for the programmer of serial and procedurial people programming in Prolog is different and you'll need to swich of that part of mind to undersand this.

if you have SWI-Prolog you can use this code to test this program.

First test the solve(A,B,C).
it should give you:
A = 5
B = 7
C = 1 <press enter>

YES

now if you do

solve_xmas_sum(X,M,A,S).

It will say no, because may be I've problem with my code or may be there is no answer to it.

Until I go an speak to my Professor I cant really say which is correct. So you'll have to wait for my nest post to find out the real answer.

Now I is there anyone interested in learing Prolog? I'll teach what I know for free, simply because I want keep my mind active. and if you are really generous in return you can tech me Java.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•