Solves problem 9 in haskell