Enigmatic Code

Programming Enigma Puzzles

Enigma 1449: All in order

From New Scientist #2610, 30th June 2007

I wrote six non-zero consecutive digits on separate cards and gave two cards each to ‘Arry, Barry and Carrie.  Each of them used their two digits to form a two-figure number, and then they multiplied together the three two-figure numbers.

When I asked them what the answer was they simply spelled it out by placing the six cards in a particular order.

With a little threesome logic – and far fewer multiplications than you might expect – it is possible to work out what their three two-figure numbers were.

What, in increasing order, were they?

[enigma1449]

2 responses to “Enigma 1449: All in order

  1. Jim Randell 19 March 2013 at 9:56 am

    This Python program runs in 42ms.

    I’ve included a generic function called [[ partitions() ]] which generates partitions of a sequence into n-tuples. It’s used here to assign the cards in pairs amongst the three recipients. It could have similarly been used in Enigma 70 to generate the possible pairings of brothers. As it has general utility I shall incorporate it into the enigma.py library of useful routines.

    from itertools import combinations, product, permutations
    from enigma import irange, printf
    
    # partition the sequence s into n-tuples
    def partitions(s, n):
      if len(s) == 0:
        yield ()
      else:
        for x in combinations(s[1:], n - 1):
          p = (s[0],) + x
          for ps in partitions(tuple(e for e in s[1:] if e not in x), n):
            yield (p,) + ps
    
    # possible starting numbers
    for n in irange(1, 4):
      # assign two cards to each of A, B, C
      for (A, B, C) in partitions(tuple(irange(n, n + 5)), 2):
        # A, B and C form two digit numbers from their cards
        for (a, b, c) in product(permutations(A), permutations(B), permutations(C)):
          (a, b, c) = (10 * a[0] + a[1], 10 * b[0] + b[1], 10 * c[0] + c[1])
          # and the product of these
          p = str(a * b * c)
          # needs to be a 6-digit number
          if len(p) != 6: continue
          # made of the digits on the cards
          if len(set(p)) != 6: continue
          if int(min(p)) != n: continue
          if int(max(p)) != n + 5: continue
    
          printf("p={p} [a={a} b={b} c={c}]")
    

    Solution: The three numbers are 56, 87 and 94.

    • Jim Randell 19 March 2013 at 10:03 am

      The text of the puzzle implies that such an exhaustive search is not the preferred solution, so here’s an analytical approach.

      There are four possible sequences of 6 consecutive digits: 123456, 234567, 345678 and 456789.

      Consider 123456. Any product made from a rearrangement of these digits will have a digital root of 3, and so has exactly one factor of 3. Hence exactly one of the 2-digit numbers is divisible by 3, and it has exactly one factor of three.

      If we consider the 2-digit numbers x < y < z, then z ≤ 65, y ≤ 54, x ≤ 43, and their product p ≥ 123456, hence x ≥ 123456 / (65 x 54), so x ≥ 36.

      So considering possible values for 36 ≤ x ≤ 43, and corresponding y, z and (where necessary) p, factors of 3 are marked with *:

      x = 36 (**), no solution, as 9 divides x.
      x = 41, y = 52, z = 63 (**), no solution, as 9 divides z.
      x = 41, y = 53, z = 62, no solution, no multiples of 3.
      x = 42 (*), y = 51 (*), z = 63 (**), no solution, all are multiples of 3, 9 divides z.
      x = 42 (*), y = 53, z = 61, p = 135786, not a solution.
      x = 43, y = 51 (*), z = 62, p = 135966, not a solution.
      x = 43, y = 52, z = 61, no solution, no multiples of 3.

      So we can eliminate the first case having only performed 2 calculations for p.

      Now consider 234567. The digital root is 9, so any p is divisible by 9, so there are exactly two factors of 3 in x, y and z.

      Also z ≤ 76, y ≤ 65, 52 ≤ x ≤ 54.

      So:

      x = 52, y = 63 (**), z = 74, p = 242424, not a solution.
      x = 52, y = 64, z = 73, no solutions, no multiples of 3.
      x = 53, y = 62, z = 74, no solutions, no multiples of 3.
      x = 53, y = 64, z = 72 (**), p = 244224, not a solution.
      x = 54 (***), no solutions, x has too many factors of 3.

      So the second case is also eliminated with only 2 calculations for p.

      Considering 345678. The digital root is 6, so there is only one factor of 3 among x, y and z.

      Also z ≤ 87, y ≤ 76, 53 ≤ x ≤ 65.

      So:

      x = 53, y = 64, z = 78 (*), p = 264576, not a solution.
      x = 53, y = 68, z = 74, not enough 3’s.
      x = 53, y = 64, z = 87 (*), p = 295104, not a solution.
      x = 53, y = 67, z = 84 (*), p = 298284, not a solution.
      x = 53, y = 74, z = 86, not enough 3’s.
      x = 53, y = 76, z = 84 (*), p = 338352, not a solution.
      x = 54 (***), too many 3’s.
      x = 56, y = 73, z = 84 (*), p = 343392, not a solution.
      x = 56, y = 74, z = 83, not enough 3’s.
      x = 57 (*), y = 63 (**), z = 84 (*), too many 3’s.
      x = 57 (*), y = 64, z = 83, p = 302784, not a solution.
      x = 58, y = 63 (**), z = 74, too many 3’s.
      x = 58, y = 64, z = 73, not enough 3’s.
      x = 63 (**), too many 3’s.
      x = 64, y = 73, z = 85, not enough 3’s, p would end in 0.
      x = 64, y = 75 (*), z = 83, p would end in 0.
      x = 65, y = 73, z = 84 (*), p would end in 0.
      x = 65, y = 74, z = 83, not enough 3’s, p would end in 0.

      The third case is eliminated with 6 calculations for p.

      Considering 456789. The digital root is 3, so there is a single factor of 3 among x, y, z.

      Also z ≤ 98, y ≤ 87, 54 ≤ x ≤ 76.

      So:

      x = 54 (***), too many 3’s.
      x = 56, y = 74, z = 89, not enough 3’s.
      x = 56, y = 79, z = 84 (*), p = 371616, not a solution.
      x = 56, y = 74, z = 98, not enough 3’s.
      x = 56, y = 78 (*), z = 94, p = 410592, not a solution.
      x = 56, y = 84 (*), z = 97, p = 456288, not a solution.
      x = 56, y = 87 (*), z = 94, p = 457968, this is the solution!
      x = 57 (*), y = 64, z = 89, p = 324672, not a solution.
      x = 57 (*), y = 69 (*), z = 84 (*), too many 3’s.
      x = 57 (*), y = 64, z = 98, p = 357504, not a solution.
      x = 57 (*), y = 68, z = 94, p = 364344, not a solution.
      x = 57 (*), y = 84 (*), z = 96 (*), too many 3’s.
      x = 57 (*), y = 86, z = 94, p = 460788, not a solution.
      x = 58, y = 64, z = 79, not enough 3’s.
      x = 58, y = 69 (*), z = 74, p = 296148, not a solution.
      x = 58, y = 64, z = 97, not enough 3’s.
      x = 58, y = 67, z = 94, not enough 3’s.
      x = 58, y = 74, z = 96 (*), p = 412032, not a solution.
      x = 58, y = 76, z = 94, not enough 3’s.
      x = 59, y = 64, z = 78 (*), p = 294528, not a solution.
      x = 59, y = 68, z = 74, not enough 3’s.
      x = 59, y = 64, z = 87 (*), p = 328512, not a solution.
      x = 59, y = 67, z = 84 (*), p = 332052, not a solution.
      x = 59, y = 74, z = 86, not enough 3’s.
      x = 59, y = 76, z = 84 (*), p = 376656, not a solution.
      x > 59, p would end in 0.

      In this case the unique solution is found with 14 calculations for p.

      So overall we have 24 candidates to check, one of which is the unique solution. The brute force program above checks all 480 possibilities (although it does so a lot faster than going through the 24 candidates by hand).

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: