-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.hs
34 lines (31 loc) · 754 Bytes
/
a.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
codeM, codeY :: [Int]
codeM = [6,2,2,5,0,3,5,1,4,6,2,4]
codeY = [0,5,3,1]
leapYear :: Int -> Bool
leapYear y = (((mod y 4) == 0) && ((mod y 100) /= 0)) || (mod y 400) == 0
leap :: Int -> Int -> Int
leap y m
| (leapYear y) && m<3 = 1
| otherwise = 0
yearStuff :: Int -> Int
yearStuff year = (codeY !! cent) + (div yr 4) + yr
where cent = mod (div year 100) 4
yr = mod year 100
doomsday :: Int -> Int -> Int -> Int
doomsday d m y = mod calculatedDay 7
where calculatedDay = d + (codeM !! (m-1)) + (yearStuff y) - (leap y m)
-- Try it!
-- doomsday 25 5 1810
-- 5
-- doomsday 1 1 2000
-- 6
-- doomsday 11 9 2001
-- 2
-- doomsday 7 10 2020
-- 3
-- doomsday 23 2 1927
-- 3
-- doomsday 6 9 1969
-- 6
-- doomsday 29 2 2020
-- 6