Solution for problem 9