Solution for problem 22