Which is the highest cube n^3 < 10
8 that can be incremented by a single digit from 1 to 9 to yield a perfect square?
For example, 8 is a perfect cube. When incremented by 1 it becomes 81, which is a perfect square.
When this problem was first in the queue, it was unclear whether the word 'incremented' was meant to convey (1) addition or (2) concatenation. The example makes it clear that what is meant is the latter.
I found results for both meanings, program output:
Interpretation (1) Addition
1 3 4 2
1 8 9 3
8 1 9 3
8 8 16 4
27 9 36 6
216 9 225 15
64000 9 64009 253
97336 8 97344 312
Interpretation (2) Concatenation
1 6 16 4
8 1 81 9
18821096 1 188210961 13719
-----------------------
solutions1 = []
solutions2 = []
cubes = [n**3 for n in range(1,10**4)]
print('Interpretation (1) Addition')
for c in cubes:
for d in range(1,10):
if issquare(c+d):
print(c,d,c+d,int((c+d)**.5))
solutions1.append([c,d,c+d,int((c+d)**.5)])
print()
print('Interpretation (2) Concatenation')
for c in cubes:
for d in range(1,10):
incr = int(str(c) + str(d))
if issquare(incr):
print(c,d,incr,int((incr)**.5))
solutions2.append([c,d,incr,int((incr)**.5)])
|
Posted by Larry
on 2024-01-21 13:21:12 |