Partitioning

23 views
Skip to first unread message

Skip Cave

unread,
Apr 28, 2024, 6:10:46 PMApr 28
to fo...@jsoftware.com
What verb 's' can do the following partitioning?


image.png



Skip Cave
Cave Consulting LLC


Elijah Stone

unread,
Apr 28, 2024, 6:19:27 PMApr 28
to 'Skip Cave' via forum
I suppose something like this could work

n=. i.10
t=. 2 5
(t,_) {.&.> (0,+/\t) <@}."0 _ n
┌───┬─────────┬─────┐
│0 1│2 3 4 5 6│7 8 9│
└───┴─────────┴─────┘

or, maybe nicer:

n <;.1~ 1 (0,+/\t)} 0"_1 n
┌───┬─────────┬─────┐
│0 1│2 3 4 5 6│7 8 9│
└───┴─────────┴─────┘

On Sun, 28 Apr 2024, 'Skip Cave' via forum wrote:

> What verb 's' can do the following partitioning?
>
>
> image.png
>
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>
>

Alex Shroyer

unread,
Apr 28, 2024, 7:32:16 PMApr 28
to fo...@jsoftware.com
Another approach:
   2 5 {{ (I.x,(#y)-+/x)</.y }} i.10
┌───┬─────────┬─────┐

│0 1│2 3 4 5 6│7 8 9│
└───┴─────────┴─────┘

Raul Miller

unread,
Apr 29, 2024, 12:28:27 AMApr 29
to fo...@jsoftware.com
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
>
>

LdBeth

unread,
Apr 29, 2024, 12:32:05 AMApr 29
to fo...@jsoftware.com

My take on it:

c=.(#@]~:@{.[#>:@i.@#@[) <;.1 ]

2 5 c i. 10


A break down:

a=.[#>:@i.@#@[
b=.#@]~:@{.a
c=.b <;.1 ]

2 5 a i. 10
1 1 2 2 2 2 2

2 5 b i. 10
1 0 1 0 0 0 0 1 0 0

LdBeth


>>>>> In <CAJ8Lg_f+661eA5OxhXHr5CbR...@mail.gmail.com>
>>>>> "'Skip Cave' via forum" <fo...@jsoftware.com> wrote:
> [1 <multipart/alternative (7bit)>]
> [1.1 <text/plain; UTF-8 (7bit)>]
> [1.2 <text/html; UTF-8 (quoted-printable)>]
> What verb 's' can do the following partitioning?

Skip Cave

unread,
Apr 29, 2024, 2:01:54 AMApr 29
to fo...@jsoftware.com
Alex had the right idea!

pv=:{{(I.x,(#y)-+/x)</.y}}


]n=.?15#20

9 12 3 14 3 13 18 8 12 17 17 14 19 9 18


image.png



Skip Cave
Cave Consulting LLC

Reply all
Reply to author
Forward
0 new messages