# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1378: Exaudi Deus

From New Scientist #2538, 11th February 2006

In our church we use a hymnbook with fewer than a thousand hymns. On Sunday we sing an opening hymn, a psalm, and three more hymns, the numbers being displayed in that order on the board.

Recently, as I sat at the organ I noticed that the five numbers were all different perfect squares in increasing order, and that each digit which did occur, occurred exactly three times.

What was the number of the psalm?

[enigma1378]

### One response to “Enigma 1378: Exaudi Deus”

1. Jim Randell 29 October 2013 at 8:55 am

With such a relatively small number of candidate squares to consider it’s easy just consider all possible combinations, which gives a compact Python program that runs in 339ms.

```from itertools import combinations
from collections import Counter
from enigma import irange, printf

# squares less than 1000 (as strings)
squares = list(str(i * i) for i in irange(1, 31))

# choose 5 squares
for s in combinations(squares, 5):
t = ''.join(s)
# the number of digits must be a multiple of 3
if len(t) % 3: continue
# count the digits
c = Counter(t)
# each one must appear 3 times
if any(v != 3 for v in c.values()): continue

printf("psalm = {p} [{s}]", p=s[1], s=', '.join(s))
```

Solution: The psalm was number 64.