solve exercise 18.31