My 1st try (need refactoring!)

It's not as elegant as Luke's solution, but, hopefully, it works. I'll
revisit it again soon!