Enigmatic Code

Programming Enigma Puzzles

Enigma 1757: Power point

From New Scientist #2925, 13th July 2013 [link]

I have written a list of five different three-figure numbers, each of which is a power of a single digit. The first number is odd, and thereafter each number has the same hundreds digit or the same tens digit or the same units digit as its predecessor.

What, in order, are the five numbers?

This puzzle was republished as Enigma 1770.

[enigma1757]

5 responses to “Enigma 1757: Power point”

1. Jim Randell 10 July 2013 at 6:20 pm

This is straightforward to solve. This Python program runs in 31ms.

from itertools import count
from enigma import irange, printf

# collect powers of single digits that are 3-digit numbers
powers = set()
for d in irange(2, 9):
for n in count(2):
p = d ** n
if p < 100: continue
if p > 999: break
printf("[{d}^{n} = {p}]")

def solve(ps):
# are we done?
if len(ps) == 5:
print(', '.join(ps))
else:
# extend the sequence with a new power that shares digits with the last
for p in powers:
if p not in ps and any(x == y for (x, y) in zip(p, ps[-1])):
solve(ps + [p])

# and p1 is odd
for p1 in powers:
if int(p1) % 2 > 0:
solve([p1])

Solution: The five numbers are 343, 243, 256, 216 and 512.

2. Brian Gladman 10 July 2013 at 7:36 pm

Pretty similar in structure to Jim’s version

# find all three digit powers of single digit numbers
vals = set(x ** n for x in range(2, 10) for n in range(2, 11)
if 100 <= x ** n < 1000)

# add a number to 'used' from 'unused' whilst ensuring that
# consecutive numbers share a hundreds, tens or units digit
def solve(used, unused):
# if we have a list of five, yield it as a solution
if len(used) == 5:
yield(tuple(used))
else:
# otherwise try to extend the list with each unused number
for n in unused:
# if it shares a hundreds, tens and units digit with last in list
if any(str(used[-1])[i] == str(n)[i] for i in range(3)):
# add this number to the list and try to add more
yield from solve(used + [n], unused - set((n,)))

for i in vals:
if i % 2:
# and look for solutions
for s in solve([i], vals - set((i,))):
print(s)

3. Naim Uygun 10 July 2013 at 7:56 pm

Without writing a computer program, here is my list:
343, 243, 256 216 512

4. CnN 5 August 2013 at 12:15 pm

The only discrepency I have with this solution is that the enigma specifies that proceeding numbers can have the same hundreth _or_ the same tens _or_ the same units.
E.g. 343 couldn’t be followed by 243 (since the tens match _and_ the units match)
By sticking to this stringently the puzzle is unsolvable though…

• Jim Randell 5 August 2013 at 12:43 pm

I agree that the puzzle could have been clearer on whether the “or” was “exclusive” or “inclusive”. But having studied logic and programming I was perfectly happy to use the standard inclusive meaning. And, as you point out, there are no solutions if you assume the exclusive meaning.