solved exercise 29 in chapter3