Adding solution to Exercise 3.5