Enigmatic Code

Programming Enigma Puzzles

Enigma 1027: Five-digit cubes

From New Scientist #2183, 24th April 1999 [link]

Harry, Tom and I were asked by Mary each to select a five-digit perfect cube that consisted of five different digits and to tell her (in secret) which one had been selected. After we had each done so she said:

“If I now told any one of you individually how many digits his cube has in common with each of the other two cubes he could deduce with certainty one, but not both of them”.

That in itself was enough information to enable me to deduce with certainty both the cubes that Harry and Tom had between them selected.

What were those two cubes?

In the magazine this puzzle was published as Enigma 1026 (despite that number having been used the previous week).

[enigma1027]

One response to “Enigma 1027: Five-digit cubes

  1. Jim Randell 18 January 2019 at 8:48 am

    This Python program runs in 80ms.

    Run: [ @repl.it ]

    from collections import namedtuple
    from itertools import product
    from enigma import irange, int2base, is_duplicate, filter_unique, unpack, ordered, join, printf
    
    # 5-digit cubes (as strings) consisting of different digits
    cubes = list()
    for i in irange(22, 46):
      s = int2base(i ** 3)
      if not is_duplicate(s):
        cubes.append(s)
    
    printf("[cubes = {cubes}]", cubes=join(cubes, sep=", "))
    
    # count the number of shared digits
    shared = lambda a, b: len(set(a).intersection(b))
    
    # for each cube partition cubes into unique and ambiguous shared digit counts
    P = namedtuple("P", "unique ambiguous")
    d = dict()
    for n in cubes:
      (un, am) = filter_unique(cubes, (lambda x: shared(n, x)))
      printf("[{n} -> unique = {un}]", un=join(un, sep=", "))
      d[n] = P(un, am)
    
    # now choose a cube for D
    rs = list()
    for (D, p) in d.items():
      # and choose a unique cube (for T) and an ambiguous cube (for H) to go with it
      for (T, H) in product(p.unique, p.ambiguous):
        # for T, one of D, H must be unique and one ambiguous
        if not((D in d[T].unique) ^ (H in d[T].unique)): continue
        # for H, one of D, T must be unique and one ambiguous
        if not((D in d[H].unique) ^ (T in d[H].unique)): continue
        printf("[D={D} -> T={T} H={H}]")
        rs.append((D, T, H))
    
    # from the results, knowing D's cube tells me T and H's
    (rs, _) = filter_unique(rs, unpack(lambda D, T, H: D), unpack(lambda D, T, H: ordered(T, H)))
    
    # output possible sets
    for (D, T, H) in rs:
      printf("D={D} -> T={T} H={H}")
    

    Solution: Harry and Tom have selected 19683 (= 27³) and 68921 (= 41³).

    There are only two sets of numbers which allow Mary to make her statement:

    A: (19683, 42875, 68921)
    B: (19683, 54872, 68921)

    Note that the middle cubes, 42875 and 54872, have the same digit content, so we’ll only look at case A:

    The person with 19683 would be told: “1 and 4”. From the “4” they can deduce that one of the other cubes is 68921, but the “1” is ambiguous between 42875 and 54872.

    The person with 42875 would be told: “1 and 2”. From the “1” they can deduce that one of the other cubes is 19683, but the “2” is ambiguous between 10648 and 68921.

    The person with 68921 would be told: “2 and 4”. From the “4” they can deduce that one of the other cubes is 19683, but the “2” is ambiguous between 42875 and 54872.

    Case B is similar with 42875 and 54872 swapped.

    But then when Mary makes her statement, the three participants know that these are are only two possible sets of numbers.

    So, the person with the middle number would know for sure what the other two numbers were, whereas the other two would not be sure which of the middle numbers had been chosen.

    But this means by making her statement Mary invalidates it, because after she’s made it Dick can deduce with certainty both the other two numbers with no further information, and everyone can deduce the numbers of shared digits without being told.

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: