QUOTE(Gloin @ 21 Mar, 2009 - 02:55 AM)

I don't know any short-cut polynomial algorithm for this problem and the immediate thought is that you would have to try an exponential number of combinations to find the solution.
However, considering there are likely more than one solution to many of these puzzles and that you can branch quite heavily, there's likely a pretty good chance of finding a solution fast anyways.
What's the largest puzzle that you allow? Is there a limit or do you intend to have a solver for the n by n case?
the largest puzzle that i allow is 6*6 and the smallest is 2*2, i actually i thought of it and i drew a diagram for all the possibilities on paper, i thought of using recursion for it, i don't know if this is a good idea though...
btw i already have the solution, because what my program does, is that it generates the solution first and then it shuffles the puzzle(to ensure that the puzzle is solvable) so if the user gives up and wants to see the solution the solution will be displayed, what i was thinking of doing is to write a generic algorithm to solve any puzzle...