# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1303: Lucky numbers

From New Scientist #2461, 21st August 2004

Alex and his big sister Monica were using a new method to work out their lucky numbers. First they chose at random a number from 1 to 26 and assigned that value to the letter A. They then valued each of the remaining letters B to Z, with a number relating to its position in the alphabet. For example, if A had been given the value 10, then B would be 11, C would be 12, and so on through to Q=26, R=1 … Z=9.

With this exercise complete, they added up the totals for their respective names to find their lucky numbers. Alex was delighted, because (A+L+E+X) was bigger than (M+O+N+I+C+A). And they were both pleased to find that when the two lucky numbers were added together they made a perfect square.

What was the original value chosen for A?

[enigma1303]

### 2 responses to “Enigma 1303: Lucky numbers”

1. Jim Randell 8 August 2014 at 6:53 am

This Python program runs in 39ms.

```from enigma import irange, is_square, printf

# order the letters
letter = dict((x, i) for (i, x) in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ'))

def value(word, A):
return sum((letter[x] + A - 1) % 26 + 1 for x in word)

for A in irange(1, 26):
ALEX = value('ALEX', A)
MONICA = value('MONICA', A)
if not(ALEX > MONICA): continue
if not is_square(ALEX + MONICA): continue

printf("A={A} ALEX={ALEX} MONICA={MONICA}")
```

Solution: The value chosen for A is 19.

2. Paul 8 August 2014 at 12:34 pm

Here is a MMa solution

```alphabet =CharacterRange["a","z"];