A solution for exercise 17.6