Enigmatic Code

Programming Enigma Puzzles

Enigma 550: Do your level best

From New Scientist #1703, 10th February 1990 [link]

Bern, Cara and Loren are climbing in the Hillymayas and have decided to tackle Mount Veryrest which is 700 metres high. There are three different approaches and they each take a different one. Bern’s approach is shown in the diagram.

All slopes in the Hillymayas have the same steepness — 1 up or down for 1 across; all climbers go at the same pace — 100 metres up or down in each hour. Thus, Bern could reach the top in 13 hours.

Bern’s approach is described as: up 5, down 3, up 5.
Cara’s approach is: up 3, down 2, up 4, down 1, up 3.
Loren’s approach is: up 5, down 2, up 3, down 6, up 7.

The three decide that, to be fair, they will climb so that, at each point in time, all three are at the same height. This will involve some retracing of steps. Given that condition, they try to reach the top as soon as they can.

How may hours does it take them to reach the top?


One response to “Enigma 550: Do your level best

  1. Jim Randell 25 May 2020 at 8:44 am

    I liked this puzzle, although it is solved by a fairly straightforward recursive function.

    The following Python program runs in 69ms. (I got a new laptop for my birthday yesterday, so timings from today onwards will be recorded using that, rather than my 9 year old laptop, that I’ve had since I started the site).

    Run: [ @repl.it ]

    from itertools import product
    from enigma import irange, inf, cached, printf
    # route profiles
    B = "01234543234567"
    C = "01232123454567"
    L = "012345434565432101234567"
    # possible next steps from position <p>
    step = lambda p: ([1] if p == 0 else [p - 1, p + 1])
    # can we reach the target <t> (from positions <b>, <c>, <l>) in <k> steps?
    def _solve(k, b, c, l, t):
      # are we out of steps?
      if k == 0:
        # did we reach the target
        return (B[b] == t)
        # consider possible next steps
        return any(
          _solve(k - 1, b_, c_, l_, t)
            for (b_, c_, l_) in product(step(b), step(c), step(l))
              if B[b_] == C[c_] == L[l_]
    solve = lambda k: _solve(k, 0, 0, 0, '7')
    # find the lowest number of steps
    for k in irange(0, inf):
      if solve(k):
        printf("{k} hours")

    Solution: It will take them 59 hours to reach the summit.

    The profile of the solution looks like this:

    Note that L’s route returns to level 0, so after 40 hours B and C will be back at the beginning of their routes. And they were only 100m (vertically) away from the summit after 22 hours.

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: