Solution for problem 47