solved problem 003 in Haskell