SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Thread: Xmas Sum Puzzle

  1. #1
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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...
    Azizur Rahman
    Web Application Developer

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    x=0
    m=0
    a=0
    s=0
    Code:
    0000
    0000-
    0000
    Sketch
    Aaron Brazell
    Technosailor



  4. #4
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Aaron Brazell
    Technosailor



  6. #6
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #7
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #8
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    49 :-D

  9. #9
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #10
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #11
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #12
    is very happy now :) Itay Neeman's Avatar
    Join Date
    Jun 2000
    Location
    Israel
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...
    Itay - [email] [icq]
    Darklight Studios - Bringing light into gaming
    Pretzel Wisdom
    - Mine... All Mine! coming soon...

  13. #13
    SitePoint Enthusiast Daniel's Avatar
    Join Date
    Dec 1999
    Location
    Belfast
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).
    Daniel Irvine
    Aroze - Content management simplified.
    F-Free.Net - Free Stuff and Freebies!

  14. #14
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #15
    SitePoint Enthusiast Daniel's Avatar
    Join Date
    Dec 1999
    Location
    Belfast
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Last edited by Daniel; Jan 2, 2002 at 13:05.
    Daniel Irvine
    Aroze - Content management simplified.
    F-Free.Net - Free Stuff and Freebies!

  16. #16
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    Last edited by Husain; Jan 2, 2002 at 13:18.

  17. #17
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Saz: Naturally Blonde, Naturally Dizzy!
    No longer Editor of the Community Crier.

    Don't mind me, I'm having a BLONDE moment!

  18. #18
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #19
    is very happy now :) Itay Neeman's Avatar
    Join Date
    Jun 2000
    Location
    Israel
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could someone post the source of a script that works please?

    I'm very interested in seeing it...
    Itay - [email] [icq]
    Darklight Studios - Bringing light into gaming
    Pretzel Wisdom
    - Mine... All Mine! coming soon...

  20. #20
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #21
    SitePoint Enthusiast Daniel's Avatar
    Join Date
    Dec 1999
    Location
    Belfast
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Daniel Irvine
    Aroze - Content management simplified.
    F-Free.Net - Free Stuff and Freebies!

  22. #22
    is very happy now :) Itay Neeman's Avatar
    Join Date
    Jun 2000
    Location
    Israel
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    :=(1000) + (100) + (10) + m;
                              
    msxa:=(1000) + (100) + (10) + a;
                              
    xmas:=(1000) + (100) + (10) + s;
                              if (
    x<>m) and (x<>a)and (x<>s) and (m<>a) and (m<>s) and (s<>athen
                                 
    if (axsm-msxa=xmasthen
                                 begin
                                      write
    (x,m,a,s);
                                      
    writeln;
                                 
    end;
                         
    end;
         
    readln;
    end
    Enjoy.
    Itay - [email] [icq]
    Darklight Studios - Bringing light into gaming
    Pretzel Wisdom
    - Mine... All Mine! coming soon...

  23. #23
    SitePoint Guru jkcity's Avatar
    Join Date
    May 2001
    Location
    England
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. #24
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    Azizur Rahman
    Web Application Developer


Bookmarks

Posting Permissions

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