add book's solution for problem 6