Enigmatic Code

Programming Enigma Puzzles

Enigma 235: Double trouble

From New Scientist #1381, 27th October 1983 [link]

In the following football table and addition sum letters have been substituted for digits (from 0 to 9). The same letter stands for the same digit wherever it appears and different letters stand for different digits.

The three teams are eventually going to play each other once — or perhaps they have already done so.

Enigma 235

(Two points are given for a win and one point to each side in a drawn match).

Find the scores in the football matches and write the addition sum out with numbers substituted for letters.

Note: I now have a phone line installed at my new house, but I’m waiting for ADSL to be activated on it, so I only have sporadic access to the internet at the moment. The current estimate is that I should have an internet connection next week.

[enigma235]

One response to “Enigma 235: Double trouble

  1. Jim Randell 5 November 2014 at 1:43 pm

    This Python program uses the [[ Football() ]] helper class from the enigma.py library. It runs in 33ms.

    from enigma import irange, Football, printf
    
    digits = set(irange(0, 9))
    
    football = Football(points={ 'w': 2, 'd': 1 })
    
    # consider possible match outcomes
    for (AB, AC, BC) in football.games(repeat=3):
      # generate the table
      A = football.table([AB, AC], [0, 0])
      B = football.table([AB, BC], [1, 0])
      C = football.table([AC, BC], [1, 1])
      # values for n, y, z
      (n, y, z) = (C.l, B.d, C.points)
      # determine p from the sum: 2(10n + p) = 10p + z
      (p, r) = divmod(20 * n - z, 8)
      if r > 0: continue
      ds1 = digits.difference([n, y, z, p])
      if len(ds1) != 6: continue
    
      # total number of goals against = y + n + p
      # and this is the same as the total of the goals for column
      # = x + q + q, where x = Goals for A
      g = y + n + p
      for q in irange(0, g // 2):
        if q not in ds1: continue
        x = g - 2 * q
    
        # generate possible scorelines for A
        for (sAB, sAC) in football.scores([AB, AC], [0, 0], x, y):
          # and the remaining match for B
          for (sBC,) in football.scores([BC], [0], q, n, [sAB], [1]):
            # and check C
            if football.goals([sAC, sBC], [1, 1]) != (q, p): continue
    
            printf("AB={AB}:{sAB} AC={AC}:{sAC} BC={BC}:{sBC}")
            printf("A={A}")
            printf("B={B}")
            printf("C={C}")
            printf("n={n} y={y} z={z} p={p} q={q} x={x}")
    

    Solution: A vs. B was a 0-0 draw; A vs. C was a 2-1 win for A; B vs. C was a 3-2 win for B. The addition sum is 25 + 25 = 50.

Leave a reply to Jim Randell Cancel reply

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