add my solution to homework in chapter 8