Solves problem 12 in haskell