Solve #51 in Haskell.