Problem 52 in Haskell