Enigmatic Code

Programming Enigma Puzzles

Enigma 1207: Nice ones

From New Scientist #2363, 5th October 2002 [link]

We had a gathering of our very respectable and mathematically inclined family recently to celebrate the forthcoming centenary of its oldest surviving member.

Out of interest I pointed out to them that, given any odd number which does not end in 5, some multiple of it must consist simply of a string one ones. For example, if you look at 71 then the number 1111111… consisting of thirty-five ones is a multiple of it!

This set the family chattering and Alan wrote down the shortest string one ones which was a multiple of his age.

Alan’s father, Bob, then rubbed out a majority of the ones to leave the shortest string of ones which was a multiple of his age. Bob’s grandfather, Colin, then rubbed out a majority of the remaining ones to leave the shortest string of ones which was a multiple of his age.

How old is Bob?

[enigma1207]

Advertisements

One response to “Enigma 1207: Nice ones

  1. Jim Randell 27 August 2015 at 8:43 am

    See Enigma 1212 for more fun with repdigits.

    To get to a unique solution I required at least 16 years between generations. (i.e. Bob must be at least 16 years older than Alan, and Colin must be at least 32 years older than Bob).

    This Python program runs in 33ms.

    from enigma import irange, printf
    
    # find the first repdigit of <d> that is a multiple of <m>
    # return the length of the repdigit
    def repdigit(d, m, base=10):
      r = d % m
      n = 1
      while r > 0:
        r = (r * base + d) % m
        n += 1
      return n
    
    # check the examples
    assert repdigit(1, 71) == 35
    
    # record repunit lengths for ages less than 100
    length = dict()
    for i in irange(1, 99):
      if not(i % 2 == 0 or i % 5 == 0):
        length[i] = repdigit(1, i)
    
    # minimum distance between generations
    gen = 16
    
    # consider Bob's age, B, and repunit length, b
    for (B, b) in length.items():
    
      # Alan's age, A, is less than B
      # and his repunit length, a, is more than twice b
      As = list((A, a) for (A, a) in length.items() if A + gen < B and a > b * 2)
      if not As: continue
    
      # Colin's age, C, in more than B
      # and his repunit length, c, is less than half b
      Cs = list((C, c) for (C, c) in length.items() if B + 2 * gen < C and c * 2 < b)
      if not Cs: continue
    
      printf("B={B} b={b}, As={As}, Cs={Cs}")
    

    Solution: Bob is 53.

    Bob’s repunit had 13 digits.

    Alan is aged either 27 (and his repunit has 27 digits), or 29 (and his repunit has 28 digits).

    Colin is aged 91 (and his repunit has 6 digits).

    If we reduce the generation gap we can find an additional solutions. With a gap of 13 we get:

    Alan is 47 (repunit has 46 digits) or 49 (repunit has 42 digits). Bob is 63 (repunit has 18 digits). Colin is 91 (repunit has 6 digits).

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: