# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1372: Three tours

From New Scientist #2531, 24th December 2005

The Romans have set up a transport service linking the five centres of Emmaus, Jerusalem, Bethlehem, Hebron and Masada. Each of the roads EJ, EB, EH, JB, BH, JM and HM is served in one direction only and by just one of the four animals Ass, Colt, Donkey and Mule. For example, you could ride from E to J, but I won’t say by which animal.

For his birthday, Jesus has been given a voucher which he has just used to make three tours by animal, each tour starting at E and finishing at M. The animals he rode were, in order, as follows (unfortunately I have forgotten the last animal on each journey).

1. A, C, M, C, D, M, ?.
2. D, A, C, D, A, C, A, ?.
3. D, M, C, M, C, A, ?.

In which direction can you journey between Bethlehem and Hebron and on which animal?

[enigma1372]

### 2 responses to “Enigma 1372: Three tours”

1. Jim Randell 17 November 2013 at 9:09 am

I treated the animals as distinct, although I’ve been led to believe that “donkey” (which originally was pronounced to rhyme with “monkey”) was introduced to save the delicate from having to hear the word “ass”, and so they are the same animal.

This Python 3 program runs in 49ms.

```from enigma import printf

# ajacency graph
roads = { 'B': 'EHJ', 'E': 'BHJ', 'H': 'BEM', 'J': 'BEM', 'M': 'HJ' }

# is s->d on m an allowable route? return an updated route map, or None
def route(s, d, m, routes):
# if it's an existing route
if s + d in routes:
# and the mount matches
if m == routes[s + d]:
return routes
# can we create a new route
elif d + s not in routes:
routes = dict(routes)
routes[s + d] = m
return routes

# can we make a journey using the specified mounts?
# ms - mounts
# src, dst - start and finish of journey
# routes - map: src -> dst -> mount
def journey(ms, src, dst, routes):
# are we done?
if not ms:
# can we get from to the final destination?
if dst in roads[src] and (src + dst in routes or dst + src not in routes):
yield routes
else:
# consider possible paths from src
routes2 = route(src, d, ms[0], routes)
if routes2:
yield from journey(ms[1:], d, dst, routes2)

# solve a collection of journeys
def solve(js, src, dst, routes):
# are we done?
if not js:
yield routes
else:
for routes2 in journey(js[0], src, dst, routes):
yield from solve(js[1:], src, dst, routes2)

# find route maps which allow all three journeys
for routes in solve(['ACMCDM', 'DACDACA', 'DMCMCA'], 'E', 'M', dict()):
# and check there is a route from E to J
if 'EJ' in routes:
# what direction is the B to H route?
for k in ('BH', 'HB'):
if k in routes:
printf("{k[0]}->{k[1]} on {m} [{routes}]", m=routes[k])
```

Solution: You can journey from Bethlehem to Hebron by Ass.

If you don’t use the information that the Emmaus/Jerusalem journey starts in Emmaus and ends in Jerusalem you can find a second distinct solution.

This site uses Akismet to reduce spam. Learn how your comment data is processed.