solved exercise 24 in chapter3