# Enigmatic Code

Programming Enigma Puzzles

## Enigma 117: Sizzling sixes

From New Scientist #1261, 9th July 1981 [link]

You may remember (Enigma No. 105) the rapture of the cricket commentators over the batting of Henry Draycott. Here’s another snatch from their conversation that same afternoon:

“Oh, what a lovely six, another beautiful clean hit! How about that one, Jack?”

“Even better than the previous ones, and they were superb!”

“With the same magic qualities, Bob?”

“Oh, yes – just like his other sixes. The difference between the square of his score and the reverse of that square is the same for his scores both before and after the hit for six.”

“Remarkable! And if Henry reaches his double century, will it include the maximum possible number of such sixes?”

“Not so fast, Frank! I’ll come to that in a moment. First let me point out that this last six was even better than the earlier ones! Its ‘difference’ was the product of four consecutive odd integers, each one a prime or a square. And now for your last question…”

Well, what’s the answer? And what was Henry’s score at the time of this conversation?

[enigma117]

### 2 responses to “Enigma 117: Sizzling sixes”

1. Jim Randell 16 August 2013 at 8:23 am

This Python code isn’t hugely efficient, but it runs in only 40ms, so I think that’s OK.

```from itertools import combinations
from enigma import irange, multiply, is_prime, is_square, printf

# "difference" measure
def diff(n):
n2 = n ** 2
return abs(n2 - int(str(n2)[::-1]))

# factor n into 4 consecutive odd numbers
# check if they are all squares or primes
def check(n):
fs = [1, 3, 5, 7]
while True:
p = multiply(fs)
if p == n: break
if p > n: return None
fs.append(fs.pop(0) + 8)
if all(is_prime(x) or is_square(x) for x in fs): return fs
return None

# find scores less than 200 where diff(s) = diff(s + 6)
ss = list()
score = list()
for s in irange(0, 194):
d = diff(s)
if d != diff(s + 6): continue
ss.append(s)
printf("[before = {s}, after = {s6}, diff = {d}]", s6=s + 6)

fs = check(d)
if fs is not None:
score.append(s + 6)
printf("[score = {s6}, factors = {fs}]", s6=s + 6)

# there should be only one score
assert len(score) == 1
score = score
printf("henry's score = {score}")

# find maximal sequences of scores
n = len(ss)
while n > 0:
ms = list()
for s in combinations(ss, n):
# the scores must be at least 6 apart in order to be possible
if any(s[i + 1] - s[i] < 6 for i in irange(0, len(s) - 2)): continue
printf("[maximal sequence = {s}, len = {n}]")
ms.append(s)
if len(ms) > 0: break
n -= 1

printf("henry {x} achieve a maximal sequence", x=('can' if any(score in m for m in ms) else 'cannot'))
```

Solution: Henry cannot achieve a maximal sequence. He had just reached a score of 188 at the time of the conversation.

2. Hugh Casement 20 July 2015 at 1:13 pm

188² = 35344 which is 9009 less than 44353.  Previous score
182² = 33124 which is again 9009 less than its reversal 42133.
9009 = 7×9×11×13.

To achieve a maximum sequence he would need to have reached a score of 179 and then score two sixes in a row:
179² = 32041 which is 18018 more than 14023.
185² = 34225 which is 18018 less than 52243.
191² = 36481 which is 18018 more than 18463.
I think I’m right in saying that the only previous pairs were 132 & 138, 157 and 163,
and there can be no more before he reaches 200.
Please correct me if I’m wrong.

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