How do you calculate number of inversions for a 8×8 puzzle? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 3

How do you calculate number of inversions for a 8×8 puzzle?

The following tutorial shows how to do it but i don't understand it at all ,so if anyone can explain me ? Ty ! https://www.google.com/amp/s/www.geeksforgeeks.org/check-instance-8-puzzle-solvable/amp/ Also they talk about a=[[1, 8,2], [0, 4,3], [7, 6,5]] having 10 inversions but when i used their code to test it out , it came only 2!!.

11th Feb 2021, 10:53 AM
Abhay
Abhay - avatar
1 Respuesta
0
I am highly guessing here... I notice that “a” looks like it is meant to represent a grid, which could have multiple shufflings (IDK what an inversion is). however, if the code only worked with the upper layer (only the rows of the grid), it would end up with only 2 different ways to order the rows that did not basically come to the same thing when repeated. What i mean is that no matter which way you mix 1 2 and 3, if you say the mix over and over you will find yourself either saying “1 2 3” or “3 2 1.”
13th Feb 2021, 12:14 AM
Wilbur Jaywright
Wilbur Jaywright - avatar