Enigmatic Code

Programming Enigma Puzzles

Enigma 256: Ups and downs

From New Scientist #1403, 29th March 1984 [link]

“You’re looking fit!” I remarked to my nephew Henry.

“Thanks,” he replied. “I keep fit by running down Bill’s field then walking up.”

“Do you know your average speed?” I inquired.

“I’ll let you work it out — it’s a one digit number — while my speeds, up and down, are whole numbers. As you know, I don’t like fractions, and all these speeds are in miles per hour.”

“I don’t think you’ve given me enough information,” I complained.

“I think I will have, if I tell you the difference between my speeds, up and down the field.” Then he did so.

“Still not enough information.”

“Sorry! — I should have told you that I run down the field at less than 17 miles an hour. Now you have enough information.”

What was his average speed?



7 responses to “Enigma 256: Ups and downs

  1. Jim Randell 6 February 2015 at 8:18 am

    This Python program runs in 34ms.

    from collections import defaultdict
    from enigma import irange, printf
    # record the solutions by difference
    s = defaultdict(list)
    # consider the average speed, a single (decimal) digit
    for a in irange(1, 9):
      # the walking speed is less
      for u in irange(1, a - 1):
        x = 2 * u - a
        if x < 1: continue
        (d, r) = divmod(a * u, x)
        if r > 0: continue
        k = d - u
        printf("[a={a} u={u} d={d} diff={k}]")
        s[k].append((a, d, u))
    # look for ambiguous differences
    for (k, vs) in s.items():
      if len(vs) < 2: continue
      # but the actual down speed is less than 17 mph
      for (a, d, u) in vs:
        if d < 17:
          printf("avg={a}mph [down={d}, up={u}, diff={k}]")

    Solution: Henry’s average speed is 5 mph.

  2. Naim Uygun 6 February 2015 at 9:22 am
    for v1 in range(16,2,-1):
        for v2 in range(1,v1):
            if v1 <= v2 : continue
            if  v != int(v) :continue
            if v>9 : continue
            print("\n average speed =",int(v))
            print(" down speed=",int(v1)," up speed=",int(v2))
    • Jim Randell 6 February 2015 at 9:45 am

      Hi Naim, the program you have posted gives 5 possible solutions. How do you decide which one is the correct answer?

      • Naim Uygun 6 February 2015 at 10:25 am

        Hi Jim,
        In my opinion, the nearest speed to 17 (run down) should be selected.
        Is there enough information for a single solution?

        • Jim Randell 6 February 2015 at 12:16 pm

          Yes – there is enough information to get a single solution. A careful reading of the puzzle text gives enough information for a unique answer to be found.

          If you need a more detailed explanation I’m happy to explain further.

  3. Hugh Casement 6 February 2015 at 6:07 pm

    I reasoned as follows:
    Suppose he runs at speed r and walks at w (m.p.h.). His average over the double distance is 2rw/(r + w). For all values to be integral and the average less than 10, we could have
    6 and 2: difference 4, average 3
    6 and 3: difference 3, average 4
    12 and 4: difference 8, average 6
    12 and 6: difference 6, average 8
    15 and 3: difference 12, average 5
    18 and 6: difference 12, average 9
    20 and 5: difference 15, average 8
    28 and 4: difference 24, average 7
    There was ambiguity, so the difference must be 12; then 18 was eliminated, leaving 15 and 3.

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

%d bloggers like this: