Project Euler problem, solved in Haskell