Bob is reading a 500 page book, with odd numbered pages on the left, and even numbered pages on the right. Multiple times in the book, the sum of the digits of the two opened pages are 18. Find the sum of the page numbers of the last time this occurs.
Begin with the assumption that the first digit is 4, since we are seeking the last time it occurs. If this ends up not having a solution, then we will assume the first digit is 3.
Knowing the first digit on both pages is 4 means the sod of the last 2 digits on both pages must be 10. So 4 digits must sum to 10. This rules out most page pairs (page pairs which have the same second digit) because the last digits will be one even and one odd. So the second digits must also have opposite parity. So the last digit of the first page must be 9 and the last digit of the second page must be 0. But now the sod of the first and last digits is already up to 17 (4+4+9+0). So the second digits must be a 0 and a 1.
Hence: 409 and 410, whose sum is 419.
also confirmed with a program showing the 5 pairs:
49 50
139 140
229 230
319 320
409 410
----------------
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
for i in range(1,500,2):
if sod(i) + sod(i+1) == 18:
print(i,i+1)
|
Posted by Larry
on 2023-08-29 11:02:31 |