in reply to Day of week calculation

Can someone explain to me how would one come up with the idea behind the code from line 12 to 18? I mean I kind of understand it but I would have never though of it :-).

Its a very basic, its just counting , like for hide and seek, like turning the pages of a book, board games, summing up groceries, or subtracting from cash on hand ($20)...