Solves problem 17 in haskell