Enigmatic Code

Programming Enigma Puzzles

Enigma 772: Have you seen the trailer?

From New Scientist #1927, 28th May 1994 [link]

My friend was towing a small open trailer behind his car when the tow bar snapped. Luckily the trailer was light, so he turned it upside down and put it (like a hat) on the roof of his car. Consequently traffic behind could see his number plate twice, once on the car and once (upside-down) on the trailer. Amazingly, despite the inversion, both looked the same.

Being a British car, the number plate consisted of a letter, three digits and three letters (the first of the three letters not being I, O, S or Z for fear of confusing it with a digit).

The three digits were different and formed a three-figure number which was not a prime, not the sum of two primes, and not the difference of two primes.

What was the full number plate?

Note that by May 1994, the first letter (indicating the year of registration) had got as far as L, and the letter I was not used.

[enigma772]

One response to “Enigma 772: Have you seen the trailer?

  1. Jim Randell 15 April 2024 at 10:01 am

    The 3-digit number formed by the digits is not a prime, not the sum of two primes, and not the difference of two primes.

    It is conjectured that every even number is the sum of two primes, and also the difference of two primes, (and this is fairly easily verified for even numbers less than 1000), so we can look for odd numbers that are not prime where (n − 2) and (n + 2) are also not prime.

    This Python program considers all possible plates that satisfy the requirements, with the additional restriction on registration years up to May 1994.

    Run: [ @replit ]

    from enigma import (str_upper, str_digit, incl, is_prime, printf)
    
    # possible inverted characters
    inv = {
      'E': '3',
      'H': 'H',
      'I': 'I1',
      'L': '7',
      'M': 'W',
      'O': 'O0',
      'S': '5',
      'W': 'M',
      'X': 'X',
      'Z': '2',
      '0': '0O',
      '1': '1I',
      '2': 'Z',
      '3': 'E',
      '5': 'S',
      '7': 'L',
      '8': '8',
    }
    
    # character classes
    letter = incl(inv.keys(), str_upper)
    digit = incl(inv.keys(), str_digit)
    year = incl(letter, "ABCDEFGHJKL") # year letters in May 1994
    
    # find a character/inverse pair that fit in the specified classes
    def pair(cl1, cl2):
      for x in cl1:
        for y in inv.get(x, ''):
          if y in cl2:
            yield (x, y)
    
    # suppose the registration is: A123XYZ, then:
    
    # 3 is a digit that is a self inverse
    for (v3, v) in pair(digit, digit):
      if v != v3: continue
    
      # 2/X, 1/Y are a digit/letter that are inverse pairs
      for (v2, vX) in pair(digit, letter):
        if vX in "IOSZ": continue  # avoid confusion
        for (v1, vY) in pair(digit, letter):
          # form the number
          if len({v1, v2, v3}) != 3: continue
          n = int(v1 + v2 + v3)
          # must be odd
          if n % 2 == 0: continue
          # must not be a prime, the sum of 2 primes, or the difference of 2 primes
          if any(is_prime(x) for x in (n, n - 2, n + 2)): continue
    
          # A/Z are years that are an inverse pair
          for (vA, vZ) in pair(year, year):
    
            # output solution
            printf("{vA}{v1}{v2}{v3}{vX}{vY}{vZ} -> n={n}")
    

    Solution: The number plate was: H531ESH.


    This method of vehicle registration was replaced in 2001, by which time the following plates would also form a viable solution:

    M531ESW
    W531ESM
    X531ESX

    Year letters I, O, Q, U and Z were not used.

Leave a Comment

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