raw problem 12 solution in Haskell