Enigmatic Code

Programming Enigma Puzzles

Enigma 310: Jogging on

From New Scientist #1458, 30th May 1985 [link]

“Nick and I have taken up jogging”, said Tom. “We ran round a field starting at the gate and we believe that, for all practical purposes, each of us jogged at our own constant speed.”

“After we had completed some laps and a few yards, I overtook Nick. Although we were tired, we kept on going, until we finally met at the gate. By this time I had done four laps more than Nick.”

“How many laps did you do?” I asked.

“That’s interesting — by coincidence, the number of his laps and the number of my laps (completed), when we first met and when we finished, were all composite”.

I suggested a possible answer to my question, but he said, “We weren’t that energetic!”

This reply enabled me to work out the correct answer.

What is it?

[enigma310]

Advertisements

One response to “Enigma 310: Jogging on

  1. Jim Randell 14 September 2015 at 9:27 am

    In order for Tom to lap Nick, such that they have completed an exact number of laps on the fourth lapping, the extra distance on the first lap must be an integer number of quarter laps. We are told that the first lapping occurs “a few yards” beyond the gate, so the number must be non-zero, and also that “we finally met at the gate” on the fourth lapping, so the number cannot be 2 (or they would meet at the gate on the second lapping). So the extra distance at the first lapping is either ¼ or ¾ of a full circuit.

    Tom’s reply indicates that the setter’s initial guess must have been the second lowest possible solution, so the answer we are looking for is the lowest possible number of laps.

    This Python program runs in 33ms (so it’s not really worth using a more sophisticated implementation of is_composite()).

    from itertools import count
    from enigma import factor, printf
    
    def is_composite(n):
      fs = factor(n)
      return (fs is not None and len(fs) > 1)
    
    # the final number of laps by nick is a composite number
    for n4 in count(1):
      if not is_composite(n4): continue
    
      # the final number of laps by tom is also a composite number
      t4 = n4 + 4
      if not is_composite(t4): continue
    
      # the number of laps when nick is fist lapped
      (n1, bit) = divmod(n4, 4)
      # nick is not lapped by the gate, and n1 is composite
      if bit % 2 == 0 or not is_composite(n1): continue
    
      # similarly for tom
      t1 = n1 + 1
      if not is_composite(t1): continue
    
      printf("n4={n4} t4={t4}, n1={n1} t1={t1} bit={bit}")
      break
    

    Solution: Tom did 39 laps of the field.

    Nick did 35 laps of the field.

    When Tom first lapped Nick, Tom had completed 9 laps and Nick had completed 8 laps. (In fact this occurs when Tom has done 9¾ laps and Nick has done 8¾ laps).

    The setter’s first guess must have been that Tom did 85 laps in total and Nick did 81 laps (so that Tom first passes Nick when Tom has done 21¼ laps and Nick has done 20¼ laps). This does seem more likely as the wording of the puzzle suggests that the first lapping occurs ¼ of the way around the field, rather than ¾ of the way around.

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: