ṙJṖ«/ argument: 1D array (z)
ṙ rotate z by each of the above amount (current array is 2D)
Ṗ remove the last array
«/ reduce by [impliclitly vectorized] minimum
Try it online!
Verify all of them at once! (slightly modified)
I'm pretty sure Dennis can out-golf this.
How it works
The algorithm is rather convoluted. Let us observe what this does to
Firstly, we use
J to obtain
[1,2,3,4]. Note that Jelly uses 1-indexing.
Then, we see
ṙ. It takes two arguments: an array and an integer. It rotates the array to the left by an amount specified by the integer. Here,
ṙ would see
[4,2,2,5] on its left and
[1,2,3,4] on its right (more about how this works can be found in the tutorial). In Jelly, commands implicitly vectorize. Therefore, this command will be performed over each individual element on the right, which is why we would create a 2D array:
[[4,2,2,5]ṙ1,[4,2,2,5]ṙ2,[4,2,2,5]ṙ3,[4,2,2,5]ṙ4], which becomes:
Notice that the original elements are on the last row, since in that row we rotated to the left by an amount equal to the length of the array, which is why we use
Ṗ next to remove that row, so that the columns are the collections of the elements of the array which are not at the current index:
The following operation,
«/, is also quite convoluted. Firstly,
« returns the minimum of the two numbers it sees on its left and on its right. For example,
3. Now, if the two arguments are arrays, then it would vectorize as I have said above. What this means it that
[1,5,2,3]«[4,1,5,2] would become
[1«4,5«1,2«5,3«2] which is
reduce, which means that we do the operation over each row until the end. For example,
[1,2,3,4]+/ would become
((1+2)+3)+4, which is the sum of the array
So, if we apply
«/ to the 2D array we just obtained, we would get:
which, because of the vectorization, would be equivalent to:
which computes the minimum of every array without the element at the index.