I think I will go chew on dinner instead.
(This is a lovely little problem that I suspect is ideally solved by recursion, but I have not yet figured out how to set things up so that the recursion will do what I actually want it to. Dinner should help. :) )