New answers tagged

2

Google Sheets, 90 88 Closing parens discounted. Input matrix starts at A2: A1: =COUNTA(2:2), gets number of columns (assume square) A2: =SUM(ArrayFormula(OFFSET(A2,,,A1,A1)+TRANSPOSE(ArrayFormula(OFFSET(A2,,,A1,A1))))) That was fun! How it Works: Add the matrix to its negative transpose. If the resulting matrix is all 0's, then the sum of all elements is 0,...


1

Java (JDK), 89 bytes m->{for(int i=0;++i<m.length;)for(int j=0;++j<i;)if(m[i][j]!=-m[j][i])return 0;return 1;} Try it online! I cheated a bit by returning 0 for false and 1 for true instead of the actual boolean/Boolean values.


0

Google Sheets, 47 Closing parens/quotes already discounted. Input: A1 A2 to A3: =ArrayFormula(LEN(SPLIT(A1," "))) =A2=COUNTIF(2:2,A2)


0

Haskell, 49 bytes import Data.List f x=x==transpose(map(map(0-))x) Try it online! My first Haskell. Function tacking a matrix and checking if input is equal to input mapped to (0-value) and transposed


0

Burlesque, 7 bytes ln)L[sm Try it online! Requires a trailing newline after the input. Technically the trailing newline is only needed if the input ends on a newline (as ln ignores one trailing newline), and it doesn't make a difference whether it's there or not otherwise, but stating it as a blanket requirement is probably preferable. Returns 1 for square ...


3

Julia 1.0, 9 bytes A->A==-A' A straightforward anonymous function checking the equality. Try it online!


2

Scala, 32 bytes l=>l.transpose==l.map(_.map(-1*)) Finally, something that Scala has a builtin for! The function's pretty straightforward - it compares the transpose of a List[List[Int]](doesn't have to be a List, could be any Iterable) to the negative, found by mapping each list inside l and using - to make it negative. Try it in Scastie


3

Wolfram Mathematica, 20, 7 bytes There is a built-in function for this task: AntisymmetricMatrixQ But one can simply write a script with less byte counts: #==-#ᵀ& The ᵀ character, as it is displayed in notebooks, stands for transpose. But if you copy this into tio, it won't be recognized because these characters are only supported by Mathematica ...


2

Google Sheets, 171 167 163 Input is in A1. =-IFERROR(JOIN(,ArrayFormula(MID(A1,SEQUENCE(LEN(A1),1,LEN(A1),-1),1)))=""&A1,1)&"&)1,1A&""=)))1,)1-,)1A(NEL,1,)1A(NEL(ECNEUQES,1A(DIM(alumroFyarrA,(NIOJ(RORREFI-= Palindrome: -1&)1A&"=)))1,)1-,)1A(NEL,1,)1A(NEL(ECNEUQES,1A(DIM(alumroFyarrA,(NIOJ(RORREFI-= Not: ...


1

gorbitsa-ROM, 8 bytes r1 R A1 B0 T This is an awful abuse of rule Input and output can assume whatever forms are most convenient. If input takes form of "arr[i][j] arr[j][i]", the problem becomes "is sum = 0?". This code takes pairs of values and outputs their sum if it's not 0 Thus if you provide matrix as previously mentioned pairs, ...


3

Charcoal, 10 bytes ⁼θEθE豧λκ Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - if the matrix is antisymmetric, nothing if not. Explanation: Eθ Map over input matrix rows (should be columns, but it's square) Eθ Map over input matrix rows §λκ Cell of transpose ± Negated ⁼θ Does ...


5

JavaScript (ES6), 42 bytes Returns false for antisymmetric or true for non-antisymmetric. m=>m.some((r,y)=>r.some((v,x)=>m[x][y]+v)) Try it online!


9

R, 23 bytes function(m)!any(m+t(m)) Try it online! Checks whether there are any non-zero elements in \$M+M^T\$.


0

SnakeEx, 38 bytes h:{c<B>1}{c<L>1}{e<>}{e<R>} c:.+$ e:.$ A match is truthy; no match is falsey. Try it here The previous 50-byte SnakeEx submission was copied from the original solution to the detect-square-inputs problem in the 2D pattern-matching language challenge. Here's the thing: that problem says, "Match the entire input ...


7

C (gcc), 67 64 bytes -3 thanks to AZTECCO i,j;f(m,s)int**m;{for(i=j=0;i=i?:s--;)j|=m[s][--i]+m[i][s];m=j;} Try it online! Returns 0 if the matrix is antisymmetric, and a nonzero value otherewise.


1

Ruby, 40 bytes ->a{a==a.transpose.map{|r|r.map{|c|-c}}} Try it online!


5

Brachylog, 5 bytes 5 bytes seems to be the right length for this (unless you're Jelly). Actually, this would be three bytes if Brachylog implicitly vectorized predicates like negation. \ṅᵐ²? Try it online! Explanation \ Transpose ṅᵐ² Map negation at depth 2 ? Assert that the result is the same as the input


1

Pip, 5 bytes Z_=-_ A function submission; pass a nested list as its argument. Try it online! Explanation Z_ The argument, zipped together = Equals -_ The argument, negated


4

Pyth, 5 bytes qC_MM Try it online! Explanation qC_MM q : Check if input equals C : Transpose of _MM : Negated input


6

Octave, 19 bytes @(a)isequal(a',-a); Try it online! The semicolon doesn't need to be there, but it outputs the function otherwise, so I'll take the one-byte hit to my score for now. Explanation It's pretty straightforward - it checks to see if the matrix of the transpose is equal to the negative matrix


3

MATL, 5 bytes !_GX= Try it online! Explanation !_GX= // Implicit input on top of stack ! // Replace top stack element with its transpose _ // Replace top stack element with its negative G // Push input onto stack X= // Check for equality


2

Japt, 5 bytes eUy®n Try it e compare input with : Uy columns of input ®n with each element negated Previous version ÕeËËn didn't work, corrected using the ® symbol


10

Python 2, 45 bytes lambda A:A==[[-x for x in R]for R in zip(*A)] Try it online!


4

Io, 69 bytes method(x,x map(i,v,v map(I,V,V+x at(I)at(i)))flatten unique==list(0)) Try it online! Explanation For all a[x][y], it checks whether all a[x][y]+a[y][x]==0. method(x, // Input x. x map(i,v, // Map all x's rows (index i): v map(I,V, // Foreach the ...


13

APL (Dyalog Unicode), 3 bytes -≡⍉ Try it online! This is exactly an APLcart entry on "antisymmetric". Basically it checks if the input's negative - matches ≡ the input's transpose ⍉.


4

Jelly, 3 bytes Z⁼N Try it online! Explanation Z Transposition ⁼ Equals N Negative


4

05AB1E (legacy), 3 bytes ø(Q Try it online! Explanation ø The input transposed, ( Negated, Q Is equal to the orginal input


0

Rust, 44 bytes |a|a.iter().map(|n|(n&1)*2-1).sum::<i8>()==0 Try it online Argument type is a: Vec<i8>. .iter() and ::<i8> add 13 bytes to the solution which hurts the score quite a bit, but the compiler can't infer the <i8> unfortunately. If this closure accepted an iterator instead of a Vec<i8> (for example std::slice::...


0

Scala, 20 bytes a=>(a:\0)(_%2*2-1+_) Try it online! Outputs 0 if there as many odd numbers as even numbers, a negative number if there are more even numbers, and a positive number if there are more odd numbers. Previous solution, 33 bytes a=>a.count(_%2>0)==a.count(_%2<1) Pretty straightforward solution. Just checks if the number of odd ...


2

MATL, 6 5 bytes -1 bytes thanks to @LuisMendo oEqs~ Try it online! Explanation oEqs~ o % Replace each elements with its parity (i.e. mod 2) E % Multiply all element by 2 q % Decrement all elements by 1 s % Sum the array ~ % Boolean not the sum


1

Charcoal, 94 bytes WS⊞υι≔⪫υ¶ηPη…η⌕ηX≔⟦⟧υF⁴«≔⟦⟧ζW¬№ζ⟦ⅈⅉι⟧«⊞ζ⟦ⅈⅉι⟧M✳⊗ι≡KKO⊞υLζ\≦⁻³ι/≔﹪⁻⁵ι⁴ι¿№+|-KK≔﹪⁺²ι⁴ι»»⎚FυP=№υN Try it online! Link is to verbose version of code. Takes input as the course and power level separated by a blank line, and outputs - for correct power level, = for incorrect power level, and nothing for an impossible course. Explanation: WS⊞υι ...


1

Scala, 332 317 bytes (l:Int,s:List[String])=>{def h(d:Int,c:(Int,Int),p:Int,r:Set[Any]):Int={val x=(c._1+(d-2)%2,c._2+(d-1)%2) val a=s(x._2)(x._1) if(a==79)if(p==1)1 else math.max(0,h(d,x,p-1,r+(c->d)))else if(r(x->d))-1 else h(d^(4-5*a%26%5),x,p-1,r+(c->d))} 0 to 3 map(h(_,s.map(_ indexOf'X').zipWithIndex.find(_._1>=0)get,l,Set()))max} I ...


1

Python 3, 384 378 bytes def l(d,r,m,i,c,p): m+=[[d]+p];p[1]+=(d-1)*(~d%2);p[0]-=(d-2)*(d&1);s=r"/\-|+OX ".index(c[p[1]][p[0]]) if s<2:d+=(s^d&1)*2+1;d%=4 if 1<s<5:d+=2;d%=4 if s==5:r+=[i] if [d]+p in m:return r return l(d,r,m,i+1,c,p) def f(c,v): i=c.index("X");i2=c.index("\n");p=[i%(i2+1),i//i2];c=c....


4

JavaScript (Node.js),  170 ... 147  145 bytes Expects (n)(a), where n is an integer and a is an array of strings. Returns 3 for truthy, 0 for falsy or 1 for mediumy. n=>a=>(g=(d,y=a.findIndex(r=>~(x=r.search`X`),j=n))=>+(a+a+1)[~j]?D&&g(--D):!(k=Buffer(a[y+=(d-2)%2])[x+=~-d%2]*5%26%5)*-~!--j|g(d^4-k&3,y))(D=3) Try it online! How? We ...


5

APL (Dyalog Unicode), 146 115 bytes {(∨/+⍺⊃⊢)∨⌿↑{'O'=1↓⊃¨⊢∘(((⊢,⍉∘⊖∘⌽¨)1⌽¨⊂,⊂∘⍉)⊃⍨1⌈¯2+'X O\/'⍳⊃)\(4×≢,⍵)⍴⊂⍵}¨({¯1+⊃⊃⍸'X'=⍵}⌽⍉)⍣2¨(⊢,⌽∘⊖¨)(⊂,⊂∘⍉)⍵,⍳≢⍵} -31 bytes (!) thanks to @Bubbler (combining transformations; simplifying iteration end condition; smaller details) Try it online! Outputs 2 for truthy, 1 for mediumy, and 0 for falsy. Similarly to my ...


0

Pip -r, 26 bytes $&ZgM{0Na<2>AB:y-#y*Ya@?0} Takes the snake from stdin and outputs 0 for invalid or 1 for valid. Try it online! Explanation This was fun. I went through several different versions, finally ending up with a solution that abuses the y variable delightfully and also shows off Pip's chaining comparison operators. $&ZgM{0Na<2>...


0

Scala, 46 bytes (a,b)=>(a&b).toBinaryString matches "1+0+1+0*" Online demo


5

APL (Dyalog), 457 441 bytes (Classic Dyalog Character Set) r←'RULD' S←{(r⍳⍵)⌷4 4⍴2 3 4 1 4 3 1 2 4,(⍳3),3 4 2 1} C←{(⊂⍺)⌷⍵} P←,⍉0 1 2 3∘.{2 4 1 3(C⍨⍣⍺)⍵}(⊂⍳4),C\S¨'LUULU' v←6 6⍴(3⍴0),2(⊥⍣¯1)4512674568 a←1 4 4 N←{s y x←⍵+0,(r⍳⍺)⌷4 2⍴0 1 ¯1 0 0 ¯1 1 0 t Y X←⊃(1+(7<y+x)(0<y-x))⌷2 2⍴('U'5 0)('L'0 5)('R'0 ¯5)('D'¯5 0) ⊃(1+(1+y x)⌷(¯2⊖¯2⌽8 8↑4 4⍴1)∨¯1⊖¯1⌽8 8↑...


1

Perl 5 -apl -MList::Util=sum,all, 28 bytes $_=all{"@F"-sum/./g,$_}1..$_ Try it online!


2

Scala, 44 bytes x=>0 to x forall(n=>x!=(n/:(""+n))(_+_-48)) Note: /: is deprecated since 2.13.0, and foldLeft is recommended Try it online


1

Jelly,  54  51 bytes 2×þ5o6R¤ “EḶ¤ẊƓW4mð,’b6ṣ5ịþ¢Ẏṙ€Ƭ1Ẏ;U$e@ ṢṖ’Ḍe“!ṛ‘ȯÇ A dyadic Link accepting a list of integers (each greater than two) which yields 1 if that list is a vertex figure which represents a uniform polyhedron, or 0 otherwise. Try it online! Or see the test-suite. How? First, check if the input is any rotation or reflection of either 4,4,N or ...


2

APL (Dyalog Unicode), 36 27 bytes 1∊=/¯1 0 1∘.(⊥-2|⊣×⊥)⍸⍉⍎¨↑⎕ Try it online! -9 bytes mostly from @Bubbler Full program that returns 0 or 1. Takes input as an array of strings, where each character is 0 for . or 1 for #. How? Uses the same general strategy as Martin Ender's CJam Answer. The two diagonals are indexed as y+(-1)*x and y+1*x, both rounded up ...


1

05AB1E, 68 61 bytes Ž‚ÃS2äI{¨.å•3É≠ÞÌδ)Ö“JhG•твŽ6ð9ǝ11Ž ¤š«.¥Ƶ_+ε5L._Dí«}˜€S>I.å~ Input as a list of integers. Try it online or verify all test cases. Explanation: Hard-coded approach. Step 1: Check if the input is of the type 3.3.3.N or 4.4.N: Ž‚à # Push compressed integer 33344 S # Split it into a list of digits: [3,3,3,4,4] 2ä ...


1

05AB1E, 8 7 bytes (without XOR/XNOR bonus) &b0«ÔCн Outputs 1 for truthy and 0/2/4 for falsey (only 1 is truthy in 05AB1E, so this is allowed according to rule "Output may follow your language's conventions for Truthy and Falsey"). Try it online or verify all test cases. 8 bytes with XOR bonus: &x^2вO4Q Port of @JonathanAllan's Python 2 ...


2

APL (Dyalog Extended), 9 bytes 2=≢⊆⍨∧/⊤⎕ Try it online! How it works 2=≢⊆⍨∧/⊤⎕ ⍝ Full program; input = a vector of two numbers ⊤⎕ ⍝ Binary representation of two numbers ∧/ ⍝ Bitwise AND ⊆⍨ ⍝ Extract chunks of ones 2=≢ ⍝ Test if there are exactly two chunks


1

JavaScript (V8), 44 bytes (a,b)=>(a&b).toString(2).match(/^1+0+1+0*$/) Try it online! Takes input as two numbers, returns a binary string if they meet the JFor property, otherwise null (a,b)=>(~(a^b)&(a|b)).toString(2).match(/^1+0+1+0*$/) Try it online! The same function, but instead uses an XOR to get the binary string.


1

Javascript , 70 bytes (a,b,c,d)=>(~~((a+b)%10/5)==~~((c+d)%10/5)?(c-a)*(d-b):(d-a)*(c-b))>=0 Input: is 4 numbers representing two pairs in order. Output: true/false Try it online


1

Retina, 142 bytes $ ,$", ^`\G\d+, $& %L$`, $'$>` N^$`.+,(.+), $1 N` ^(3,(3,3(,(\d+|3,[3-5]))?|4,([3-5],)?4|5,3,5|(6|8|10),\6)|4,4,\d+|4,6,(6|8|10)|5,(5|6),\8),¶ Try it online! Link includes test cases. Explanation: $ ,$", Duplicate the list and suffix a comma to each copy. ^`\G\d+, $& Reverse the first copy of the list. %L$`, $'$>` ...


3

Python 3, 190 bytes def f(F):s="".join(hex(k)[2]for k in F);F[1:]in[[4,4],[3]*3]or{s,s[::-1]}&{*"555 333 366 388 3aa 466 566 468 46a 3434 3444 3454 3535 33333 33334 33335".split()}and max(F)<16or f(F[1:]+F[:1]) Try it online! Takes input as a list of integers representing the vertex figure. The function errors (RecursionError) if ...


Top 50 recent answers are included