Simplified haskell solution to problem 39.