C#

help

Root Question Message

xellez12/8/2022

It is supposed to be 10 inversion count but I am getting 13

```
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 ?TheBoxyBear12/8/2022

What do you mean by inversion?

xellez12/8/2022

it is for a puzzle problem

xellez12/8/2022

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.

xellez12/8/2022

trying to apply the same method

Jimmahdean12/8/2022

just counting, i get ~~12~~ 13

Jimmahdean12/8/2022

but i'm lacking about four cups of coffee so idk

Jimmahdean12/8/2022

i'm not sure what you're trying to do really

Jimmahdean12/8/2022

1 precedes 0 : 1

8 precedes 2 0 4 3 7 6 5 : 7 (8)

2 precedes 0 : 1 (9)

0 precedes nothing

4 precedes 3 : 1 (10)

3 precedes nothing

7 precedes 6 5 : 2 (12)

6 precedes 5 : 1 (13)

8 precedes 2 0 4 3 7 6 5 : 7 (8)

2 precedes 0 : 1 (9)

0 precedes nothing

4 precedes 3 : 1 (10)

3 precedes nothing

7 precedes 6 5 : 2 (12)

6 precedes 5 : 1 (13)