Solve #54 in Haskell.