finished prob 9.  this is sort of brute force.  There has to be a
better solution...