Let y(n) represent sum of digits of n
3.
For 10<n<999 list all the triplets (n,n+1,n+2) such that y(n),y(n+1),y(n+2)
are three successive integers
a.in any order
b.corresponding to n,n+1,n+2.
Part b
When the y values must be in order, there are 38 of them (121 for 'a')
(code is below)
(Part a solved by un-commenting one line of code and comment out one other line.)
14 15 16
23 24 25
41 42 43
71 72 73
77 78 79
86 87 88
161 162 163
224 225 226
242 243 244
254 255 256
272 273 274
296 297 298
302 303 304
305 306 307
314 315 316
350 351 352
425 426 427
431 432 433
437 438 439
455 456 457
473 474 475
497 498 499
596 597 598
602 603 604
611 612 613
635 636 637
665 666 667
677 678 679
713 714 715
764 765 766
836 837 838
851 852 853
872 873 874
881 882 883
896 897 898
947 948 949
950 951 952
962 963 964
38
def sod(n):
""" Input an integer. Returns the Sum of the Digits """
aList = list(str(n))
ans = 0
for c in aList:
ans = ans + int(c)
return ans
def isTriplet(a,b,c,inOrder = False):
if inOrder:
l= ([a,b,c])
else:
l= sorted([a,b,c])
if l[1]-l[0] == 1 and l[2]-l[1] == 1:
return True
return False
sumOfCubes = []
biggestN = 1000
for n in range(biggestN):
sumOfCubes.append(sod(n**3))
count = 0
for i in range(12,biggestN):
if isTriplet(sumOfCubes[i-2],sumOfCubes[i-1],sumOfCubes[i],True):
# if isTriplet(sumOfCubes[i-2],sumOfCubes[i-1],sumOfCubes[i]):
count += 1
print(i-2,i-1,i )
print(count)
Edited on October 4, 2020, 12:10 pm
|
Posted by Larry
on 2020-10-04 12:07:26 |