help
Root Question Message
var array = new int[] { 1, 8, 2, 0, 4, 3, 7, 6, 5 };
int inv_count = 0;
for (int i = 0; i < array.Length - 1; i++) {
for (int j = i + 1; j < array.Length; j++)
{
if (array[i] > array[j])
inv_count++;
}
}
return inv_count;
}
What am I screwing up or missing something ?Now find the number of inversion, by counting tiles precedes the another tile with lower number.
In our case, 1,2,3,4,5,6,7 is having 0 inversions, and 8 is having 1 inversion as it's preceding the number 7.
Total number of inversion is 1 (odd number) so the puzzle is insolvable.