Friday, February 27, 2009

Finding max of two, three or four in haskell

maxTwo :: Int -> Int -> Int
maxTwo x y
| x>y                   = x
| otherwise             = y
maxThree :: Int -> Int -> Int -> Int
maxThree x y z 
|maxTwo x y > z            = maxTwo x y
|otherwise   = z

maxFour :: Int -> Int -> Int -> Int -> Int
maxFour v x y z
| maxThree v x y > z      = maxThree v x y
| otherwise               = z

No comments:

Post a Comment