haskell versions of problem002 and problem003