Solution to problem 31