Solve Problem 65 in Haskell