code that solve the problem from a book