Small program to solve problem 47 on PE