Permalink
Browse files

Started 19

  • Loading branch information...
Eric Wilson
Eric Wilson committed Jan 29, 2011
1 parent f8ac566 commit 610c82e9bcc5af92ed21270ecd69e2e3daabba97
Showing with 31 additions and 0 deletions.
  1. +30 −0 019.hs
  2. +1 −0 README
View
30 019.hs
@@ -0,0 +1,30 @@
+type Year = Int
+type Month = Int
+type Day = Int
+
+data Date = Date { year :: Year
+ , month :: Month
+ , day :: Day
+ } deriving (Show)
+
+isLeapYear :: Year -> Bool
+isLeapYear year
+ | mod year 400 == 0 = True
+ | mod year 100 == 0 = False
+ | mod year 4 == 0 = True
+ | otherwise = False
+
+daysInYear :: Year -> Int
+daysInYear year =
+ if isLeapYear year
+ then 366
+ else 365
+
+daysInMonth :: Date -> Int
+daysInMonth date
+ | elem m [1,3,5,7,8,10,12] = 31
+ | m == 2 = if isLeapYear y then 29 else 28
+ | otherwise = 30
+ where
+ m = month date
+ y = year date
View
1 README
@@ -19,4 +19,5 @@ Here's the current status: (No status listed if no code is checked in.)
#14: Some exploratory work
#15: SOLVED
#16: SOLVED
+#19: Some preliminary work
#20: SOLVED

0 comments on commit 610c82e

Please sign in to comment.