Friday, February 27, 2009

finding out how many are equal amongst three numnbers in haskell

howManyEqual :: Int -> Int -> Int -> Int
howManyEqual x y z 
|((equal x y) + (equal y z) + (equal x z)) == 1     = 2
| otherwise                                         = (equal x y) + (equal y z) + (equal x z)
equal :: Int -> Int -> Int
equal x y 
| x == y           = 1
| otherwise        = 0

No comments:

Post a Comment