solved problem 005 in haskell