¿La matriz es centrosimétrica ... y también lo es el código?

37

Definición

A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix A of size n×n is centrosymmetric if, for any i,j([1,n]Z) the following relation is satisfied:

Ai,j=An+1i,n+1j

Examples of such matrices

Here is an illustration of the symmetry of a matrices like these (borrowed from the aforementioned Wikipedia article):

Centrosymmetric 5 by 5 matrix illustrated in a really nice way

An even-side-length (4×4) centrosymmetric matrix:

(1234567887654321)

And an odd-side-length (3×3) one:

(123565321)

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 n2 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]]
Mr. Xcoder
fuente
1
Hmm, 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
@JungHwanMin In this particular case Python's # won't work because comments preceded by # are inline only :P
Mr. Xcoder
1
Possible duplicate of I'm a palindrome. Are you?
Pavel
6
I 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
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

Respuestas:

20

JavaScript (ES6), size 12 11 9

All versions return false for centrosymmetric or true for non-centrosymmetric.


1-dimensional array + length, size 9 (89 bytes)

Takes input in currying syntax (length)(array), where array is 1-dimensional.

w=>a=> //
a.some //
(v=>v- //
a[--w])//
/////////
//)]w--[a
// -v>=v(
// emos.a
// >=a>=w

Try it online!


Matrix + width, size 11 (131 bytes)

Takes input in currying syntax (width)(matrix).

/**/w=>a=>a
.some(r=>r.
some(v=>v-a
[y][w-++x],
x=!y--),y=w
);'*/'/*';)
w=y,)--y!=x
,]x++-w[]y[
a-v>=v(emos
.r>=r(emos.
a>=a>=w/**/

Try it online!

Payload

w => a => a.some(r => r.some(v => v - a[y][w - ++x], x = !y--), y = w)

Container

/**/CODE;'*/'/*';EDOC/**/

Matrix only, size 12 (155 bytes)

This is my original solution, which computes the width of the matrix by itself.

/**/a=>a[w=a
.length-1,s=
'some']((r,y
)=>r[s]((v,x
)=>v-a[w-y][
w-x]))////*/
/*////))]x-w
[]y-w[a-v>=)
x,v((]s[r>=)
y,r((]'emos'
=s,1-htgnel.
a=w[a>=a/**/

Try it online!

How?

We need a few critical tokens that cannot be split:

  • some
  • length
  • )=>

Line-feeds may be inserted almost anywhere else.

The unrolled payload code reads as:

a => a[w = a.length - 1, s = 'some']((r, y) => r[s]((v, x) => v - a[w - y][w - x]))

and is wrapped inside the following structure:

/**/CODE////*/

which, once reversed, becomes a valid block comment:

/*////EDOC/**/
Arnauld
fuente
18

Jelly, score 2

⁼Ṛ
Ṛ⁼

Try it online!

Takes input as a flattened square matrix (vector of size n2).

Erik the Outgolfer
fuente
15

Befunge-93, size 24

   &:00p110p920p::*:v   
vp01:+1g01-1pg02g01&_v#<
>00g`#v_>:           1$^
v2p011<  v:g00p029p01< @
>0g1+20p^>*:#v_1# .#<@ .
v+1g00gg02g01<$ >1+10pv0
>:10g-\88++20g -g-     |
vg02p011_v#`g00g01-1  <1
>1+20p   >:   ^ ^      <
                        
                        
                        
                        
                        
                        
<      ^ ^   :>   p02+1>
1<  1-10g00g`#v_110p20gv
|     -g- g02++88\-g01:>
0vp01+1> $<10g20gg00g1+v
. @<#. #1_v#:*>^p02+1g0>
@ <10p920p00g:v  <110p2v
^$1           :>_v#`g00>
<#v_&10g20gp1-10g1+:10pv
   v:*::p029p011p00:&   

Try it online!

Input: n, followed by the elements of the array, all separated by spaces. NOTE: you may need to use a different interpreter if you have a large enough input.

I'm sure there's a better way to do this, I just wanted to try this in Befunge. The actual code portion is the top half.

How?

The code is divided into two main sections, the initialization and the verification.

Initialization:

   &:00p110p920p::*:v   
vp01:+1g01-1pg02g01&_v#<
>00g`#v_>:           1$^

This section of the code writes the input matrix right below the code as ASCII characters. Both this and the next section use the three cells at the top left of the code as data. They are stored as n, i, j.

Verification:

                     v 
                     1
v2p011<  v:g00p029p01< @
>0g1+20p^>*:#v_1# .#<@ .
v+1g00gg02g01<$ >1+10pv0
>:10g-\88++20g -g-     |
vg02p011_v#`g00g01-1  <1
>1+20p   >:   ^ ^      <

This sections checks every index i,j [1-indexed] against the condition Ai,j=An+1i,n+1j. However, we have a problem: we have j offset by 8. To fix that, the following formulae are used:

i=(n+1)i

j=n+1(j8)+8=(n+1)+(8+8)j

The other portions of code are unread garbage to make it centrosymmetric.

Zacharý
fuente
15

Haskell, n=8

No comments!

Takes input as a 1-D list

s a b=  
    a/=b
f =s<*> 
 reverse
esrever 
 >*<s= f
b=/a     
  =b a s

Try it online!

n=10

Takes input as a 2-D matrix

r =reverse
s a b=a/=b
f   =s<*>r
c  =concat
g =  f<$>c
c>$<f  = g
tacnoc=  c
r>*<s=   f
b=/a=b a s
esrever= r

Try it online!

Thanks to potato44 for all their help in chat. And Lynn for golfing off a row.

Explanation

The general idea here is a simple one, we concat the list and compare it to it's reverse. However since we want to be centrosymmetric we have to tread carefully. First we write the code as we would normally:

g=((==)<*>reverse).concat

Now in order for our reverse lines to also be valid Haskell we need the left hand side of our equations to look like a function definition tacnoc.)esrever>*<)==(( doesn't.

The first step to fixing this is disposing of parentheses.

s a b=a==b
f=s<*>reverse
g=f.concat

However we have some new problems now. Both . and == when reversed are the same, so our reversed lines attempt to redefine the operators (<*> reversed is >*< so we are fine on that front). . can be replaced with <$> since functions are functors. And we can replace == with /=, which negates our output, but that is still within the specs. Now we have

s a b=a/=b
f=s<*>reverse
g=f<$>concat

In order to trim down our line length we alias concat and reverse.

r=reverse
s a b=a/=b
f=s<*>r
c=concat
g=f<$>c

Now we just finish this by making everything centrosymmetric and square.

The shorter 1-D version works in much the same way except since there is no need to concat we can save two lines by removing it.

Wheat Wizard
fuente
How about this for n=10?
Lynn
@Lynn Thanks! In my head the reverse of <$> was also <$>.
Wheat Wizard
9

Python 2, size 10 (109 bytes)

def f(a):#
 return(a#
==[r[::-1#
]for r in#
a[::-1]])#
#)]]1-::[a
#ni r rof]
#1-::[r[==
#a(nruter 
#:)a(f fed

Try it online!

Previous Python 2, size 14 (209 bytes)

lambda a:all(#
a[i][j]==a[-i#
-1][-j-1]for #
i in range(  #
len(a))for j #
in range(len(#
a)))         #
#         )))a
#(nel(egnar ni
# j rof))a(nel
#  (egnar ni i
# rof]1-j-[]1-
#i-[a==]j[]i[a
#(lla:a adbmal

Try it online!

Chas Brown
fuente
1
Not sure if it would be enough for a rearrangement but FYI -i-1 and -j-1 could simply be ~i and ~j
Mr. Xcoder
@Mr. Xcoder: I fiddled with that a bit, but it doesn't change the outcome.
Chas Brown
Works in python3.6 too, but might not be optimal.
SIGSTACKFAULT
8

Pyth, size 6 (41 bytes)

q_M_QQ
q.q   


   q.q
QQ_M_q

Try it here

Explanation

The first line reverses the input and each row, and checks if we're left with a copy of the input.
The .q in the second line exits the program, so everything after that, as well as the q before it, is a no-op.


fuente
8

APL (Dyalog Unicode), score 7 6 5 4

Full program. Prompts for matrix expression from stdin. Prints a 1 or a 0 and then throws a consistent error. No comments!

r←,⎕
r≡⌽r
r⌽≡r
⎕,←r

Try it online!

 prompt for expression and evaluate it
, ravel (flatten) it
r← store the result in r (for ravelled)

⌽r mirror r
r≡ implicitly print whether r is identical to that

 depth of r (gives 1)
r⌽ use r to rotate that
 (this will always cause a RANK ERROR and quit because a matrix is not permitted as left argument to )

Adám
fuente
7

Perl 6, size 9 8 7

{.flat#
#}talf.
#  ],R[
eq # qe
[R,]  #
.flat}#
#talf.{

Try it online!

reverse is the bottleneck here. I've changed it to the technically longer, but much more splittable [*-1 X-^*]. Okay, I've changed it to [R,] after seeing Brad Gilbert's answer to another question.

The flattened code is {.flat eq [R,] .flat}.

Edit: Damn, I've realised I don't even need to flatten the first list, but attempts at shortening it to a size 6 have failed with just one byte too many to fit...

{@_#}_@
eq#<<|
[R,] #
# ],R[
|<<#qe
@_}#_@{

:(

Though if we take it as a one dimensional array, it's easy to fit it in a size 6.

{$_# }
eq #_$
[R,] #
# ],R[
$_# qe
} #_${

Try it online!

Jo King
fuente
6

Wolfram Language (Mathematica) (REPL only), size 8 (71 bytes)

f=#[[c=-
1;;1;;-1
,c]]==#&
(*      
      *(
&#==]]c,
1-;;1;;1
-=c[[#=f

Returns True for centrosymmetric input, and False otherwise.

On Mathematica REPL, lines with syntax errors are ignored (with a thick red bar appearing on the side of the screen). Here, only the first three lines, f=#[[c=-1;;1;;-1,c]]==#&, are executed.

This code captures the function in the name f.

Sadly, the built-in PalindromeQ is too long.

JungHwan Min
fuente
6

Pyt, size 1

Try it online!

Checks if the input (in the form of concatenated rows) is a palindrome.

Lynn
fuente
._. well, this isn't centrosymmetric according to the challenge: n>=2, but nice job.
Zacharý
6
By my understanding the n2 is a constraint on the input, not on the definition of a centrosymmetric matrix.
Lynn
Whoops, forgot that.
Zacharý
5

Japt, size 9 4 (11 bytes)

UªSê


êSªU

Try it online!

Takes one-dimensional input, checks if it is a palindrome. If you want, you can fill the two empty lines for some ascii art.
The old two-dimensional version, rotates the input twice and checks if it's equal to the original:

W=U  I
Wz2;II
Vc)eUc
cUe)cV
II;2zW
I  U=W

Try it online!

Nit
fuente
1
Nice! I think I have a 6 and I'm trying to beat an uncooperative 4 into submission too, but they're both much more trivial than this.
Shaggy
@Shaggy I managed to get the same solution down to six after giving it a fresh look, four would be very impressive.
Nit
Given that input can (now) be a 1 dimensional array, this can be done with a score of 2.
Shaggy
@Shaggy I'm not sure if I see how, the source must be NxN.
Nit
like so
Shaggy
4

Husk, size 3

Ṡ=↔
=↔=
↔=Ṡ

Try it online! Input as 1D-List. Each line defines a function, but only the one on the first line is called.

Ṡ=↔ is a palindrome tests which checks whether the input equals (=) its reverse ().


Husk, size 4

Ṡ=↔Σ
Σ↔=Ṡ
Ṡ=↔Σ
Σ↔=Ṡ

Try it online! For input as 2D-matrix, we concatenate (Σ) the list of lists before checking that it is a palindrome.

Laikoni
fuente
3

MATL, score 4

t,!P
]=%?
?%=]
P!,t

Input has the format [1 2; 2 1], using ; as row separator.

Output is via STDERR (allowed by default):

  • For centrosymmetric input a consistent error error is produced. With the current Linux and Octave versions in TIO the following STDERR output is produced (disregarding the final lines that start with Real time: ...):

    octave: X11 DISPLAY environment variable not set
    octave: disabling GUI features
    Python 2.7.15 (default, May 16 2018, 17:50:09) 
    [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> >>> /usr/include/c++/8/bits/basic_string.h:1048: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]: Assertion '__pos <= size()' failed.
    panic: Aborted -- stopping myself...
    

    The error may be different depending on the Linux and Octave versions, but will be consistent across inputs.

  • For non-centrosymmetric input no error is produced, and the STDERR output on TIO is

    octave: X11 DISPLAY environment variable not set
    octave: disabling GUI features
    Python 2.7.15 (default, May 16 2018, 17:50:09) 
    [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> >>> 
    

Try it online! Or verify all test cases:

  • Centrosymmetric: 1, 2, 3, 4, 5, 6.
  • Non-centrosymmetric: 1, 2, 3, 4, 5, 6.

Check that the program is centrosymmetric.

Explanation

% is the comment symbol, which causes the rest of the line o be ignored. Newlines are also ignored. So the code is just

t,!P]=?P!,t

which does the following:

t       % Input, implicit. Duplicate
,       % Do twice
  !     %   Transpose
  P     %   Flip vertically
]       % End
=       % Compare element-wise
?       % If all comparisons gave true
  P     %   Implicit input. Transpose. Actually, since there is no more input, an
        %   error is prand the program exits. The rest of the code is not executed, 
        %   and will be described in parentheses
  !     %   (Transpose)
  ,     %   (Do twice)
    t   %     (Duplicate)
        %   (End, implicit)
        % (End, implicit)
Luis Mendo
fuente
3

Haskell, size 11, 10, 9, 8

Takes the input as a 2D list! (Credit to Ørjan Johansen)

r= --r}-
 reverse
(==)<*> 
 r.map{-
-{pam.r 
 >*<)==(
esrever 
-}r-- =r
Program man
fuente
Bugs: Second <*> should be >*<. In the 2D one, there's a missing - and the reversed part doesn't have the spaces in the right places.
Ørjan Johansen
Got the 2D one down to 8
Ørjan Johansen
2

Python 2, size 8

i=input#
a=i()###
a[::-1##
]!=a<_##
##_<a=!]
##1-::[a
###)(i=a
#tupni=i

Try it online!

Takes input as a 1D list of concatenated rows (of length n2) and outputs via exit code (0 for symmetric inputs, 1 otherwise).

The list is simply checked to be a palindrome. If it is, the comparison chain a[::-1]!=a<_ fails at the != step and short-circuits; otherwise the unknown variable _ gets evaluated, crashing the program.

Lynn
fuente
2

R, size 9

   #)x-))
#(nacs-<x
#(ver(yna
#       #
#       #
#       #
any(rev(#
x<-scan(#
))-x)#   

Try it online!

The last three lines are the actual program that takes a 1D array as input and checks if it's equal to its reverse. Truthy value: FALSE, Falsy value: TRUE.

any(rev(x<-scan())-x)

R + pryr, size 9

pryr::f(#
any(rev(#
x)-x))#  



  #))x-)x
#(ver(yna
#(f::ryrp

Try it online!

JayCe
fuente
2

C# (.NET Core), score 13 11 10

l=>a=>a.//
Where((e//
,i)=>e!=//
a[l-i-1]//
).Any()///
///()ynA.)
//]1-i-l[a
//=!e>=)i,
//e((erehW
//.a>=a>=l

Try it online!

Takes input as 1D array and n2 as length; returns false for centrosymmetric and true for non-centrosymmetric. This version uses System.Linq but I don't know how to fit it in the code submission due to the particular requirements of the challenge. Unrolled code:

l => a => a.Where((e,i) => e != a[l-i-1]).Any()

Following is my previous submission that does not use LINQ:

C# (.NET Core), score 16 15 13

l=>a=>{/////*
var r=1<2;for
(int i=0;i<l;
)r&=a[i]==a[l
-i++-1];
return r;}
     /*/
   };r nruter
     ;]1-++i-
l[a==]i[a=&r)
;l<i;0=i tni(
rof;2<1=r rav
*/////{>=a>=l

Try it online!

Unrolled code:

l => a =>
{
    var r = 1<2;
    for (int i = 0; i < l;)
        r &= a[i] == a[l-i++-1];
    return r;
}
Charlie
fuente
If you change int to var (thus also tni to rav), the second submission also works in JavaScript.
Zacharý
2

Ruby, score 9 8

->z{z==#
z.######
reverse#
}#######
#######}
#esrever
######.z
#==z{z>-

Try it online!

A lambda taking a flattened matrix as input. Returns true for centrosymmetric, false otherwise.

-1 thanks to Mr.XCoder,

Unpacked:

->z{
  z == z.reverse
}
benj2240
fuente
2

Clean, size 9

Thanks to Ørjan Johansen!

import //
 StdEnv//
r=reverse
?m=m==r//
    m    
//r==m=m?
esrever=r
//vnEdtS 
// tropmi

Try it online!

Clean, size 10

import/*//
*/StdEnv//
r =reverse
?m      //
 =m==r m//
//m r==m= 
//      m?
esrever= r
//vnEdtS/*
//*/tropmi

Try it online!

Οurous
fuente
1
It's not because of newline, it works with indent. 9 lines
Ørjan Johansen
@ØrjanJohansen Can't believe I forgot you could indent them. Thanks!
Οurous
You're welcome, and I edited the middle line after I posted, it just needs to be m.
Ørjan Johansen
@ØrjanJohansen I've updated the answer to reflect that. It looks really elegant that way as well.
Οurous
2

05AB1E, size 3 (11 bytes)

ÂQq

qQÂ

Input as a single list.
Try it online.

I guess this one doesn't count.. ;p

ÂQ
qâ

Input as a single list.
Try it online.

Explanation:

         # Bifurcate this list (short for DR: Duplicate & Reverse copy)
 Q        # Check if the input-list and the reversed list are equal
  q       # Terminate the program
   qQâ    # No-ops

Some size 3 (11 bytes) alternatives:

R€R
QqQ
R€R

Matrix as input.
Try it online.

RQ 
 q  
 QR

Single list as input.
Try it online.

Kevin Cruijssen
fuente
1

C (gcc), 12 x 12

C(e,n,t,r)//
int*e;{for//
(r=t=0;e[t//
];r|=e[t]^//
e[~t+++n])//
;n=!!!!r;}//
//};r!!!!=n;
//)]n+++t~[e
//^]t[e=|r;]
//t[e;0=t=r(
//rof{;e*tni
//)r,t,n,e(C

Try it online!

Jonathan Frech
fuente
1

><>, Size 6

!/l2(\
s\?\ ?
/{=/ ;
: /={/
? \?\s
\(2l/!

Try it online!

(It turns out it's a pain passing multiple value to -v in tio)

Input is taken as a one dimensional array as the initial stack state with -v. Exits with no output if the matrix is centrosymmetric, exits with an error (prints "Something smells fishy...") if not.

l2(    Checks if the length of the stack is less than 2
?;     Exits cleanly if so

{=     Checks if the first and last elements are equal
?\s    Causes an error ('s' is not a valid instruction) if not

I wasn't entirely happy with this output format, so here's a size 7 one which outputs 1 for true, and 0 for false.

!/l2(\\
 ?   ?0
 =;n1/n
;{   {;
n/1n;= 
0?   ? 
\\(2l/!

Try it online!

Sasha
fuente
Nice job! ><> can be a fun language to work with, unless it's a complex program, then it's a pain.
mbomb007
1
if you swap the truthy and falsey values you can get it down to 4 with {-?;
Jo King
1

Stax, n = 3

$cr
=q=
rc$

Run and debug it

Explanation:

$cr =q= rc$ Full program, implicit input
$           Flatten
 cr         Copy and reverse
    =       Compare to original
     q      Print result
      =     Silently error because there is only one item on stack
        rc$ Not executed

3 is the best possible because I need at least three commands: Copy, reverse, and compare

Stax, n = 4

Mrxr
M=qX
Xq=M
rxrM

Run and debug it

Explanation:

Mrxr M=qX Xq=M rxrM Full program, implicit input
Mr                  Transpose and reverse
  x                 Push input again
   r M              Reverse and transpose
      =             Compare
       qX Xq        Print result twice and save to X
            =       Silently error because there is only one item on stack
             M rxrM Not executed
wastl
fuente
1

Java 10, size 13 (181 bytes)

a->{var r///*
=1>0;for(int 
l=a.length,i=
0;i<l;)r&=a[i
]==a[l-++i]; 
return r;}   
     /*/     
   };r nruter
 ;]i++-l[a==]
i[a=&r);l<i;0
=i,htgnel.a=l
 tni(rof;0>1=
*///r rav{>-a

Try it online.

Inspired by @Charlie's C# answer.

Golfed explanation:

a->{var r=1>0;for(int l=a.length,i=0;i<l;)r&=a[i]==a[l-++i];return r;}

a->{                    //  Method with byte-array parameter and boolean return-type
  var r=1>0;            //  Result-boolean, starting at true
  for(int l=a.length,   //  The length of the input-array
      i=0;i<l;)         //  Loop `i` in the range [0, length)
    r&=                 //   Bitwise-AND the result-boolean with:
       a[i]             //    Whether the current item
           ==a[l-++i];  //    equals the opposite item
  return r;}            //  Return the result
Kevin Cruijssen
fuente
1

C (gcc), score 11

Takes a list of int and n as arguments. Returns n as truthy value, 0 as falsy.

/*//};n=l;k
--*==++l*=*
n);l>k;n*n+
l=k(rof{;l*
tni)n,l(f;k
*/*/////*/*
k;f(l,n)int
*l;{for(k=l
+n*n;k>l;)n
*=*l++==*--
k;l=n;}//*/

Try it online!

gastropner
fuente
0

Javascript ES6, size 8:

/***/a=>
""+a==a.
reverse(
)/////*/
/*/////)
(esrever
.a==a+""
>=a/***/

Javascript ES6, size 7 (is it valid?):

a=>""+a
==a.//=
reverse
`     `
esrever
=//.a==
a+"">=a

Test:

<script>
f=

a=>""+a
==a.//=
reverse
`     `
esrever
=//.a==
a+"">=a
</script>

<script>
console.log([
  [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],
].every(f))

console.log([
  [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],
].every(x=>!f(x)))
</script>

or with lambda saved to variable named a:

a=

a=>""+a
==a.//=
reverse
`     `
esrever
=//.a==
a+"">=a

console.log([
  [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],
].every(a))

console.log([
  [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],
].every(x=>!a(x)))

Qwertiy
fuente
0

Clojure, Size 9

#(= %(;;;
reverse;;
(map;;;;;
reverse;;
%)));)))%
;;esrever
;;;;;pam(
;;esrever
;;;(% =(#

Try it online!

Lispy Louie
fuente