Finished Problem 39 (Haskell)