Enigmatic Code

Programming Enigma Puzzles

Enigma 1663: Flintoff’s farewell

From New Scientist #2829, 10th September 2011 [link] [link]

Recently retired cricket all-rounder Andrew Flintoff was known as Freddie until a much-publicised incident with a pedalo gave rise to the new nickname Fredalo. In the sum shown, digits have been replaced by letters, different letters representing different digits. Since there are 11 different letters everything is in base 11. Use 0 to 9 as normal and X for the extra digit.

What is the eight-digit number (still in base 11) represented by FLINTOFF?

[enigma1663]

4 responses to “Enigma 1663: Flintoff’s farewell

  1. Jim Randell 4 December 2011 at 11:08 am

    This can be done in a much shorter program without the early rejection, and all the tedious mucking around with base 11 carries, but it’s 1000× slower.

    The following Python code has a runtime of 33ms.

    from itertools import permutations
    from enigma import printf
    
    # L + O = F, so neither L nor O (nor F) can be 0 (zero)
    d = set(range(1, 11))
    for L, O in permutations(d, 2):
      (c0, F) = divmod(L + O, 11)
      if F == 0: continue
      (c1, f) = divmod(L + L + c0, 11)
      if not(f == F): continue
    
      d1 = d.difference((L, O, F))
      if len(d) - len(d1) != 3: continue
      d1.add(0)
      for E, A in permutations(d1, 2):
        (c2, o) = divmod(E + A + c1, 11)
        if not(o == O): continue
    
        d2 = d1.difference((E, A))
        for W, D in permutations(d2, 2):
          (c3, T) = divmod(W + D + c2, 11)
          (c4, N) = divmod(E + E + c3, 11)
    
          d3 = d2.difference((W, D, T, N))
          if len(d2) - len(d3) != 4: continue
          for R in d3:
            (c5, I) = divmod(R + R + c4, 11)
            d4 = d3.difference((R, I))
            if len(d3) - len(d4) != 2: continue
            (c6, l) = divmod(A + F + c5, 11)
            if not(l == L): continue
            if not(c6 == 0): continue
    
            digits = '0123456789A'
            FLINTOFF = ''.join(digits[x] for x in (F, L, I, N, T, O, F, F))
            printf("FLINTOFF={FLINTOFF} [{n}] / L={L} O={O} F={F} E={E} A={A} W={W} D={D} T={T} N={N} R={R} I={I}", n=int(FLINTOFF, 11))
    

    Solution: FLINTOFF = 68042966 (base 11).

    • Jim Randell 4 December 2011 at 11:47 am

      Here’s the shorter program, with no early rejection – it takes 3m36s to run (26s in PyPy).

      from itertools import permutations
      from enigma import printf
      
      def unsplit(*i):
        return reduce(lambda a, b: 11*a + b, i, 0)
      
      for (A, D, E, F, I, L, N, O, R, T, W) in permutations(range(11), 11):
        if 0 in (L, O, F): continue
        FAREWELL = unsplit(F, A, R, E, W, E, L, L)
        FREDALO  = unsplit(F, R, E, D, A, L, O)
        FLINTOFF = unsplit(F, L, I, N, T, O, F, F)
        if FAREWELL + FREDALO != FLINTOFF: continue
      
        digits = '0123456789A'
        s = ''.join(digits[x] for x in (F, L, I, N, T, O, F, F))
        printf("FLINTOFF={s} [{FLINTOFF}] / L={L} O={O} F={F} E={E} A={A} W={W} D={D} T={T} N={N} R={R} I={I}")
      
  2. Jim Randell 8 January 2013 at 3:48 pm

    The following Python program uses the [[ SubstitutedSum() ]] solver from the enigma.py library. It runs in 52ms.

    from collections import Counter
    from enigma import SubstitutedSum, printf
    
    # count the different solutions
    r = Counter()
    p = SubstitutedSum(['FAREWELL', 'FREDALO'], 'FLINTOFF', base=11)
    for s in p.solve():
      printf("[{s}]", s=p.substitute(s, p.text))
      FLINTOFF = p.substitute(s, p.result)
      r[FLINTOFF] += 1
    
    # output the solutions
    for (k, v) in r.items():
      printf("FLINTOFF={k} [{v} solutions]")
    
  3. GeoffR 20 January 2022 at 9:56 am
    % A Solution in MiniZinc
    include "globals.mzn";
    
    % Digits for number base 11 
    var 1..10:F; var 0..10:A; var 0..10:R; var 0..10:E;
    var 0..10:W; var 0..10:L; var 0..10:D; var 0..10:O;
    var 0..10:I; var 0..10:N; var 0..10:T;
    
    % Carry digits fron R,H. side
    var 0..1:c1; var 0..1:c2; var 0..1:c3; 
    var 0..1:c4; var 0..1:c5; var 0..1:c6; 
    
    constraint all_different([F, A, R, E, W, L, D, O, I, N, T]);
    
    % Add columns from right hand side  
    constraint c1 == (L + O) div 11 /\ F == (L + O) mod 11;
    constraint c2 == (L + L + c1) div 11 /\ F == (L + L + c1) mod 11;
    constraint c3 == (E + A + c2) div 11 /\ O == (E + A + c2) mod 11;
    constraint c4 == (W + D + c3) div 11 /\ T == (W + D + c3) mod 11;
    constraint c5 == (E + E + c4) div 11 /\ N == (E + E + c4) mod 11;
    constraint c6 == (R + R + c5) div 11 /\ I == (R + R + c5) mod 11;
    constraint (A + F + c6) == L;
    
    solve satisfy;
    
    output[ " [F, A, R, E, W, L, D, O, I, N, T] = " ++ 
    show([F, A, R, E, W, L, D, O, I, N, T]) ];
    
    %  [F, A, R, E, W,  L, D, O, I, N, T] = 
    %  [6, 1, 5, 7, 10, 8, 3, 9, 0, 4, 2]
    % ----------
    %  [F, A, R, E, W, L,  D, O, I, N, T] = 
    %  [6, 1, 5, 7, 3, 8, 10, 9, 0, 4, 2]
    % ----------
    % ==========
    % so FLINTOFF = 68042966
    %
    % Sum is: 6157X788 + 6573189 = 68042966 (X = 10)
    % ....or: 61573788 + 657X189 = 68042966 (X = 10)
    
    
    

Leave a Comment

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