[Haskell-cafe] Solution to Thompson's Exercise 4.4
Gour
haskell_list at atmarama.org
Sat Mar 12 05:04:12 EST 2005
Kaoru Hosokawa (khosokawa at gmail.com) wrote:
> I hope to find a better solution. I googled but couldn't find the
> answer.
Here is what I have. I do not have working Haskell interpreter at
the moment (being on amd64), but this is what I have in my archive:
weakAscendingOrder :: Int -> Int -> Int -> Bool
weakAscendingOrder a b c
| (a < b) && (b == c) ||
(a == b) && (b < c) = True
| otherwise = False
howManyEqual :: Int -> Int -> Int -> Int
howManyEqual a b c
| (a == b ) && (b == c) = 3
| weakAscendingOrder a b c = 2
| (a /= b) && (b /= c) = 0
isEqual :: Int -> Int -> Int -> Int -> Bool
isEqual x a b c
| (x == a) = True
| (x == b) = True
| (x == c) = True
| otherwise = False
howManyOfFourEqual :: Int -> Int -> Int -> Int -> Int
howManyOfFourEqual a b c d
| isEqual a b c d = howManyEqual b c d + 1
| otherwise = howManyEqual b c d
Pls. test it ;)
Sincerely,
Gour
--
Registered Linux User | #278493
GPG Public Key | 8C44EDCD
More information about the Haskell-Cafe
mailing list