Enigmatic Code

Programming Enigma Puzzles

Enigma 534: Under and over

From New Scientist #1686, 14th October 1989 [link]

The important C.A.R. Rally has just been held at Bun’s Hutch, where the track is as in the map.

Enigma 534

There were 12 cars in the rally, numbered 1 to 12. For the start at 10:00, the cars took up the 12 lettered positions on the map, one car to each position. At 10:01 the cars all reached their first bridge, going under or over; at 10:02 the cars all reached their second bridge.

I had taken a photo at 10:01 and also at 10:02. Each photo showed all the numbers of the cars and so each bridge showed a fraction with one number over another. On one photo the fractions worked out to be 1/2, 2/3, 2/3, 2 1/3, 4, 5 1/2, and on the other 2, 2, 2, 3, 5 1/2, 7, but I forget which photo was which.

Which cars started at each of the 12 letters?

[enigma534]

One response to “Enigma 534: Under and over

  1. Jim Randell 13 January 2020 at 9:18 am

    This Python 3 program runs in 1.58s.

    Run: [ @repl.it ]

    from fractions import Fraction as F
    from enigma import multiset, irange, uniq, subsets, update, join
    
    # the positions of the cars on each bridge in the photos
    p1 = [ "FA", "GB", "CL", "DI", "JE", "KH" ]
    p2 = [ "EL", "FA", "BK", "CH", "ID", "JG" ]
    
    # assemble the two sets of fractions
    f1 = multiset.from_seq([F(1, 2), F(2, 3), F(2, 3), F(7, 3), F(4, 1), F(11, 2)])
    f2 = multiset.from_seq([F(2, 1), F(2, 1), F(2, 1), F(3, 1), F(11, 2), F(7, 1)])
    
    def solve(p1, p2, f1, f2, ns, d):
      # are we done?
      if not(p1 and p2):
        yield d
      else:
        # look at the next pair of bridges
        (b1, b2) = (p1[0], p2[0])
        # find unallocated symbols
        u = list(uniq(x for x in b1 + b2 if x not in d))
        # allocate the symbols
        for s in subsets(ns, size=len(u), select="P"):
          d2 = update(d, u, s)
          # create the required fractions
          (q1, q2) = (F(d2[b1[0]], d2[b1[1]]), F(d2[b2[0]], d2[b2[1]]))
          if q1 in f1 and q2 in f2:
            for z in solve(p1[1:], p2[1:], f1.difference([q1]), f2.difference([q2]), ns.difference(s), d2): yield z
    
    # try the photos both way round
    for (x, y) in [(p1, p2), (p2, p1)]:
      for d in solve(x, y, f1, f2, set(irange(1, 12)), dict()):
        print(join((join(t, sep="=") for t in sorted(d.items())), sep="; "))
    

    Solution: The starting positions are: A=2; B=6; C=7; D=10; E=4; F=11; G=12; H=3; I=5; J=8; K=9; L=1.

    So when the 10:01 photo was taken the bridges were:

    B1: F/A = 11/2 = 5 + 1/2
    B2: G/B = 12/6 = 2
    B3: C/L = 7/1 = 7
    B4: D/I = 10/5 = 2
    B5: J/E = 8/4 = 2
    B6: K/H = 9/3 = 3

    Which corresponds to the second photo mentioned in the text.

    When the 10:02 photo was taken the bridges were:

    B1: E/L = 4/1 = 4
    B2: F/A = 11/2 = 5 + 1/2
    B3: B/K = 6/9 = 2/3
    B4: C/H = 7/3 = 2 + 1/3
    B5: I/D = 5/10 = 1/2
    B6: J/G = 8/12 = 2/3

    Which corresponds to the first photo mentioned in the text.

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: