I have a fairly good idea on how to make a very efficient algorithm for this. If there is a need for it, I would love to help in any way I can.