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.
This happens 5 times in the book. The last time is when it's open to pages 409 and 410, when the total of two page numbers is 819
left right
page page total sod
49 50 99 18
139 140 279 18
229 230 459 18
319 320 639 18
409 410 819 18
ct =
5
There are no solutions where the even number is on the left, the normal structure of a book.
clearvars,clc
ct=0;
for leftPage=1:499
total=sod(leftPage)+sod(leftPage+1);
if mod(total,18)==0
disp([leftPage,leftPage+1,2*leftPage+1,total])
ct=ct+1;
end
end
ct
|
Posted by Charlie
on 2023-08-29 08:52:33 |