Here's a variation that works:

   d=: 1 _1 2 3 4 2 5 6 3 8 10 3 2
   f=: {{y ({~,]) x i.~ +/\(i.@#~:i.~)y }}
   1 f d
2 5
   2 f d
3 8

The phrase (i.@# ~: i.~) finds the locations of duplicates

   (i.@#~:i.~) 1 _1 2 3 4 2 5 6 3 8 10 3 2
0 0 0 0 0 1 0 0 1 0 0 1 1

And, +/\ computes a running sum
   +/\(i.@#~:i.~) d
0 0 0 0 0 1 1 1 2 2 2 3 4

With this, we can find the index of the first occurrence of a
duplicate count number using x i.~ ...

Once we have the index of a duplicate, we can return that index and
the corresponding value from the list.

-- 
Raul

On Wed, Jan 26, 2022 at 3:49 PM Pawel Jakubas <[email protected]> wrote:
>
> It should be of course
>   1 f d
> 2 5
>
> Would be great if you could decompose your solution and the idea behind the
> solution. Many thanks.
>
> Cheers,
> Pawel
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to