Solve problem 17 using Haskell.