Friday, February 27, 2009

finding the highest common factor/divisor for two integers in haskell

hcf :: Int -> Int -> Int
--handles all cases of zero
hcf 0 0 = undefined 
hcf m 0 = abs m
hcf 0 n = abs n
hcf m n 
    | m == n       = m 
    | m > n        = hcf n (rem m n) 
    | otherwise    = hcf n m

No comments:

Post a Comment