Do problem 5 in Haskell.