In my opinion we should point out if a question is more atom-like then is 
appropriate for J.
The most important in using J is thinking J-like, which I learned by studying 
Rich's J for C-programmers.
So my wholistic solution is 

   (</. i.@#) 20 ?.@# 8
+-----+------------+-------------+----+-----+-----+
|0 3 6|1 2 5 7 8 17|4 10 13 18 19|9 12|11 15|14 16|
+-----+------------+-------------+----+-----+-----+

in which everything about the nth duplicate can be found.
E.g., if you want the value as well

   (~.;"0 (</. i.@#)) 20 ?.@# 8
+-+-------------+
|2|0 3 6        |
+-+-------------+
|4|1 2 5 7 8 17 |
+-+-------------+
|1|4 10 13 18 19|
+-+-------------+
|3|9 12         |
+-+-------------+
|0|11 15        |
+-+-------------+
|5|14 16        |
+-+-------------+


R.E. Boss


-----Original Message-----
From: Programming <[email protected]> On Behalf Of Raul 
Miller
Sent: donderdag 27 januari 2022 19:11
To: Programming forum <[email protected]>
Subject: Re: [Jprogramming] Find nth duplicate in vector

Well, ... the implementation posted by xash is very nice, but in 
http://jsoftware.com/pipermail/programming/2022-January/059790.html
Pawel Jakubas specified that the value appears first, and the index appears 
second, and that the indices start with 1 for the first value.

Also, somewhere along the line, was the suggestion that the result of f should 
be empty rather than throwing an error if there was no such duplicate value.

FYI,

--
Raul


On Thu, Jan 27, 2022 at 12:50 PM Hauke Rehr <[email protected]> wrote:
>
> I wonder why there’s still so much traffic on this thread
> (okay, I’m to blame for quite some of it)
> I thought xash published the best correct solution.
> Am I wrong?
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to