solved exercise 27 in chapter3