Yesterday I was reading the book Beautiful Code when I found out a silly, and even evident, way for finding out the number of columns/rows of an square matrix when represented in an array.
Just make the square root of the length of the array.
It is so simple that I cannot imagine why I never thought about this way before.