<begin>
A student has a book containing 411 pages.
She read a certain number of pages on the first day and created a rule to work out how many pages she had to read on each succeeding day.
She decided that the number of pages to be read on the next day should be equal to the square of the sum of the digits of the page she ended at.
She found that on the sixth day, the number of pages she had set herself to read took her exactly to the final page of the book.
How many pages did she read on the 1st day?
<end>
The above puzzle comes from
a Cambridge University publication.
My question: list all the possibles scenarios , completing the book not necessarily in 6-day period, but still adherring to her rules.
Reading to page 61 on day 1 does it but here are all the outcomes that get to 411
13 29 150 186 411 0 day 5
16 65 186 411 0 0 day 4
29 150 186 411 0 0 day 4
61 110 114 150 186 411 day 6
65 186 411 0 0 0 day 3
110 114 150 186 411 0 day 5
114 150 186 411 0 0 day 4
150 186 411 0 0 0 day 3
186 411 0 0 0 0 day 2
190 290 411 0 0 0 day 3
241 290 411 0 0 0 day 3
290 411 0 0 0 0 day 2
program pages
implicit none
integer i,j,k,l,sq,bookmark(8)
do 2 i=1,410
do l=1,8
bookmark(l)=0
enddo
j=1
bookmark(1)=i
1 k=bookmark(j)
j=j+1
bookmark(j)=bookmark(j-1)+sq(k)
if(bookmark(j).eq.411)then
print 10,(bookmark(l),l=1,6),' day ',j
10 format(6(i3,2x),a8,i1)
go to 2
elseif (bookmark(j).lt.411)then
go to 1
endif
2 continue
end
function sq(n)
implicit none
integer sq,n,i1,i2,i3
i1=n/100
n=n-i1*100
i2=n/10
n=n-i2*10
i3=n
sq=(i1+i2+i3)**2
return
end
Edited on January 25, 2019, 4:49 am