Solve #3 in Haskell.