Hackerrank - Project Euler+ #019 - Counting Sundays

Hackerrank - Problem description

The problem description - Hackerrank.

Solution

The implementation is specific based on a programming language - the features in libraries for date manipulation.

I found out from given date, what is the next sunday. Then I added 7 days to the sunday's date, to have next sunday. I was cautioned for cases where the sunday is 25th day in a month (e.g. march). Next would be 32nd, which is invalid date. This date needs to be "translated" to next possible date in next month (would be 1st of April in our case). I repeat the process until I reach upper date constraint.

I created solution in:

All solutions are also available on my GitHub profile.

Ruby

Leave a Reply