g | x | w | all
Bytes Lang Time Link
038Charcoal220330T202147ZNeil
100Haskell220408T022542Zalephalp
059PARI/GP220330T154027Zalephalp
060J220403T123300Zovs
072K ngn/k220403T043903Zdoug
121Haskell220402T222551ZDLosc
080Python + NumPy220331T011947Zloopy wa
076R220330T132202ZGiuseppe
010Jelly220330T173313ZJonathan
111Python 3220330T151822Zovs
234Python3220330T143602ZAjax1234

Charcoal, 52 43 39 38 bytes

F⁺θ§θ⁰⊞υ⟦⟧UMθEι⊞O§υ⁺κμλ≦⮌υIE⌊θEθ⊟§υ⁺κμ

Try it online! Link is to verbose version of code. Outputs in Charcoal's default one-element-per-line format. Explanation:

F⁺θ§θ⁰⊞υ⟦⟧

Create a list of empty lists that will eventually hold the antidiagonals.

UMθEι⊞O§υ⁺κμλ

Extract the antidiagonals from the input. (This replaces each element in the array with the antidiagonal to which it belongs, but unfortunately I can't make use of this fact.)

≦⮌υ

Reverse the antidiagonals so that we can extract the elements in the original order using Pop().

IE⌊θEθ⊟§υ⁺κμ`

Transpose the array, but read the elements back from the antidiagonals. (If Charcoal had an equivalent of JavaScript's unshift() then I would be able to unshift directly from the transposed array's antidiagonals to recover the elements.)

Haskell, 100 bytes

-3 bytes thanks to Wheat Wizard.

t m=[[m!!(i-1-x+y)!!(j+x-y)|j<-[0..l m-1],let[x,y]=min(i+j)<$>[l$m!!0,l m]]|i<-[1..l$m!!0]]
l=length

Try it online!

An ugly port of my PARI/GP answer.


Curry (PAKCS), 101 bytes

-4 bytes thanks to Wheat Wizard.

t m=[[m!!(i-1-x+y)!!(j+x-y)|j<-[0..l m-1],let[x,y]=map(min$i+j)[l$m!!0,l m]]|i<-[1..l$m!!0]]
l=length

Try it online!

PARI/GP, 59 bytes

m->matrix(#m,#m~,i,j,m[i-d=min(l=i+j-1,#m)-min(l,#m~),j+d])

Attempt This Online!

Shift the \$n\$-th anti-diagonal to lower left by \$\min(n,w)-\min(n,h)\$, where \$w\$ and \$h\$ are the number of columns and rows of the matrix respectively.

J, 62 60 bytes

Quite messy. The logic is very similar to my Python answer. Porting the Jelly answer might be shorter.

[:|:*@#@,(({.,{:"1@}.)((}.~#),~({.~#),.])|:@$:@:(}:"1)@}.^:)

Try it online!

K (ngn/k), 154 74 72 bytes

{$[1=&/#'1*:\x;:+x;[r:,/(*x),1_-1#'x;(,(#x)#r),+(+o(1_-1_'x)),,(#x)_r]]}

Try it online!

Haskell, 132 121 bytes

-11 thanks to Wheat Wizard

t[h]=pure<$>h
t s@([x]:r)=[s>>=id]
t(h:r)|n<-t$init<$>r,(a,b)<-splitAt(length r)$h++(last<$>r)=zipWith(\i->(++[i]))b(a:n)

Try it online!

If the input list has only one row, or only one column, transpose it. Otherwise, recurse on the "nub" that results from removing the J-bracket; then split the J-bracket into two parts, put one part atop the nub, and append the other part itemwise to the right side of the nub.

It's still pretty long, so I'm guessing there's a better way to do this...

Python + NumPy, 80 bytes

def f(a):b=0*a.T;b[1:,:-1]=a.any()and f(a[1:,:-1]);b[b<1]=a[a>0];a[:]=0;return b

Attempt This Online!

Accepts and destroys (overwrites with zeros) a NumPy array. Relies on elements being positive as promised in OP.

R, 76 bytes

\(m)array(unsplit(split(m,i),rev(t(i<-pmin(row(m),rev(col(m)))))),dim(t(i)))

Attempt This Online!

As in the other challenge, splits the array to find the J-brackets. Then unsplits and adds array structure to get to the J-twin as a matrix.

Longer explanation to follow.

Jelly, 10 bytes

ZL_Lṙ@ŒdŒḍ

A monadic Link that accepts a rectangular list of lists and yields its J-bracket-twin as a list of lists.

Try it online! Or see the test-suite.

How?

ZL_Lṙ@ŒdŒḍ - Link: list of lists, A
Z          - transpose A
 L         - length of that -> columnCount(A)
   L       - length of A -> rowCount(A)
  _        - columnCount(A) subtract rowCount(A) = N
      Œd   - anti-diagonals of A
    ṙ@     - rotate this list of anti-diagonals left by N
        Œḍ - create a matrix with these anti-diagonals

Python 3, 111 bytes

def f(x):
 r,*a=x;k=len(a)
 if k*r[1:]:r+=map(list.pop,a);x=*zip(r[:k],*f(a)),r[k:]
 return[*map(list,zip(*x))]

Try it online!

Python3, 234 bytes:

E=enumerate
s=lambda m,d:(k for i,j in E(m)for x,k in E(j)if(i==d and x<(len(m[0])-d))or(i>d and x==(len(m[0])-1-d)))
r=lambda d,m:[[next(d[min(x,len(m)-1-y)])for y,_ in E(m)]for x,_ in E(m[0])]
lambda m:r({i:s(m,i)for i,_ in E(m)},m)

Try it online!