Solution for problem 30