countInversions

private fun countInversions(puzzleState: ArrayList<Int>, blankTileMarker: Int): Int

Counts the number of inversions in the puzzle state.

An inversion refers to a pair of elements that are out of their natural order (in this 8-puzzle, the natural order of the elements/positions is ascending).

Return

Number of inversions in the puzzle state.

Parameters

puzzleState

Current puzzle state (flattened into one dimension, following row-major order).

blankTileMarker

Indicator that the tile is blank.