Solve problem 123 using Haskell.