Solve #24 in Haskell.