g | x | w | all
Bytes Lang Time Link
062JavaScript Node.js240825T233310Zl4m2
056Wolfram Language Mathematica201004T215558Zatt
012Uiua231105T235145ZBubbler
020Uiua 0.1.0231105T091339ZPseudo N
154Scala231104T053507Z138 Aspe
072Ruby231104T051943ZValue In
022K ngn/k231104T033845Zdoug
014J231103T155155ZJonah
6875Vyxal231103T144141Zpacman25
110Ruby161126T023521ZCary Swo
008Husk201004T050053ZRazetime
084R161124T104849ZBillywob
105JavaScript ES6 100 101161123T211859Zedc65
085Mathematica161123T235939Zuser6198
092Mathematica161123T230549ZGreg Mar
093Mathematica 93 Bytes161123T224837ZKelly Lo
096Python 2161123T210918ZKarl Nap
011Jelly161123T213011Zlynn
017MATL161123T204408ZLuis Men
116JavaScript ES6161123T205556ZNeil
01305AB1E161123T202554ZOliver N

JavaScript (Node.js), 62 bytes

x=>x.map(_=>x.map(g=_=>x[i=i?i-1:j++]*x[j+~i]?x[i]:g()),i=j=1)

Try it online!

Wolfram Language (Mathematica), 60 58 56 bytes

ListConvolve[#,Less/@#,All,,Pick,##&]~Partition~Tr[1^#]&

Try it online!

ListConvolve[ ,       ,   ,,    ,   ]                       convolve
                     #                                        list length of input
             #                                                with input as kernel
                       All                                    with maximum overhang
               Less/@       Pick                              by taking from kernel where overlap
                                 ##&                          flattened
                                     ~Partition~Tr[1^#]     reshape

All is not documented as a third argument to ListConvolve. It behaves like {1,-1}.

Uiua, 12 bytes

⊏⍜♭⍏⊞+.⊃⇡▽⧻.

Try it online!

⊏⍜♭⍏⊞+.⊃⇡▽⧻.   input: vector V of length N
               ⧻.    keep V and push N
           ⊃⇡▽     consume both and push [0..N-1], V cycled N times
       ⊞+.          self outer product of range by addition
 ⍜♭⍏              flatten, replace the array with its sorting order, and
                     put it back into the same sized matrix
⊏                   for each number in the matrix, select the item at that index
                    in "V cycled N times"

The above is a slightly golfuscated version of the code below:

Uiua, 14 bytes

⍜∩♭'⊏⍏⊞+.⍏.↯⧻.

Try it online!

⍜∩♭'⊏⍏⊞+.⍏.↯⧻.    input: a vector of integers of length N
               ↯⧻.     make the input a matrix by copying the input N times -> X
             ⍏         rise; sorting order of the rows (same as range N)
         ⊞+.           self outer product by addition -> Y
⍜∩♭          .        operate on X and Y flattened and assemble back..
    '⊏⍏                reorder elements of X by sorted order of elements of Y

Uiua (0.1.0), 20 bytes

↯~√⧻./⊐⊂≐(□↘)-⇡×2.⧻.

Try it online

Explanation

                  ⧻. # (nondestructively) get array length
             -⇡×2.   # construct a range from len down to -len + 1
        ≐(□↘)        # for each element of the range, drop that many from the array
     /⊐⊂             # join all resulting arrays together
  √⧻.                # get square root of length, suppose we call it N...
↯~                   # ...then this reshapes the array to MxN, where M is inferred

Scala, 154 bytes

Golfed version. Try it online!

a=>{val n=a.size;var L,M=List[Int]();for(i<-0 to n-1){L=L:::a.slice(0,i+1).reverse.toList;M=M:::a.slice(i+1,n).reverse.toList};(L::: M).grouped(n).toList}

Ungolfed version. Try it online!

object Main {
  def main(args: Array[String]): Unit = {
    val a = Array(1, 2, 3, 4, 5)
    val n = a.length
    var L, M = List.empty[Int]

    for (i <- 0 until n) {
      L = L ::: a.slice(0, i+1).reverse.toList
      M = M ::: a.slice(i+1, n).reverse.toList
    }

    val zipped = (L ::: M).grouped(n).toList

    println(zipped)
  }
}

Ruby, 72 bytes

->a,*r{t=[]
a.map{r+=t=[_1]+t}
r+=t while t.pop
[*r.each_slice(a.size)]}

Attempt This Online!

K (ngn/k), 22 bytes

{x@l!s#,/=+/!s:2#l:#x}

Try it online!

J, 14 bytes

#($$&;</.)@#,:

Attempt This Online!

Vyxal, 55 bitsv2, 6.875 bytes

LẋÞ`f?Lẇ

Try it Online!

Bitstring:

0110000101111000101000101100100011000011001101100100000
LẋÞ`f?Lẇ­⁡​‎⁠‏​⁢⁠⁡‌⁢​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌­
# ‎⁡implicit input
Lẋ        # ‎⁢repeated [length] times
  Þ`      # ‎⁣antidiagonals
    f?Lẇ  # ‎⁤flatten and wrap in chunks the size of the length
💎

Created with the help of Luminespire.

Ruby, 110 bytes

n=a.size
b=[*(0...n)]
b.product(b).group_by{|i,j|i+j}.flat_map{|_,f|f.sort.map{|i,j|a[i][j]}}.each_slice(n).to_a
      #=> [[1, 2, 1, 3, 2],
      #    [1, 4, 3, 2, 1],
      #    [5, 4, 3, 2, 1],
      #    [5, 4, 3, 2, 5],
      #    [4, 3, 5, 4, 5]]

The sort operation may not be required, but the doc for Enumerable#group_by does not guarantee the ordering of values in the hash values (which are arrays), but current versions of Ruby provide the ordering one would expect and the ordering I would need if sort were removed from my code.

The steps are as follows.

n=a.size 
  #=> 5 
b=[*(0...n)]
  #=> [0, 1, 2, 3, 4] 
c = b.product(b)
  #=> [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3],
  #    [1, 4], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 0], [3, 1], [3, 2],
  #    [3, 3], [3, 4], [4, 0], [4, 1], [4, 2], [4, 3], [4, 4]] 
d=c.group_by{|i,j|i+j}
  #=> {0=>[[0, 0]],
  #    1=>[[0, 1], [1, 0]],
  #    2=>[[0, 2], [1, 1], [2, 0]],
  #    3=>[[0, 3], [1, 2], [2, 1], [3, 0]],
  #    4=>[[0, 4], [1, 3], [2, 2], [3, 1], [4, 0]],
  #    5=>[[1, 4], [2, 3], [3, 2], [4, 1]],
  #    6=>[[2, 4], [3, 3], [4, 2]],
  #    7=>[[3, 4], [4, 3]],
  #    8=>[[4, 4]]} 
e=d.flat_map{|_,f|f.sort.map{|i,j|a[i][j]}}
  #=> [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 5, 4, 3, 5, 4, 5] 
f=e.each_slice(n)
  #=> #<Enumerator: [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2,
  #                  5, 4, 3, 5, 4, 5]:each_slice(5)>

Lastly, f.to_a returns the array shown earlier.

Husk, 9 8 bytes

CL¹Σ∂RL¹

Try it online!

-1 byte from Zgarb.

Explanation

CL¹Σ∂*L¹;
       ¹  input(appends a ¹ to the end)
        ; enclosed
     *L   repeated length times
    ∂     antidiagonals
   Σ      flattened into a single list
C         cut into pieces of size
 L¹       of the length of the input       

R, 84 bytes

t(matrix(unlist(split(m<-t(matrix(rev(x<-scan()),l<-sum(1|x),l)),row(m)-col(m))),l))

Reads input from stdin and outputs/returns an R-matrix.

reversed_x <- rev(x<-scan())                # Read input from stdin and reverse
m <- t(matrix(reversed_x,l<-sum(1|x),l))    # Repeat and fit into matrix
diag_list <- split(m,row(m)-col(m))         # Split into ragged list of diagonals
t(matrix(unlist(diag_list),l))              # Flatten and transform back to matrix

Explained

The most interesting aspect about this answer is how the diagonals are retrieved. In general an object can be split up using the split function if supplied an object containing factors upon which the object is split into. To create these factors we can use col and row which return a matrix containing the column and row indices respectively. By taking the differences: row(m)-col(m) we get a matrix like:

     [,1] [,2] [,3] [,4] [,5]
[1,]    0   -1   -2   -3   -4
[2,]    1    0   -1   -2   -3
[3,]    2    1    0   -1   -2
[4,]    3    2    1    0   -1
[5,]    4    3    2    1    0

in which each diagonal is uniquely identified. We can now split based on this matrix and turn it into a ragged list by applying split:

$`-4`
[1] 1
$`-3`
[1] 2 1 
$`-2`
[1] 3 2 1
$`-1`
[1] 4 3 2 1
$`0`
[1] 5 4 3 2 1
$`1`
[1] 5 4 3 2
$`2`
[1] 5 4 3
$`3`
[1] 5 4
$`4`
[1] 5

(Note how the name of each vector correspond to the diagonal values in the matrix above).

The last step is just to flatten and turn it into a matrix of the form:

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    1    3    2
[2,]    1    4    3    2    1
[3,]    5    4    3    2    1
[4,]    5    4    3    2    5
[5,]    4    3    5    4    5

JavaScript (ES6) 100 101 105

a=>eval("for(u=r=[],i=l=a.length;i+l;i--)for(j=l;j--;v&&((u%=l)||r.push(s=[]),s[u++]=v))v=a[j-i];r")

Less golfed

a => {
  u = 0
  for(r=[], i=l=a.length; i+l>0; i--)
    for(j=l; j--; )
    {
      v = a[j-i]
      if (v) 
      {
        u %= l
        if (u==0) r.push(s=[])
        s[u++] = v
      }
    }
  return r
}

Test

F=
a=>eval("for(u=r=[],i=l=a.length;i+l;i--)for(j=l;j--;v&&((u%=l)||r.push(s=[]),s[u++]=v))v=a[j-i];r")

function update() {
  var a=I.value.match(/\d+/g)
  if (a) {
    var r=F(a)
    O.textContent = r.join`\n`
  }
}

update()
<input id=I value='1 2 3 4 5' oninput='update()'>
<pre id=O></pre>

Mathematica, 85 bytes

Literally performing the steps suggested:

(l=Length@#;Partition[Flatten@Table[Reverse@Diagonal[Table[#,l],i],{i,-l+1,l-1}],l])&

My gut says that there should be a clever way to use Part to do this shorter, but every attempt I've made has been longer than 85 bytes.

Mathematica, 92 bytes

n=NestList[#2,(r=Reverse)@#,(l=Length@#)-1]&;{Most@r[#~n~Rest],#~n~Most}~ArrayReshape~{l,l}&

Unnamed function taking a list as its argument. There might be other structures to such a function, but hopefully I golfed this structure pretty good....

The first part n=NestList[#2,(r=Reverse)@#,(l=Length@#)-1]& defines a function n of two arguments: the first is a list of length l, and the second is a function to apply to lists. n applies that function l-1 times to the reversed argument list, saving all the results in its output list. (Defining r and l along the way is just golfing.)

n is called twice on the original list, once with the function being Rest (drop the first element of the list) and once with the function being Most (drop the last element). This produces all the desired sublists, but the whole list is there twice (hence the extra Most) and the first half is there in backwards order (hence the r[...]). Finally, ~ArrayReshape~{l,l} forgets the current list structure and forces it to be an lxl array.

Mathematica 93 Bytes

Partition[Flatten[Table[If[i>n,#[[n;;(i-n+1);;-1]],#[[i;;1;;-1]]],{i,1,2(n=Length@#)-1}]],n]&

Here's how I'd ordinarily write this code (109 Bytes):

Partition[Reverse@Flatten[Table[Reverse@Diagonal[ConstantArray[Reverse@#,n],k],{k,-(n=Length@#)+1,n-1}]],n]&

This matrix plot gives a good idea from the structure due to a sequentially increasing input vector.

enter image description here

Here's the matrix plot with a random input vector. Obviously some structure still exists.

enter image description here

Python 2, 105 96 bytes

-1 and -4 and -4 bytes thanks to Flp.Tkc

a=input()
n=len(a)
L,M=[],[]
for i in range(n):L+=a[i::-1];M+=a[:i:-1]
print zip(*[iter(L+M)]*n)

The for loop adds the items like in the description, the real magic happens in the zip which is from here

Jelly, 11 bytes

WẋLŒDUṙLFsL

Try it online!

Explanation

               Input: array z
WẋL            length(z) copies of z
   ŒD          Diagonals (starting with main diagonal)
     U         Reverse each
      ṙL       Rotate left length(z) places
               (now the top-left diagonal is in front)
        F      Flatten
         sL    Split into chunks of size length(z)

MATL, 17 bytes

!Gg*tRwZRhPXzGne!

Try it online!

How it works

The following explanation uses input [1 2 3 4 5] as an example. To visualize the intermediate results, insert % (comment symbol) after any statement in the code.

Note that ; is the row separator for matrices. So [1 2] is a row vector, [1; 2] is a column vector, and [1 0; 0 1] is the 2×2 identity matrix.

!     % Implicitly input a row vector. Transpose. Gives a column vector
      % STACK: [1; 2; 3; 4; 5]
Gg    % Push input with all (nonzero) values replaced by ones
      % STACK: [1; 2; 3; 4; 5], [1 1 1 1 1]
*     % Multiply, with broadcast. Gives a square matrix
      % STACK: [1 1 1 1 1;
                2 2 2 2 2;
                3 3 3 3 3;
                4 4 4 4 4;
                5 5 5 5 5]
tR    % Duplicate. Upper triangular part
      % STACK: [1 1 1 1 1;
                2 2 2 2 2;
                3 3 3 3 3;
                4 4 4 4 4;
                5 5 5 5 5],
               [1 1 1 1 1
                0 2 2 2 2;
                0 0 3 3 3;
                0 0 0 4 4;
                0 0 0 0 5]
wZR   % Swap. Lower triangular part, below main diagonal 
      % STACK: [1 1 1 1 1;
                0 2 2 2 2;
                0 0 3 3 3;
                0 0 0 4 4;
                0 0 0 0 5],
               [0 0 0 0 0;
                2 0 0 0 0;
                3 3 0 0 0;
                4 4 4 0 0;
                5 5 5 5 0]
h     % Concatenate horizontally
      % STACK: [1 1 1 1 1 0 0 0 0 0;
                0 2 2 2 2 2 0 0 0 0;
                0 0 3 3 3 3 3 0 0 0;
                0 0 0 4 4 4 4 4 0 0;
                0 0 0 0 5 5 5 5 5 0]
P     % Flip vertically
      % STACK: [0 0 0 0 5 5 5 5 5 0;
                0 0 0 4 4 4 4 4 0 0;
                0 0 3 3 3 3 3 0 0 0;
                0 2 2 2 2 2 0 0 0 0;
                1 1 1 1 1 0 0 0 0 0]
Xz    % Column vector of nonzeros, taken in column-major order
      % STACK: [1;2;1;3;2;1;4;3;2;1;5;4;3;2;1;5;4;3;2;5;4;3;5;4;5]
Gne   % Reshape into a matrix with as many rows as input size
      % STACK: [1 1 5 5 4;
                2 4 4 4 3;
                1 3 3 3 5;
                3 2 2 2 4;
                2 1 1 5 5]
 !    % Transpose. Implicitly display
      % STACK: [1 2 1 3 2;
                1 4 3 2 1;
                5 4 3 2 1;
                5 4 3 2 5;
                4 3 5 4 5]

JavaScript (ES6), 116 bytes

a=>a.map(_=>b.splice(0,a.length),b=[].concat(...a.map((_,i)=>a.slice(~i)),...a.map((_,i)=>a.slice(0,~i))).reverse())

Well, it's a start...

05AB1E, 13 bytes

.p¹.sR¦«í˜¹gä

Try it online!

Explanation:

                # Implicit input
 .p             # Get prefixes
   ¹            # Get first input
    .s          # Get suffixes
      R         # Reverse
       ¦        # Remove first element
        «       # Concatenate
         í      # Reverse every one
          ˜     # Flatten
           ¹gä  # Split into pieces of the length
                # Implicit print