It's probably worth noting that this problem statement is ambiguous.
I think it's clear that we want to treat the left argument as the
running sum +/\0,x but the significance of the right argument is
unclear to me.
I think it's safe to assume that the right argument is small (fewer
than a million elements and we're not overly concerned about time).
But the the value 2 happens to match the position 2 and I am not
completely sure which was intended. Nor am I certain whether the right
argument is intended to be a sorted sequence or a set of unique values
or something else.
Meanwhile, J provides several different partitioning facilities. We
have (;.) which partitions sequences, and there's (/.) which
partitions sets (and we can "roll our own" using structural
operations).
So... anyways, I'll propose two different 's' verbs - spos and sval:
NB. partition by position in y
spos=: {{ (1 ((#~ (#y)&>) +/\0,x)}(#y)#0) <;.1 y }}
spos=: {{ ((i.#y) e. +/\0, x) <;.1 y }}
NB. partition by value in y
sval=: {{ (+/(+/\x) </ y) </. y }}
And, of course, there are other approaches...
FYI,
--
Raul
On Sun, Apr 28, 2024 at 6:10 PM 'Skip Cave' via forum
<
fo...@jsoftware.com> wrote:
>
> What verb 's' can do the following partitioning?
>
>
>
>
> Skip Cave
> Cave Consulting LLC
>
>