Wonderful it works very well. Is it something easy to dertermine the order of your algorithm ?. That will give idea of how long it can take to run. I obsereved that for higher dimension it takes much longer.
At that rate, order 5 will test about 1 billion cases and take over a day to run. But
I think it might be feasible if bad solution sets are eliminated early.
The big problem is the permutations, which are factorial order. I would suggest picking the corner two items first. They have to have the same top digit. Then that determines the possible top digits of the rest of the rows.