37
6
Defintion
A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix \$A\$ of size \$n \times n\$ is centrosymmetric if, for any \$i,\: j \in ([1, n] \cap \mathbb{Z})\$ the following relation is satisfied: $$A_{i,\:j}=A_{n+1-i,\:n+1-j}$$
Examples of such matrices
Here is an illustration of the symmetry of a matrices like these (borrowed from the aforementioned Wikipedia article):
An even-side-length (\$4\times 4\$) centrosymmetric matrix:
$$\left(\begin{matrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 8 & 7 & 6 & 5 \\ 4 & 3 & 2 & 1\end{matrix}\right)$$
And an odd-side-length (\$3\times 3\$) one:
$$\left(\begin{matrix} 1 & 2 & 3 \\ 5 & 6 & 5 \\ 3 & 2 & 1\end{matrix}\right)$$
Task and Specs
Given a square matrix of size at least \$2\$, output one of two distinct and consistent values, deciding whether the matrix is centrosymmetric or not. You can assume that the matrix will consist entirely of positive integers.
However, your code must also be centrosymmetric. That is, it must be a program / function (or equivalents) consisting of \$n\$ lines, each of which containing \$n\$ bytes in your language's encoding, and must satisfy the definition given above, but with bytes instead of positive integers. Your submission's score will be the value of \$n\$, with a lower \$n\$ being better.
You can take input and provide output through any standard method and in any reasonable format, while taking note that these loopholes are forbidden by default. You may (optionally) choose to take the size, \$n\$, as input too (unless you take input as a 1D list, in which case you may only take \$n^2\$ as additional input).
Test cases
Truthy:
[[1, 2], [2, 1]]
[[1, 2, 3], [5, 6, 5], [3, 2, 1]]
[[10, 5, 30], [2, 6, 2], [30, 5, 10]]
[[100, 100, 100], [100, 50, 100], [100, 100, 100]]
[[1, 2, 3, 4], [5, 6, 7, 8], [8, 7, 6, 5], [4, 3, 2, 1]]
[[3, 4, 5, 6, 7], [5, 6, 7, 8, 9], [3, 2, 10, 2, 3], [9, 8, 7, 6, 5], [7, 6, 5, 4, 3]]
Falsy:
[[1, 2], [1, 2]]
[[1, 2, 10], [5, 6, 5], [11, 2, 1]]
[[14, 5, 32], [2, 6, 2], [30, 5, 16]]
[[19, 19, 19], [40, 50, 4], [19, 19, 19]]
[[1, 2, 20, 4], [7, 6, 7, 8], [8, 7, 6, 6], [3, 3, 2, 1]]
[[3, 4, 5, 6, 7], [5, 6, 7, 8, 9], [4, 5, 10, 4, 5], [5, 6, 7, 8, 9], [3, 4, 5, 6, 7]]
1Hmm, this still looks pretty hard for non-golfing languages because it breaks parentheses and brackets without comments. A naive approach would be to end each line with a comment character (like Python's
#
), so that the bottom half of the code would all be a comment. – JungHwan Min – 2018-07-16T20:31:37.720@JungHwanMin In this particular case Python's
#
won't work because comments preceded by#
are inline only :P – Mr. Xcoder – 2018-07-16T20:32:56.403comment out half lines with doc strings """? – fəˈnɛtɪk – 2018-07-16T20:35:07.433
@Mr.Xcoder I mean something like
acode#\nbcode#\nccode#\n#edocc\n#edocb\n#edoca
. – JungHwan Min – 2018-07-16T20:37:27.407Or even
aco#de\nbco#de\ncco#de\ned#occ\ned#ocb\ned#oca
. – JungHwan Min – 2018-07-16T20:39:33.5931
Possible duplicate of I'm a palindrome. Are you?
– Pavel – 2018-07-16T22:11:03.533It's basically the same question with the added task of flattening the input first. – Pavel – 2018-07-16T22:11:32.777
6I guess I'll just beg to differ, as the restrictions on the source change things quite a lot and the winning criterion is different. In my opinion, these differences suffice. Plus, the are other techniques (in many languages shorter ones - e.g. Mathematica) that can be used instead of flatten+palindrome check. – Mr. Xcoder – 2018-07-16T22:18:22.663
Our input is guarentted to be square, must our code? – Post Rock Garf Hunter – 2018-07-17T16:36:31.660
@WW *A centrosymmetric matrix is a square matrix* and your code must be centrosymmetric, so yes, the code has to be square. – Mr. Xcoder – 2018-07-17T16:39:16.113
Why does a centrosymmetric matrix have to be square? The definition works just as well without it. – Post Rock Garf Hunter – 2018-07-17T16:41:21.330
@WW Because I chose to define it as such. For the purposes of this challenge, any centrosymmetric matrix must be square. – Mr. Xcoder – 2018-07-17T16:42:20.120
My question is why did you choose that? – Post Rock Garf Hunter – 2018-07-17T16:47:24.123
1@WW In short, to keep the challenge simple and avoid any kind of unwanted edge cases. Besides, keeping it square is more intuitive to me. – Mr. Xcoder – 2018-07-17T16:50:13.297
Keeping it square also has the added benefit of preventing one-liner palindromes. – mbomb007 – 2018-07-17T21:35:28.703
I wonder how much harder/easier this challenge would be if the rotation was 90 degrees instead of 180. – Enrico Borba – 2018-07-23T06:20:42.710