Enigmatic Code

Programming Enigma Puzzles

Enigma 511: Double, double …

From New Scientist #1663, 6th May 1989 [link]

I wrote an odd number on the board and asked the class how many numbers (including the original number itself) could be made by writing exactly the same digits but in different orders. (For example, if the number had been 5051, the answer would have been nine, namely 5051, 5015, 5105, 5150, 5501, 5510, 1055, 1505 and 1550).

Clever Dick got the right answer immediately, so to keep him busy I told him to repeat the exercise with exactly double my original number.

“That just doubles the number of ways, Miss,” he reported.

I told him to double again and repeat the exercise, and again he reported “That doubles the number of ways yet again, Miss.”

So I told him to double the number yet again and to repeat the exercise with the four-figure answer.

“It’s doubled the number of ways again, Miss,” he replied and, as always, he was quite right.

What number did I write on the board?

[enigma511]

One response to “Enigma 511: Double, double …

  1. Jim Randell 5 August 2019 at 8:16 am

    This Python program constructively examines the number of arrangements of possible numbers.

    It runs in 111ms.

    Run: [ @repl.it ]

    from enigma import irange, subsets, uniq, icount, nsplit, div, printf
    
    # count the number of ways to arrange the digits of a number
    def count(n):
      # arrangements with a leading zero are discarded
      return icount(uniq(s for s in subsets(nsplit(n), size=len, select='P') if s[0]))
    
    # check the example
    assert count(5051) == 9
    
    # the final number is had 4 digits and is 8x the first (odd) number
    for n in irange(125, 1249, step=2):
      # check 8n -> 8k
      k = div(count(n * 8), 8)
      if k is None: continue
      # check n -> k, 2n -> 2k, 4n -> 4k
      if not all(count(m * n) == m * k for m in (1, 2, 4)): continue
      # output solution
      fmt = lambda x: list(m * x for m in (1, 2, 4, 8))
      printf("{ns} -> {ks}", ns=fmt(n), ks=fmt(k))
    

    Solution: The starting number was 447.

    A 3-digit number with all digits non-zero and different has 3! = 6 rearrangements.

    If two of the digits are the same, this number is halved to give 3 arrangements.

    Similarly, a 4-digit number will all digits non-zero and different has 4! = 24 rearrangements.

    Again, if two of the digits are the same, this number is halved to give 12 arrangements.

    So starting with 447 and doubling we get:

    447 → 894 → 1788 → 3576

    The corresponding numbers of arrangements of the digits are:

    3 → 6 → 12 → 24

    If we continue to double we get 7512, which again has 24 arrangements. But doubling again to 14304 yet again doubles the number of arrangements, having 48.

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: