Originally posted by: stonecold3169
Alright, bear with me here, this may be incoherent

first of all, I have this coded in the language of Scheme, and you can put in any sized square grid and it will solve it. If you're interested in seeing my source, and have a scheme interpreter, you ar emore then welcome to. Next: Obviously you know that the algorithm is going to be recursive, well, at least if you are going to make it work for multiple puzzle box sizes. Next: It's important to realize ahead of time that this is going to grow in running time very exponentially. That is, this is going to get nasty. a 3 by 3 box is the base case, and everything needs to be broken up into a base case, so a 4x4 box is going to have 4 3x3 puzzle boxes inside of it, so keep that in mind too. I used scheme because its hella fast at this kind of stuff, you definitely don't want to try this in java or the such, it's just too slow. So here is what I did... I used a list (since scheme doesn't have arrays) of lists to store in the first 3x3 grid, which is the one in the bottom left hand corner (well, the corner opposite of where you want the blank tile to be in the end). From here, it is relatively simple to solve in that the puzzle can be solved using a series of counterclockwise rotations upon the right "outside" of the grid. Where this gets complicated is that this implies you know where pieces are, which you don't... luckily, you saved a list of 3 lists with the values inside of them, and that way you don't need to scan the whole deal to find out where the first, second, third, etc pieces are. You then recursively need to move the pieces counterclockwise along the lists in which the blank goes to the outside, the piece you ar etrying to fit in goes to tehoutside, and then rotate until it gets there. It sounds more confusing then it is, but sit down and try it. Every game can be won using counterclockwise rotations and nothing else. Clockwise rotations have a small(sub 20%) chance of cause an impossible situation by doing clockwise rotations at all. Recursion doesn't like chances of failure. After the first grid is solved, simply move over one set of blocks and do it again until you are at the end of columns, then go back to the blocks on top of the first set and solve that, etc... until it is all solved. If you need any more help, let me know... this is some crazy head stuff, and I made a very good female friend by teaming up to tackle this my sophmore year of college

... involved many, many late nights in a comp lab.