Solves problem 13 in haskell