Solve #12 in Haskell.