solved problem 16 in Haskell