-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path019.hs
More file actions
19 lines (13 loc) · 661 Bytes
/
019.hs
File metadata and controls
19 lines (13 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- project euler: problem 19 (http://projecteuler.net/problem=19)
-- (c) 2013 charles feng (https://github.com/charlesfeng)
-- shared under the mit license (http://www.opensource.org/licenses/mit)
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s = foldl (\x y -> (x + y) `mod` 7) 1 m
d = foldl inc [s] [ (x, y) | x <- [1901 .. 2000], y <- [0 .. 11] ]
where inc d a = ((head d) + (m !! y) + (if y == 1 && (x `mod` 100 /= 0 || x `mod` 400 == 0) && x `mod` 4 == 0 then 1 else 0)) `mod` 7 : d
where x = fst a
y = snd a
main = do
print $ foldl (\x y -> if y == 0 then x + 1 else x) 0 (init d)
-- answer: 171
-- runtime: 0.2s