Problem 7 solved in Haskell.