Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Leap-year/Haskell/leap-year-1.hs
Normal file
9
Task/Leap-year/Haskell/leap-year-1.hs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import Data.List
|
||||
import Control.Monad
|
||||
import Control.Arrow
|
||||
|
||||
leaptext x b | b = show x ++ " is a leap year"
|
||||
| otherwise = show x ++ " is not a leap year"
|
||||
|
||||
isleapsf j | 0==j`mod`100 = 0 == j`mod`400
|
||||
| otherwise = 0 == j`mod`4
|
||||
1
Task/Leap-year/Haskell/leap-year-2.hs
Normal file
1
Task/Leap-year/Haskell/leap-year-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
isleap = foldl1 ((&&).not).flip map [400, 100, 4]. ((0==).).mod
|
||||
6
Task/Leap-year/Haskell/leap-year-3.hs
Normal file
6
Task/Leap-year/Haskell/leap-year-3.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
*Main> mapM_ (putStrLn. (ap leaptext isleap)) [1900,1994,1996,1997,2000]
|
||||
1900 is not a leap year
|
||||
1994 is not a leap year
|
||||
1996 is a leap year
|
||||
1997 is not a leap year
|
||||
2000 is a leap year
|
||||
14
Task/Leap-year/Haskell/leap-year-4.hs
Normal file
14
Task/Leap-year/Haskell/leap-year-4.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import Test.HUnit
|
||||
|
||||
isLeapYear::Int->Bool
|
||||
isLeapYear y
|
||||
| mod y 400 == 0 = True
|
||||
| mod y 100 == 0 = False
|
||||
| mod y 4 == 0 = True
|
||||
| otherwise = False
|
||||
|
||||
tests = TestList[TestCase $ assertEqual "4 is a leap year" True $ isLeapYear 4
|
||||
,TestCase $ assertEqual "1 is not a leap year" False $ isLeapYear 1
|
||||
,TestCase $ assertEqual "64 is a leap year" True $ isLeapYear 64
|
||||
,TestCase $ assertEqual "2000 is a leap year" True $ isLeapYear 2000
|
||||
,TestCase $ assertEqual "1900 is not a leap year" False $ isLeapYear 1900]
|
||||
Loading…
Add table
Add a link
Reference in a new issue