Project Euler Problem 19

問題

You are given the following information, but you may prefer to do some research for
yourself.

    * 1 Jan 1900 was a Monday.
    * Thirty days has September,
      April, June and November.
      All the rest have thirty-one,
      Saving February alone,
      Which has twenty-eight, rain or shine.
      And on leap years, twenty-nine.
    * A leap year occurs on any year evenly divisible by 4, but not on a century unless
it is divisible by 400.

How many Sundays fell on the first of the month during the twentieth century
(1 Jan 1901 to 31 Dec 2000)?

ソース

def get_date(y, m, d)
	if m == 1 || m == 2
		m += 12
		y -= 1
	end
	(y + y / 4 - y / 100 + y / 400 + (2.6 * m + 1.6).floor + d) % 7
end

count = 0
1901.upto(2000) do |y|
	1.upto(12) do |m|
		count += 1 if get_date(y, m, 1) == 0
	end
end
puts count

解答

171

感想

ツェラーの公式*1を使用
これを知っていれば余裕!