Very nice work!
I've not read it in detail, thus not in the position to comment whether it's logical method or trial and error. I'd suggest to express your algorithm with more mathematical notation, and support the steps with more lemmas and/or theorems which form the keys of your algorithm. Congratulations !