problem 16 in Haskell