Very nice. I think this one would give my coworkers tremendous pause, but this will work in the general case, whereas NetWallah's solution fails if we have some more grotesque AoHoAoAoH thing going on.

Update: And it actually gives you tremendous control over localization scope, since you can stash the guard at whatever level you want. Nice.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.