Minimal Centrosymmetrization
Clash Royale CLAN TAG#URR8PPP
up vote
10
down vote
favorite
Topically related.
Objective: Given a matrix of positive integers $M$, output the smallest centrosymmetric matrix which contains $M$ (this matrix may contain non-positive integers as well).
A centrosymmetric matrix is a square matrix with rotational symmetry of order 2—i.e. it remains the same matrix after rotating it twice. For example, a centrosymmetric matrix has the top-left element the same as the bottom-right, and the element above the center the same as the one below the center. A useful visualization can be found here.
More formally, given a matrix $M$, produce a square matrix $N$ such that $N$ is centrosymmetric and $Msubseteq N$, and there is no other square matrix $K$ such that $dim K<dim N$.
$A$ is a subset of $B$ (notation: $Asubseteq B$) if and only if each value $A_i,j$ appears at index $B_i+i^prime,j+j^prime$ for some pair of integers $(i^prime, j^prime)$.
Note: some matrices have multiple solutions (e.g. [[3,3],[1,2]]
being solved as [[2,1,0],[3,3,3],[0,1,2]]
or [[3,3,3],[1,2,1],[3,3,3]]
); you must output at least one of the valid solutions.
Test cases
input
example output
[[1, 2, 3],
[4, 5, 6]]
[[1, 2, 3, 0],
[4, 5, 6, 0],
[0, 6, 5, 4],
[0, 3, 2, 1]]
[[9]]
[[9]]
[[9, 10]]
[[9, 10],
[10, 9]]
[[100, 200, 300]]
[[100, 200, 300],
[ 0, 0, 0],
[300, 200, 100]]
[[1, 2, 3],
[4, 5, 4]]
[[1, 2, 3],
[4, 5, 4]
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[4, 5, 4],
[1, 2, 3]]
[[3, 2, 1],
[4, 5, 4],
[1, 2, 3]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
code-golf array-manipulation matrix
add a comment |Â
up vote
10
down vote
favorite
Topically related.
Objective: Given a matrix of positive integers $M$, output the smallest centrosymmetric matrix which contains $M$ (this matrix may contain non-positive integers as well).
A centrosymmetric matrix is a square matrix with rotational symmetry of order 2—i.e. it remains the same matrix after rotating it twice. For example, a centrosymmetric matrix has the top-left element the same as the bottom-right, and the element above the center the same as the one below the center. A useful visualization can be found here.
More formally, given a matrix $M$, produce a square matrix $N$ such that $N$ is centrosymmetric and $Msubseteq N$, and there is no other square matrix $K$ such that $dim K<dim N$.
$A$ is a subset of $B$ (notation: $Asubseteq B$) if and only if each value $A_i,j$ appears at index $B_i+i^prime,j+j^prime$ for some pair of integers $(i^prime, j^prime)$.
Note: some matrices have multiple solutions (e.g. [[3,3],[1,2]]
being solved as [[2,1,0],[3,3,3],[0,1,2]]
or [[3,3,3],[1,2,1],[3,3,3]]
); you must output at least one of the valid solutions.
Test cases
input
example output
[[1, 2, 3],
[4, 5, 6]]
[[1, 2, 3, 0],
[4, 5, 6, 0],
[0, 6, 5, 4],
[0, 3, 2, 1]]
[[9]]
[[9]]
[[9, 10]]
[[9, 10],
[10, 9]]
[[100, 200, 300]]
[[100, 200, 300],
[ 0, 0, 0],
[300, 200, 100]]
[[1, 2, 3],
[4, 5, 4]]
[[1, 2, 3],
[4, 5, 4]
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[4, 5, 4],
[1, 2, 3]]
[[3, 2, 1],
[4, 5, 4],
[1, 2, 3]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
code-golf array-manipulation matrix
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
I was wondering why you made that choice
– W W
yesterday
2
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday
add a comment |Â
up vote
10
down vote
favorite
up vote
10
down vote
favorite
Topically related.
Objective: Given a matrix of positive integers $M$, output the smallest centrosymmetric matrix which contains $M$ (this matrix may contain non-positive integers as well).
A centrosymmetric matrix is a square matrix with rotational symmetry of order 2—i.e. it remains the same matrix after rotating it twice. For example, a centrosymmetric matrix has the top-left element the same as the bottom-right, and the element above the center the same as the one below the center. A useful visualization can be found here.
More formally, given a matrix $M$, produce a square matrix $N$ such that $N$ is centrosymmetric and $Msubseteq N$, and there is no other square matrix $K$ such that $dim K<dim N$.
$A$ is a subset of $B$ (notation: $Asubseteq B$) if and only if each value $A_i,j$ appears at index $B_i+i^prime,j+j^prime$ for some pair of integers $(i^prime, j^prime)$.
Note: some matrices have multiple solutions (e.g. [[3,3],[1,2]]
being solved as [[2,1,0],[3,3,3],[0,1,2]]
or [[3,3,3],[1,2,1],[3,3,3]]
); you must output at least one of the valid solutions.
Test cases
input
example output
[[1, 2, 3],
[4, 5, 6]]
[[1, 2, 3, 0],
[4, 5, 6, 0],
[0, 6, 5, 4],
[0, 3, 2, 1]]
[[9]]
[[9]]
[[9, 10]]
[[9, 10],
[10, 9]]
[[100, 200, 300]]
[[100, 200, 300],
[ 0, 0, 0],
[300, 200, 100]]
[[1, 2, 3],
[4, 5, 4]]
[[1, 2, 3],
[4, 5, 4]
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[4, 5, 4],
[1, 2, 3]]
[[3, 2, 1],
[4, 5, 4],
[1, 2, 3]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
code-golf array-manipulation matrix
Topically related.
Objective: Given a matrix of positive integers $M$, output the smallest centrosymmetric matrix which contains $M$ (this matrix may contain non-positive integers as well).
A centrosymmetric matrix is a square matrix with rotational symmetry of order 2—i.e. it remains the same matrix after rotating it twice. For example, a centrosymmetric matrix has the top-left element the same as the bottom-right, and the element above the center the same as the one below the center. A useful visualization can be found here.
More formally, given a matrix $M$, produce a square matrix $N$ such that $N$ is centrosymmetric and $Msubseteq N$, and there is no other square matrix $K$ such that $dim K<dim N$.
$A$ is a subset of $B$ (notation: $Asubseteq B$) if and only if each value $A_i,j$ appears at index $B_i+i^prime,j+j^prime$ for some pair of integers $(i^prime, j^prime)$.
Note: some matrices have multiple solutions (e.g. [[3,3],[1,2]]
being solved as [[2,1,0],[3,3,3],[0,1,2]]
or [[3,3,3],[1,2,1],[3,3,3]]
); you must output at least one of the valid solutions.
Test cases
input
example output
[[1, 2, 3],
[4, 5, 6]]
[[1, 2, 3, 0],
[4, 5, 6, 0],
[0, 6, 5, 4],
[0, 3, 2, 1]]
[[9]]
[[9]]
[[9, 10]]
[[9, 10],
[10, 9]]
[[100, 200, 300]]
[[100, 200, 300],
[ 0, 0, 0],
[300, 200, 100]]
[[1, 2, 3],
[4, 5, 4]]
[[1, 2, 3],
[4, 5, 4]
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[1, 2, 3],
[5, 6, 5],
[3, 2, 1]]
[[4, 5, 4],
[1, 2, 3]]
[[3, 2, 1],
[4, 5, 4],
[1, 2, 3]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1]]
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1],
[9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
code-golf array-manipulation matrix
edited yesterday
asked yesterday


Conor O'Brien
27.7k260155
27.7k260155
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
I was wondering why you made that choice
– W W
yesterday
2
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday
add a comment |Â
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
I was wondering why you made that choice
– W W
yesterday
2
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
I was wondering why you made that choice
– W W
yesterday
I was wondering why you made that choice
– W W
yesterday
2
2
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
6
down vote
Brachylog, 12 bytes
á¹Â↔áµÂ↔?aaáµÂ.&≜∧
Try it online!
Contrary to most Brachylog answers, this takes the input through the Output variable .
, and outputs the result through the Input variable ?
(confusing, I know).
Explanation
á¹ We expect a square matrix
↔áµÂ↔? When we reverse the rows and then the matrix, we get the initial matrix back
?a Take an adfix (prefix or suffix) of that square matrix
aáµ Take an adfix of each row of that adfix matrix
. It must be the input matrix
&≜ Assign values to cells which are still variables (will assign 0)
∧ (disable implicit unification between the input and the output)
8 bytes, gives all valid matrices
Technically, this program also works:
á¹Â↔áµÂ↔?aaáµÂ
But this will leave as variables the cells which can take any value (they show as _XXXXX
, which is an internal Prolog variable name). So technically this is even better than what is asked, but I guess it's not what the challenge asks for.
I wish≜
did delayed labeling...
– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
add a comment |Â
up vote
3
down vote
JavaScript (ES6), 192 180 177 bytes
f=(m,v=[w=0],S=c=>v.some(c))=>S(Y=>S(X=>!m[w+1-Y]&!m[0][w+1-X]&!S(y=>S(x=>(k=(m[y-Y]||0)[x-X],g=y=>((r=a[y]=a[y]||)[x]=r[x]||k|0)-k)(y)|g(w-y,x=w-x)),a=)))?a:f(m,[...v,++w])
Try it online!
Algorithm
Starting with $w=0$:
- We consider a square container matrix $M$ of width $w+1$.
We consider each pair $(X,Y)$ such that the input matrix $m$ can fit within the container matrix when it's inserted at these coordinates.
Example:
$$beginalignw=2,&&(X,Y)=(0,1),&&m = pmatrix4,5,4\1,2,3endalign\
M=pmatrixcolorgray0,colorgray0,colorgray0\4,5,4\1,2,3$$
We test whether we can complete the matrix such that it's centrosymmetric.
Example:
$$M^prime=pmatrixcolorblue3,colorblue2,colorblue1\4,5,4\1,2,3$$
- We increment $w$ until we find such a valid configuration.
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
add a comment |Â
up vote
1
down vote
Python 2, 242 227 bytes
r=range
def f(m):
w,h=len(m),len(m[0]);W=max(w,h)
while 1:
for x in r(1+W-w):
for y in r(1+W-h):
n=[W*[0]for _ in r(W)];exec"for i in r(w):n[i+x][y:y+h]=m[i]nN=n;n=[l[::-1]for l in n[::-1]]n"*2
if n==N:return n
W+=1
Try it online!
add a comment |Â
up vote
1
down vote
Jelly, 27 bytes
oZ0á¹Âz0oâ¸ṚUŻ€Z$2¡Láoâ¸ṚU$ƑƇḢ
Try it online!
Newlines added to actual output over TIO for clarity.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
Brachylog, 12 bytes
á¹Â↔áµÂ↔?aaáµÂ.&≜∧
Try it online!
Contrary to most Brachylog answers, this takes the input through the Output variable .
, and outputs the result through the Input variable ?
(confusing, I know).
Explanation
á¹ We expect a square matrix
↔áµÂ↔? When we reverse the rows and then the matrix, we get the initial matrix back
?a Take an adfix (prefix or suffix) of that square matrix
aáµ Take an adfix of each row of that adfix matrix
. It must be the input matrix
&≜ Assign values to cells which are still variables (will assign 0)
∧ (disable implicit unification between the input and the output)
8 bytes, gives all valid matrices
Technically, this program also works:
á¹Â↔áµÂ↔?aaáµÂ
But this will leave as variables the cells which can take any value (they show as _XXXXX
, which is an internal Prolog variable name). So technically this is even better than what is asked, but I guess it's not what the challenge asks for.
I wish≜
did delayed labeling...
– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
add a comment |Â
up vote
6
down vote
Brachylog, 12 bytes
á¹Â↔áµÂ↔?aaáµÂ.&≜∧
Try it online!
Contrary to most Brachylog answers, this takes the input through the Output variable .
, and outputs the result through the Input variable ?
(confusing, I know).
Explanation
á¹ We expect a square matrix
↔áµÂ↔? When we reverse the rows and then the matrix, we get the initial matrix back
?a Take an adfix (prefix or suffix) of that square matrix
aáµ Take an adfix of each row of that adfix matrix
. It must be the input matrix
&≜ Assign values to cells which are still variables (will assign 0)
∧ (disable implicit unification between the input and the output)
8 bytes, gives all valid matrices
Technically, this program also works:
á¹Â↔áµÂ↔?aaáµÂ
But this will leave as variables the cells which can take any value (they show as _XXXXX
, which is an internal Prolog variable name). So technically this is even better than what is asked, but I guess it's not what the challenge asks for.
I wish≜
did delayed labeling...
– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
add a comment |Â
up vote
6
down vote
up vote
6
down vote
Brachylog, 12 bytes
á¹Â↔áµÂ↔?aaáµÂ.&≜∧
Try it online!
Contrary to most Brachylog answers, this takes the input through the Output variable .
, and outputs the result through the Input variable ?
(confusing, I know).
Explanation
á¹ We expect a square matrix
↔áµÂ↔? When we reverse the rows and then the matrix, we get the initial matrix back
?a Take an adfix (prefix or suffix) of that square matrix
aáµ Take an adfix of each row of that adfix matrix
. It must be the input matrix
&≜ Assign values to cells which are still variables (will assign 0)
∧ (disable implicit unification between the input and the output)
8 bytes, gives all valid matrices
Technically, this program also works:
á¹Â↔áµÂ↔?aaáµÂ
But this will leave as variables the cells which can take any value (they show as _XXXXX
, which is an internal Prolog variable name). So technically this is even better than what is asked, but I guess it's not what the challenge asks for.
Brachylog, 12 bytes
á¹Â↔áµÂ↔?aaáµÂ.&≜∧
Try it online!
Contrary to most Brachylog answers, this takes the input through the Output variable .
, and outputs the result through the Input variable ?
(confusing, I know).
Explanation
á¹ We expect a square matrix
↔áµÂ↔? When we reverse the rows and then the matrix, we get the initial matrix back
?a Take an adfix (prefix or suffix) of that square matrix
aáµ Take an adfix of each row of that adfix matrix
. It must be the input matrix
&≜ Assign values to cells which are still variables (will assign 0)
∧ (disable implicit unification between the input and the output)
8 bytes, gives all valid matrices
Technically, this program also works:
á¹Â↔áµÂ↔?aaáµÂ
But this will leave as variables the cells which can take any value (they show as _XXXXX
, which is an internal Prolog variable name). So technically this is even better than what is asked, but I guess it's not what the challenge asks for.
answered yesterday


Fatalize
26.2k448131
26.2k448131
I wish≜
did delayed labeling...
– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
add a comment |Â
I wish≜
did delayed labeling...
– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
I wish
≜
did delayed labeling...– Erik the Outgolfer
23 hours ago
I wish
≜
did delayed labeling...– Erik the Outgolfer
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
@EriktheOutgolfer Instant labeling is still useful when we need to enumerate things, so ideally we would need two different predicates…
– Fatalize
23 hours ago
add a comment |Â
up vote
3
down vote
JavaScript (ES6), 192 180 177 bytes
f=(m,v=[w=0],S=c=>v.some(c))=>S(Y=>S(X=>!m[w+1-Y]&!m[0][w+1-X]&!S(y=>S(x=>(k=(m[y-Y]||0)[x-X],g=y=>((r=a[y]=a[y]||)[x]=r[x]||k|0)-k)(y)|g(w-y,x=w-x)),a=)))?a:f(m,[...v,++w])
Try it online!
Algorithm
Starting with $w=0$:
- We consider a square container matrix $M$ of width $w+1$.
We consider each pair $(X,Y)$ such that the input matrix $m$ can fit within the container matrix when it's inserted at these coordinates.
Example:
$$beginalignw=2,&&(X,Y)=(0,1),&&m = pmatrix4,5,4\1,2,3endalign\
M=pmatrixcolorgray0,colorgray0,colorgray0\4,5,4\1,2,3$$
We test whether we can complete the matrix such that it's centrosymmetric.
Example:
$$M^prime=pmatrixcolorblue3,colorblue2,colorblue1\4,5,4\1,2,3$$
- We increment $w$ until we find such a valid configuration.
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
add a comment |Â
up vote
3
down vote
JavaScript (ES6), 192 180 177 bytes
f=(m,v=[w=0],S=c=>v.some(c))=>S(Y=>S(X=>!m[w+1-Y]&!m[0][w+1-X]&!S(y=>S(x=>(k=(m[y-Y]||0)[x-X],g=y=>((r=a[y]=a[y]||)[x]=r[x]||k|0)-k)(y)|g(w-y,x=w-x)),a=)))?a:f(m,[...v,++w])
Try it online!
Algorithm
Starting with $w=0$:
- We consider a square container matrix $M$ of width $w+1$.
We consider each pair $(X,Y)$ such that the input matrix $m$ can fit within the container matrix when it's inserted at these coordinates.
Example:
$$beginalignw=2,&&(X,Y)=(0,1),&&m = pmatrix4,5,4\1,2,3endalign\
M=pmatrixcolorgray0,colorgray0,colorgray0\4,5,4\1,2,3$$
We test whether we can complete the matrix such that it's centrosymmetric.
Example:
$$M^prime=pmatrixcolorblue3,colorblue2,colorblue1\4,5,4\1,2,3$$
- We increment $w$ until we find such a valid configuration.
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
add a comment |Â
up vote
3
down vote
up vote
3
down vote
JavaScript (ES6), 192 180 177 bytes
f=(m,v=[w=0],S=c=>v.some(c))=>S(Y=>S(X=>!m[w+1-Y]&!m[0][w+1-X]&!S(y=>S(x=>(k=(m[y-Y]||0)[x-X],g=y=>((r=a[y]=a[y]||)[x]=r[x]||k|0)-k)(y)|g(w-y,x=w-x)),a=)))?a:f(m,[...v,++w])
Try it online!
Algorithm
Starting with $w=0$:
- We consider a square container matrix $M$ of width $w+1$.
We consider each pair $(X,Y)$ such that the input matrix $m$ can fit within the container matrix when it's inserted at these coordinates.
Example:
$$beginalignw=2,&&(X,Y)=(0,1),&&m = pmatrix4,5,4\1,2,3endalign\
M=pmatrixcolorgray0,colorgray0,colorgray0\4,5,4\1,2,3$$
We test whether we can complete the matrix such that it's centrosymmetric.
Example:
$$M^prime=pmatrixcolorblue3,colorblue2,colorblue1\4,5,4\1,2,3$$
- We increment $w$ until we find such a valid configuration.
JavaScript (ES6), 192 180 177 bytes
f=(m,v=[w=0],S=c=>v.some(c))=>S(Y=>S(X=>!m[w+1-Y]&!m[0][w+1-X]&!S(y=>S(x=>(k=(m[y-Y]||0)[x-X],g=y=>((r=a[y]=a[y]||)[x]=r[x]||k|0)-k)(y)|g(w-y,x=w-x)),a=)))?a:f(m,[...v,++w])
Try it online!
Algorithm
Starting with $w=0$:
- We consider a square container matrix $M$ of width $w+1$.
We consider each pair $(X,Y)$ such that the input matrix $m$ can fit within the container matrix when it's inserted at these coordinates.
Example:
$$beginalignw=2,&&(X,Y)=(0,1),&&m = pmatrix4,5,4\1,2,3endalign\
M=pmatrixcolorgray0,colorgray0,colorgray0\4,5,4\1,2,3$$
We test whether we can complete the matrix such that it's centrosymmetric.
Example:
$$M^prime=pmatrixcolorblue3,colorblue2,colorblue1\4,5,4\1,2,3$$
- We increment $w$ until we find such a valid configuration.
edited yesterday
answered yesterday


Arnauld
60.3k472253
60.3k472253
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
add a comment |Â
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
(The MathJax rendering bug has been reported in this post.)
– Arnauld
yesterday
add a comment |Â
up vote
1
down vote
Python 2, 242 227 bytes
r=range
def f(m):
w,h=len(m),len(m[0]);W=max(w,h)
while 1:
for x in r(1+W-w):
for y in r(1+W-h):
n=[W*[0]for _ in r(W)];exec"for i in r(w):n[i+x][y:y+h]=m[i]nN=n;n=[l[::-1]for l in n[::-1]]n"*2
if n==N:return n
W+=1
Try it online!
add a comment |Â
up vote
1
down vote
Python 2, 242 227 bytes
r=range
def f(m):
w,h=len(m),len(m[0]);W=max(w,h)
while 1:
for x in r(1+W-w):
for y in r(1+W-h):
n=[W*[0]for _ in r(W)];exec"for i in r(w):n[i+x][y:y+h]=m[i]nN=n;n=[l[::-1]for l in n[::-1]]n"*2
if n==N:return n
W+=1
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 242 227 bytes
r=range
def f(m):
w,h=len(m),len(m[0]);W=max(w,h)
while 1:
for x in r(1+W-w):
for y in r(1+W-h):
n=[W*[0]for _ in r(W)];exec"for i in r(w):n[i+x][y:y+h]=m[i]nN=n;n=[l[::-1]for l in n[::-1]]n"*2
if n==N:return n
W+=1
Try it online!
Python 2, 242 227 bytes
r=range
def f(m):
w,h=len(m),len(m[0]);W=max(w,h)
while 1:
for x in r(1+W-w):
for y in r(1+W-h):
n=[W*[0]for _ in r(W)];exec"for i in r(w):n[i+x][y:y+h]=m[i]nN=n;n=[l[::-1]for l in n[::-1]]n"*2
if n==N:return n
W+=1
Try it online!
edited yesterday
answered yesterday


TFeld
10.2k1832
10.2k1832
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 27 bytes
oZ0á¹Âz0oâ¸ṚUŻ€Z$2¡Láoâ¸ṚU$ƑƇḢ
Try it online!
Newlines added to actual output over TIO for clarity.
add a comment |Â
up vote
1
down vote
Jelly, 27 bytes
oZ0á¹Âz0oâ¸ṚUŻ€Z$2¡Láoâ¸ṚU$ƑƇḢ
Try it online!
Newlines added to actual output over TIO for clarity.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 27 bytes
oZ0á¹Âz0oâ¸ṚUŻ€Z$2¡Láoâ¸ṚU$ƑƇḢ
Try it online!
Newlines added to actual output over TIO for clarity.
Jelly, 27 bytes
oZ0á¹Âz0oâ¸ṚUŻ€Z$2¡Láoâ¸ṚU$ƑƇḢ
Try it online!
Newlines added to actual output over TIO for clarity.
answered 13 hours ago


Erik the Outgolfer
29.1k42697
29.1k42697
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f170020%2fminimal-centrosymmetrization%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why do Centrosymmetric matrices have to be square?
– W W
yesterday
@WW in a general sense, I don't suppose it has to be. For this question, however, they must be square by definition
– Conor O'Brien
yesterday
I was wondering why you made that choice
– W W
yesterday
2
@WW it was a simplification I thought to be useful for clarity
– Conor O'Brien
yesterday