12

Python 3 with numpy, 90 87 86 84 bytes from numpy import* lambda n:2*((4<<(a:=(y:=c_[1-n:n])-y.T)//4)+a%4-2&a-2*y)-1<<a<y%2 Takes \$\left\lceil \frac{n}{2}\right\rceil\$. -3 by removing x. -1 with a shorter expression for \$-x - y\$. -2 with a shorter combining method. How it works Broadcasting is used in several places to produce the ...


11

Japt v2.0a0, 2 bytes Transposes, sorts each row and automatically transposes back. yn Try it Japt, 3 bytes Transpose, sort rows, transpose. yÍy Try it


8

Haskell, 41 bytes import Data.List t=transpose t.map sort.t Try it online! This is the same boring answer you've already seen in this thread. Unfortunately it's quite short. Here's a fun answer that doesn't import anything: No imports, 53 49 bytes q=foldr.zipWith e=[]:e q(:)e.q([(0:),(++[1])]!!)e Try it online! This answer is a little odd. Explanation ...


6

Python 3, 34 bytes lambda a:zip(*map(sorted,zip(*a))) Try it online! -3 bytes thanks to pxeger


6

R, 26 bytes Or R>=4.1, 19 bytes by replacing the word function with \. function(m)apply(m,2,sort) Try it online!


6

APL (Dyalog Extended), 5 bytes ∧⍤1⍢⍉ Try it online! Sort ∧ each row ⍤1 while transposed ⍢⍉ APL (Dyalog Unicode), 9 bytes ⊖⍳∘≢∘.≤+⌿ Try it online! +⌿ sum of each column ⍳∘≢ indices from 1 to the number of rows ∘.≤ ≤-table between these two vectors ⊖ vertically reverse the resulting matrix


5

JavaScript, 99 bytes a=>a.map((r,y)=>r.map((c,x)=>((g=i=>i--&&((i%2|x+~y&i!=4)&a[~-(y+i/3)]?.[x+i%3-1])+g(i))(9)|c)==3)) f= a=>a.map((r,y)=>r.map((c,x)=>((g=i=>i--&&((i%2|x+~y&i!=4)&a[~-(y+i/3)]?.[x+i%3-1])+g(i))(9)|c)==3)) print = (a, contain) => { let t = contain.appendChild(document....


5

MATLAB / Octave, 13 bytes @(M)sort(M,1) Try it online! How it works Anonymous function that sorts along the 1st dimension, i.e. vertically.


5

C (clang), 80 79 74 bytes x,*u;f(*a,w,h){for(x=w*h*--h;x--;)w[u=a+x%h*w-x/h/~h]<*u?u[w]^=1,*u^=1:0;} Try it online! This is essentially a strided sort looped over all columns except instead of swapping out of order elements, both elements are xor'ed by one. Slightly less golfed x,*u; f(*a,w,h){ for(x=w*h*--h;x--;) w[u=a+x%h*w-x/h/~h]<*u? ...


4

Jelly, 9 bytes ZŒPZ€Ṁ€€i Try it online! Outputs 0 for falsey, non-zero for truthy -3 bytes thanks to hyper-neutrino! How it works ZŒPZ€Ṁ€€i - Main link. Takes a list of inputs I on the left and outputs O on the right Z - Transpose I ŒP - Powerset of the columns Z€ - Transpose each € - Over each column powerset: Ṁ€ - ...


4

Vyxal, 6 bytes ÞTvsÞT Try it Online! There's probably something cleverer / shorter. ÞT # Transpose vs # Sort each ÞT # Transpose


4

Jelly, 4 bytes ZṢ€Z Try it online! A monadic link which takes a 2d array of booleans. Z # Transpose € # For each Ṣ # Sort Z # Transpose back


3

JavaScript (ES6), 109 bytes a=>a.map((r,y)=>r.map((n,x)=>[...'0124689',10].map(i=>n+=x-~y&1|i&5&&(a[y+~-(i/4)]||0)[x+i%4-1]<<1)|n>4&n<8)) Try it online!


3

Raku, 21 bytes try it online! {[[xx] [xx] $_ xx 3]}


3

APL (Dyalog Classic), 50 bytes {⎕←1↑⍵⋄({(3↓⍵),⍨(+/2↑1⌽3↑⍵),1↑⍵}⍣{⎕←1↑⍺⋄(⍴⍺)<3})⍵} Try it online! Explanation: (+/2↑1⌽3↑⍵),1↑⍵ take the first three elements, rotate them, sum the first two and stick the third (which was originally the first element) on the end again so (a b c) -> (b c a) -> (b+c a) (3↓⍵),⍨ concatenate this with the rest of the ...


3

jq, 53 bytes [while(.[1];.[1]+=.[2]|(.[2]//.[0])=.[0]|.[1:])|.[0]] Try it online! Explanation: Based on example input: [1, 2, 3] [ while( While .[1] the array has at least two items ; .[1]+=.[2] add the second and third number and store them on second position. |(.[2]//.[0]) ...


3

jq, 20 bytes range(.*.)*(1+1/.)%. Try it online! output is flattened (my first jq answer)


3

Japt, 4 bytes ñÍè> Try it here ñÍè> :Implicit input of array ñ :Sort by Í : Subtracting from 2 è :Count the elements that are > : Greater than their 0-based indices


3

JavaScript (ES6), 53 bytes Suggested by @l4m2: counting the number of 1's on each column, using .filter(). Returns a matrix of Boolean values. m=>m.map((r,y)=>r.map((_,x)=>!m.filter(r=>!r[x])[y])) Try it online! JavaScript (ES6), 55 bytes Sorting the columns. m=>m.map((r,y)=>r.map((_,x)=>m.map(r=>r[x]).sort()[y])) Try it online! ...


3

Factor, 34 bytes [ flip [ natural-sort ] map flip ] Try it online! Transpose (flip), sort each row, transpose.


3

Python 3 + NumPy, 18 bytes lambda a:a.sort(0) Try it online! Input a np.array, output by modify it in-place.


2

Haskell, 72 59 bytes My C++ solution looked pretty verbose, and the recursive nature made me think of Haskell, so here's my attempt: a!i|i<foldr(\x s->s+fromEnum(i<x))0 a=a!(i+1)|1<2=i H a=a!0 Explanation: foldr (\x s -> s + fromEnum(i < x)) 0 a I'm sure there's a shorter way to do this, because I'm pretty new to haskell, but basically it ...


2

BQN, 39 bytesSBCS ↕∘≠⊸{⊏⟜𝕩¨2↑⊒⊸/⊸(+`⊑⊸=)⊸⊔0∾⊑˜⍟𝕨⟜⊑≠⊸|𝕨+𝕩} Try it here. ↕∘≠⊸{⊏⟜𝕩¨2↑⊒⊸/⊸(+`⊑⊸=)⊸⊔0∾⊑˜⍟𝕨⟜⊑≠⊸|𝕨+𝕩} # 𝕩 is input, 𝕨 is indices 0,1,..,length-1 ↕∘≠⊸{ } # pass indices into the main function as 𝕨 ≠⊸|𝕨+𝕩 # add indices to the input mod the length ⊑˜...


2

jq, 146 bytes length as$l|def x:((.[0]+.[1][-1])%$l+$l)%$l;def n:x as$x|.[1]|index($x);. as$i|[0,[],[]]|until(n;[$i[x],.[1]+[x],.[2]+[$i[x]]])|.[2][:n],.[2][n:] Try it online!


2

Brain-Flak, 112 bytes ((({})<>)<>){{}({}<(({})<>)<>>)({<({}[()]<({}[()])>)>()}{}<>)<>({}<<>({}<>)>)}{}((()()()()()){})<>{}{({}<>)<>}<> Try it online!


2

TI-Basic, 28 bytes Prompt N For(I,1,N Disp remainder(I+seq(J,J,1,N),N End Outputs each row as a list on a separate line. Note that remainder( only works for TI-84+/SE with the 2.53 MP OS. The below version uses 2 more bytes but is compatible with earlier OS's. 30 bytes Prompt N For(I,1,N Disp NfPart((I+seq(J,J,1,N))/N End


2

Python 3, 174 167 bytes bytes -7 bytes thanks to @wasif lambda l:[sum(l),eval('*'.join(map(str,l))),mean(l),median(l),[m-n for n,m in zip(l,l[1:])],sorted(l),min(l),max(l),stdev(l)] from math import* from statistics import* Try it online!


2

MATL, 35 33 32 31 bytes t1Y6Z+G5B&*Z+G&n:w:!+o~*+E+5:7m Try it online! Or verify all test cases. How it works t % Implicit input: binary matrix. Duplicate 1Y6 % Push [0 1 0; 1 0 1; 0 1 0]. This mask defines cells that are neighbours % of the central cell, whether the central cell is a square or an octagon Z+ % 2D convolution, ...


2

Charcoal, 44 bytes NθG↖→→↓↓θ¶XFθ«P↖⭆…⊕⁻ιθ⁻θι§ X¬&κ⁻X²⊕÷鲬﹪ι²←← Try it online! Link is to verbose version of code. Takes input as the 1-indexed distance from the centre. Explanation: Diagonal bit-twiddling shamelessly stolen from @m90's answer, because I can't work out what @Bubbler means regarding the antidiagonals. Nθ Input ⌈n/2⌉. G↖→→↓↓θ¶X Draw ...


2

BQN, 9 bytesSBCS -˜`⊑∾2↓+` Try it here. Based on Lynn's solution. -˜`⊑∾2↓+` 2↓+` # drop 2 elements from the plus scan ∾ # joined to ⊑ # first element of input -˜` # swapped subtraction scan


Only top voted, non community-wiki answers of a minimum length are eligible