add a solution to problem 9. The comment in the code may be not that
intuitive.