Chapter 4 exercises done.

I was looking for a way to do this without lots of `open()` type code.