Adding solution for Problem 8