Other Ocaml solutions.
let leap_year year =
year mod 4 = 0 &&
(year mod 100 <> 0 || year mod 400 = 0)
Other Nim solutions.
func isLeapYear*(year: int): bool =
year mod 4 == 0 and (
year mod 100 != 0 or year mod 400 == 0
)
Other Rust solutions.
pub fn is_leap_year(year: u64) -> bool {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
Other Elm solutions.
module Leap exposing (isLeapYear)
divisbleBy : Int -> Int -> Bool
divisbleBy div x =
modBy div x == 0
isLeapYear : Int -> Bool
isLeapYear year =
List.all
(\fn -> fn year)
[ divisbleBy 4
, fOr (divisbleBy 100 >> not) (divisbleBy 400)
]
fOr f g x =
f x || g x
Other Haskell solutions.
module LeapYear
( isLeapYear
) where
bind :: (b -> b -> b) -> (a -> b) -> (a -> b) -> a -> b
bind f a b x = f (a x) (b x)
infixl 5 &&$
(&&$) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
(&&$) = bind (&&)
infixl 5 ||$
(||$) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
(||$) = bind (||)
isLeapYear :: Integer -> Bool
isLeapYear = isDivisibleBy 400 ||$ (isDivisibleBy 4 &&$ not . isDivisibleBy 100)
where
isDivisibleBy = (\divisor x -> mod x divisor == 0)
Other Roc solutions.
module [isLeapYear]
isLeapYear : I64 -> Bool
isLeapYear = \year ->
year % 4 == 0 &&
year % 100 != 0 || year % 400 == 0