Enigmatic Code

Programming Enigma Puzzles

Enigma 517: Walk in the dark

From New Scientist #1669, 17th June 1989 [link]

Out there, somewhere in the night, is Elk Elloy, gunning for me. My only hope is to stay in the dark.

Stretching ahead of me is the Boulevard, all 3686.3 yards of it. If I can make the other end of it then I’ll be safe. But the whole length of the Boulevard is covered with neon strip lights. One hundred and ninety-three of them, each 19.1 yards long, set out end-to-end. They flash on and off steadily through the night. There go the 1st, 3rd, 5th, 7th, …, 193rd. They’re on for just an instant. Now there is a 12-second pause and then on come the 2nd, 4th, 6th, …, 192nd, for just an instant. Then another 12-second pause and we begin all over again with the odd numbered strips.

Fortunately, each strip only lights the ground directly below it, so there is a chance I can walk along the Boulevard and avoid ever being under a strip when it comes on.

There are just two catches. First, I must walk at a constant speed which is a whole number of yards per minute, otherwise I will arouse the suspicion of Patrolman Nulty who covers the Boulevard. Secondly, I cannot walk at more than 170 yards per minute.

What speed should I walk at, in yards per minute?


One response to “Enigma 517: Walk in the dark

  1. Jim Randell 16 September 2019 at 8:12 am

    Let’s suppose the clock ticks modulo 24 (so it goes: 0, 1, 2, …, 22, 23, 0, 1, 2 …).

    Then there are 193 zones (we will number them from 0 to 192), we want to avoid being in the even numbered zones at t=0 and the odd numbered zones at t=12.

    So, if we were in the middle of an even zone at t=12 we would be safe, and if we could get to the middle of the next odd zone by t = 0 we would be safe in that zone.

    That requires travelling 19.1 yards every 12 seconds. Which is 95.5 yards/minute, which is not a permitted speed.

    But it is in the right range of available speeds, so we can look at travelling 95 yards/minute or 96 yards/minute and see if they work.

    If we can get from the middle of zone 96 at t=12 to the end of the final zone without being caught, then, by symmetry, we would be able to get to the middle of zone 96 without getting caught.

    In the following Python program I express distances in “centiyards” (i.e. 1/100 of a yard). It runs in 107ms.

    Run: [ @repl.it ]

    from fractions import Fraction as F
    from enigma import printf
    # total distance, half distance
    D = 368630
    H = F(D, 2)
    # check if travelling at speed <v0>, starting at distance <d0>, time <t0> allows passage
    def check(v0, d0, t0):
      # speed in centiyards per second
      (v, d, t) = (F(v0, 60), d0, t0)
      # where are we at the next multiple of 12?
      x = -t % 12
      if x > 0:
        t += x
        d += v * x
      while d < D:
        # are we caught?
        (b, z) = (t // 12, d // 1910)
        if (b % 2) == (z % 2):
          printf("v={v:.2f} yard/min, t={t0:.2f}, d={d0}: caught at t={t}, z={z}, d={d:.2f}", v=float(v0) * 0.01, t0=float(t0), d=float(d))
          return False
        # move on 12s
        t += 12
        d += v * 12
      # we made it
      printf("v={v:.2f} yard/min, t={t:.2f}, d={d0}: not caught", v=float(v0) * 0.01, t=float(t0))
      return True
    # check 95.5 yards/min and permissible close speeds
    for v in [9550, 9500, 9600]:
      check(v, H, 12)

    Solution: You should travel at 96 yards/minute.

    To pass exactly through the centre of zone 96 at t=12 the required start time is t=12 + 1/32 seconds (= 12.03125s).

    And 96 yards/minute is the only permissible whole number speed in the allowed range that permits an unobserved passage:

    % python3.7 -i enigma517b.py
    >>> list(v for v in irange(100, 17000, step=100) if check(v, H, 12))

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: