# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1663: Flintoff’s farewell

From New Scientist #2829, 10th September 2011 [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]

### 3 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
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]")
```

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