added code for problem 47