Note: This question is not about this particular instance of this grid with these exact words, but about any combination of words.
I am programming a puzzle game where you have to arrange a grid of words correctly. The image below shows a final grid.
The grid is represented by a two-dimensional string array and could look like this (the empty spaces are represented by undefined
elements):
const crosswordGrid = [
["a", "u", "d", "i", "t",],
["t", undefined, "e", undefined, "e",],
["t", "r", "i", "c", "e",],
["i", undefined, "g", undefined, "t",],
["c", "o", "n", "c", "h",],
];
How could I mix the characters in this grid in a way that it's guaranteed solvable in X minimum steps (for example, 10)?
Note: By "step" I mean a swap of any two arbitrary characters/tiles anywhere on the entire grid. The shape of the grid stays the same and the undefined
elements stay in place.
Clearly, I can't just swap 10 random tiles because the same letters in different places will require fewer necessary swaps to get back to the correct solution. I tried swapping tiles as a chain, but that also didn't work.