Enigmatic Code

Programming Enigma Puzzles

Enigma 1200: Nine times

From New Scientist #2356, 17th August 2002 [link]

Harry, Tom and I were trying to find a five-digit number consisting of five different digits that when we multiplied it by 9 we created another five-digit number consisting of the other five digits.

We each found a different number of this type, but the numbers that Harry and Tom found each used the same five digits.

Which five-digit number did I find? (Remember that the answer required is the number as it was before multiplication).

See also Enigma 1317.

[enigma1200]

Advertisements

5 responses to “Enigma 1200: Nine times

  1. Jim Randell 28 September 2015 at 1:33 pm

    This Python code runs in 117ms.

    from itertools import permutations
    from enigma import concat, printf
    
    # candidate numbers
    ns = list()
    
    digits = "0123456789"
    for s in permutations(digits, 5):
      if s[0] == '0': continue
      n = concat(*s)
      m = str(int(n) * 9)
      if len(m) != 5: continue
      if not(concat(*(sorted(n + m))) == digits): continue
      printf("[{n} * 9 = {m}]")
      ns.append(n)
    
    # select possibilities for Dick, Harry, Tom
    for (D, H, T) in permutations(ns, 3):
      if sorted(H) == sorted(T):
        printf("D={D} [H={H} T={T}]")
    

    Solution: You found 10647.

    10647 × 9 = 95823.

    There are only three numbers with the required property. Harry and Tom found the other two:

    10638 × 9 = 95742
    10836 × 9 = 97524.

    • Jim Randell 28 September 2015 at 2:11 pm

      A bit of analysis gives a very short program to find the three candidate numbers. This Python program runs in 35ms.

      from enigma import irange, printf
      
      # b = 9*a, each is 5 digits, together they are pandigital
      # max(b) = 98765, so:
      # max(a) = 10973
      # min(a) = 10234
      # min(b) = 92106
      #
      # so: a is 10???, b is 9????
      
      for a in irange(10234, 10876):
        b = 9 * a
        if len(set(str(a) + str(b))) != 10: continue
        printf("{a} x 9 = {b}")
      
      • geoffRounce 29 September 2015 at 9:09 pm

        A MiniZinc solution gave the same three numbers :

        include "globals.mzn";
        
        var 0..9:A;   var 0..9:B;  var 0..9:C;
        var 0..9:D;   var 0..9:E;  var 0..9:F;
        var 0..9:G;   var 0..9: H;  var 0..9:I;
        var 0..9:J;
        
        constraint 
             A!= 0 /\ F!= 0 /\ alldifferent([A,B,C,D,E,F,G,H,I,J]);
        
        constraint
             (A*10000 + B *1000 + C*100 + D*10 + E) * 9 ==
             F*10000 + G*1000 + H*100 + I*10 + J;
        
        solve satisfy;
        
        output["5 Digit Number = ",show(A),show(B),show(C),show(D),show(E)];
        
        % 5 Digit Number = 10836
        % 5 Digit Number = 10647 << Answer
        % 5 Digit Number = 10638
        
      • arthurvause 6 October 2015 at 2:38 pm

        It it easy to show that both 5-digit numbers have to be multiples of 9, so the for loop can be

        for a in irange(10242,10876,9):

        • Jim Randell 6 October 2015 at 6:19 pm

          Good point. Every little helps. Only 24 of the remaining candidates for a have no repeated digits and don’t include the digit 9, so this gives a way to achieve a manual solution.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: