Created
November 24, 2012 18:48
-
-
Save kazua/4140901 to your computer and use it in GitHub Desktop.
Project Euler Problem 19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2019 | |
| //K.A | |
| object problem19 { | |
| def getSunCnt : Int = { | |
| val dayCnt = List(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) | |
| def mlf(st : Int, ed : Int) = for(y <- st to ed; m <- 1 to 12) yield if (if (m != 2 || (m == 2 && ((y % 100 == 0 && y % 400 != 0) || (y % 4 != 0)))) false else true) 29 else dayCnt(m - 1) | |
| val ml1900 = mlf(1900,1900) | |
| val ml = mlf(1901,2000) | |
| val mf = ml.foldLeft(List((1 + ml1900.sum) % 7))((wf, d) => ((wf.head + d) % 7) :: wf) | |
| mf.count(_ == 0) | |
| } | |
| def main(args : Array[String]) { | |
| println(getSunCnt) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment