I came up with
fdpa=:~. #~ 1 < #/.~
which works well on lists with few unique members.
I also found this variant of an apl/J idiom:
fdpb=: ~.@: #~ (i.@# > i.~)
eg, for
biga =: 1000000 $ 4 6 8 6 5 8 6 6 6 9
ts'fdp biga'
0.0551074 1.67784e7
ts'fdpa biga'
0.0276174 8.39002e6
ts'fdpb biga'
0.0910374 1.78269e7
However, for your (Skip's) random array,
a=: ?1000$5000
fdpa performs worse than fdp and fdpb:
ts'fdp a'
2.48377e_5 4224
ts'fdpa a'
5.12953e_5 132224
ts'fdpb a'
5.4535e_5 19584
Note that fdp and fdpb return items in order of the first repeats,
while fdpa returns them in the order of the first occurrences of
repeated items.
ie
(fdp, fdpa,: fdpb) 4 6 8 6 5 8 6 6 6 9 4 6 9
6 8 4 9
4 6 8 9
6 8 4 9
I don't know which is preferable!
Cheers,
Mike
On 14/01/2018 18:50, Jimmy Gauvin wrote:
You might try :
~. (#~ -.@~:) 4 6 8 6 5 8 6 6 6 9
6 8
On Sun, Jan 14, 2018 at 1:09 PM, Skip Cave <[email protected]> wrote:
Nice! Thanks to Henery Rich & R.E. Boss.
For me, I want to list the dups just once. So I made this "find duplicates
(and list them once)" verb:
fdp=. ~.@(#~-.@~:)
Works great!
I had tried this:
~.a#~1<+/ e. a=. 4 6 8 6 5 8 6 6 6 9
6 8
But my scheme doesn't scale well. I get "out of memory" errors on large
lists, so it is very wasteful of space, and it is WAY slower.
a=. ?1000$5000
(/:~fdp a) -: (/:~ ~.a#~1<+/ e. a)
1
ts 'fdp a'
5.99449e_6 4224
ts '~.a#~1<+/ e. a'
0.00294153 1.07405e6
Skip
Skip Cave
Cave Consulting LLC
On Sun, Jan 14, 2018 at 10:44 AM, R.E. Boss <[email protected]> wrote:
(-.@~:)4 6 8 6 5 8 6 6 6 9
0 0 0 1 0 1 1 1 1 0
R.E. Boss
-----Original Message-----
From: Programming [mailto:[email protected]]
On Behalf Of Skip Cave
Sent: zondag 14 januari 2018 17:34
To: [email protected]
Subject: [Jprogramming] Finding duplicates
I have a string of integers. How do I list just the duplicates in the
string?
Skip
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm