Project Euler - Problem 19


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. !/usr/bin/python
  2.  
  3. # Project Euler - Problem 19
  4.  
  5. months = [["JAN",2], ["FEB", 5],["MAR", 5],["APR",1],["MAY",3],["JUNE",6],
  6. ["JULY",1],["AUG",4],["SEPT",7],["OCT",2],["NOV",5],["DEC",7]]
  7. cnt = 0
  8.  
  9. for year in range(1901, 2001):
  10. for month in months:
  11. if month[1] % 7 == 0:
  12. cnt += 1
  13. if month[0] != "FEB" and year+1 % 4 == 0: # Leap year
  14. month[1] += 2
  15. elif month[0] == "FEB" and year % 4 == 0:
  16. month[1] += 2
  17. else:
  18. month[1] += 1
  19.  
  20. print cnt

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.