Solve problem 24 using Haskell.