Solution for problem 38 in Haskell. Really rusty Haskell