Permalink
Browse files

Problem 19 updated

  • Loading branch information...
1 parent 121857c commit 536c1363401062898c0d68c5c9ebe85e5b441ee7 @pavelfatin committed Jun 27, 2013
Showing with 5 additions and 5 deletions.
  1. +5 −5 p19.scala
View
@@ -1,13 +1,13 @@
-val lengths = Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 31, 31)
+val lengths = Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
val ls = for(y <- 1900 to 2000; m <- 1 to 12) yield
if(m == 2)
- if (if (y % 100 == 0) y % 400 == 0 else y % 4 == 0) 29 else 28
- else
+ if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) 29 else 28
+ else
lengths(m - 1)
-val fs = ls.foldLeft(List(1))((ws, l) => ((ws.head + l) % 7) :: ws)
+val fs = ls.scanLeft(1)((ws, l) => (ws + l) % 7)
-val r = fs.count(_ == 0)
+val r = fs.drop(12).take(1200).count(_ == 0)
assert(r == 171) // 2 ms

0 comments on commit 536c136

Please sign in to comment.