solution to problem 21
solution to problem 31