Your solution looks really elegant, and runs insanely fast.  Can you explain how it works?