D,g,@@#,BFB
D,k,@,¦+AbL/
D,f,@,dbLR$€g€k0b]$+ABcB]£>ª!
Try it online!
Unoriginal version, 30 bytes
D,f,@,¬+AbLRBcB/@0@B]ABcB]£>ª!
Try it online!
Both output 1 for golfy arrays and 0 otherwise
How they work
The first version was created by me, without checking any other solutions. The second was inspired by Dennis' comment, so I'm less happy with it.
The first version
Here, we define our main function \$f\$ that computes the golfiness of our input array, \$A\$. First, we need to yield the suffixes of \$A\$, which is done by first generating the range \$B := [1, ... \vert{A}\vert]\$, where \$\vert{A}\vert\$ denotes the length of \$A\$. This is done with the code dbLR$
, which leaves \$[B, A]\$ as the stack. We then iterate the dyadic function \$g\$ over these two lists. Being dyadic, the function binds its left argument as \$A\$ for each iterated element. It then iterates over the range \$B\$, which each element from \$B\$ being the right argument provided to \$g\$. \$g\$ is defined as
D,g,@@#,BFB
which is a dyadic function (i.e. takes \$2\$ arguments), and pushes its arguments to the stack in reversed order (#
) before execution. BF
then flattens the two arguments. We'll assume that the arguments are \$A\$ and \$e \in x\$. This leaves the stack as \$[...A, e]\$, where \$...\$ represents an array splat. Finally, B
takes the first \$e\$ elements of \$A\$ and returns a list containing those elements.
Note : The function names \$g\$ and \$k\$ aren't chosen randomly. If the commands given to an operator (such as €
) doesn't currently have a function (which g
and k
don't), then the named functions are searched for a matching function. This saves \$2\$ bytes, as normally the function would have to wrapped in {...}
to be recognised as a user-defined function. At the time of writing, the currently unused single byte commands are I
, K
, U
, Y
, Z
, g
, k
, l
, u
and w
.
When \$g\$ is applied over the elements of a range \$x\$, this returns a list of prefixes for \$A\$. We then map our second helper function \$k\$ over each of these prefixes. \$k\$ is defined as
D,k,@,¦+AbL/
which is the standard implementation of the arithmetic mean. ¦+
calculates the sum of the argument, AbL
calculates its length, then /
divides the sum by the length. This calculates the arithmetic mean of each prefix, yielding a new array, \$C\$.
Unfortunately, \$C\$ contains the mean of \$A\$ as its final element, and does not include the mean of the empty list, \$0\$. Therefore, we would have to remove the final element, and prepend a \$0\$, but popping can be skipped, saving two bytes, for reasons explained in a second. Instead, we push \$[0]\$ underneath \$C\$ with 0b]$
, then concatenate the two arrays forming a new array, \$C^+\$.
Now, we need to check each element as being less than its corresponding element in \$A\$. We push \$A\$ once again and zip the two arrays together with ABcB]
. This is the reason we don't need to pop the final element: Bc
is implemented with Python's zip
function, which truncates the longer arrays to fit the length of the shortest array. Here, this removes the final element of \$C^+\$ when creating the pairs.
Finally, we starmap \$p \in A, q \in C^+; p < q \equiv \neg(p \ge q)\$ over each pair \$p, q\$ to obtain an array of all \$0\$s if the array is golfy, and array containing at least a single \$1\$ if otherwise. We then check that all elements are falsey i.e. are equal to \$0\$ with ª!
and return that value.
The second version
This takes advantage of Dennis' approach to remove \$24\$ bytes, by eliminating the helper functions. Given our input array of \$A\$, we first compute the cumulative sums with ¬+
, i.e the array created from \$[A_0, A_0+A_1, A_0+A_1+A_2, ..., A_0+...+A_i]\$. We then generate Jelly's equivalent of J
(indicies), by calculating the range \$B := [1 ... \vert{A}\vert]\$ where \$\vert{A}\vert\$ once again means the length of the array.
Next, we divide each element in \$A\$ by the corresponding index in \$B\$ with BcB/
and prepend \$0\$ with @0@B]
. This results in a new array, \$C^+\$, defined as
$$C^+ := [0, A_0, \frac{A_0+A_1}{2}, \frac{A_0+A_1+A_2}{3}, ..., \frac{A_0+...+A_i}{i+1}]$$
The final part is identical to the first version: we push and zip \$A\$ with \$C^+\$, then starmap inequality over each pair before asserting that all elements in the resulting array were falsy.