/* This is O(scary), but seems quick enough in practice. */ (via http://tr.im/lKXH ) View the discussion thread.