solved problem #4 in haskell