Ever since I read this blog, I have been curious to see how other space-filling curves other than Hilbert can be used to reduce the run time. I chose the Peano curve.
Let's build a $$$3^k x 3^k$$$ matrix and visit all the cells on the matrix according to this curve. Then denote $$$\text{ord}(i,j,k)$$$ as the number of cells visited before the cell $$$(i,j)$$$ on the $$$3^k x 3^k$$$ matrix.