implemented problem004 in haskell