Project Euler

Project Euler Problem 19

steloflute 2012. 6. 3. 22:57

Problem 19

14 June 2002

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)?


Answer:
171

 

Human intuition?

 

Probabilistic calculation gave the answer.

 

P(A day is Sunday) = 1/7
100 (years) * 12 (months) / 7 (days in a week) = 171.42857..

 

I tried 171 and it worked



'Project Euler' 카테고리의 다른 글

Project Euler Problem 21  (0) 2012.06.03
Project Euler Problem 20  (0) 2012.06.03
Project Euler Problem 18  (0) 2012.06.03
Project Euler Problem 17  (0) 2012.06.03
Project Euler Problem 16  (0) 2012.06.03