Working solution for 8puzzle using 2d array