For beginners I would suggesg this as it indicate the two uses of y: Ff=: 13 :'~.(-.~:y)#y'
Linda -----Original Message----- From: Programming [mailto:[email protected]] On Behalf Of 'Mike Day' via Programming Sent: Sunday, January 14, 2018 4:22 PM To: [email protected] Subject: Re: [Jprogramming] Finding duplicates 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 >>>> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww >>>> w.jsoftware.com%2Fforums.htm&data=02%7C01%7C%7Cd1c0760e39a540214165 >>>> 08d55b94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617 >>>> 191764814&sdata=ympE9UeLwrcs8QjHd70OSatPwYl5uSGRnR1i1%2FeIjCE%3D&re >>>> served=0 >>> -------------------------------------------------------------------- >>> -- For information about J forums see >>> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww >>> .jsoftware.com%2Fforums.htm&data=02%7C01%7C%7Cd1c0760e39a54021416508 >>> d55b94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617191 >>> 764814&sdata=ympE9UeLwrcs8QjHd70OSatPwYl5uSGRnR1i1%2FeIjCE%3D&reserv >>> ed=0 >>> >> --------------------------------------------------------------------- >> - For information about J forums see >> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww. >> jsoftware.com%2Fforums.htm&data=02%7C01%7C%7Cd1c0760e39a54021416508d5 >> 5b94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617191764 >> 814&sdata=ympE9UeLwrcs8QjHd70OSatPwYl5uSGRnR1i1%2FeIjCE%3D&reserved=0 >> > ---------------------------------------------------------------------- > For information about J forums see > https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.j > software.com%2Fforums.htm&data=02%7C01%7C%7Cd1c0760e39a54021416508d55b > 94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617191764814 > &sdata=ympE9UeLwrcs8QjHd70OSatPwYl5uSGRnR1i1%2FeIjCE%3D&reserved=0 --- This email has been checked for viruses by Avast antivirus software. https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.avast.com%2Fantivirus&data=02%7C01%7C%7Cd1c0760e39a54021416508d55b94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617191764814&sdata=eZJhjLR%2Bwsd%2FWGlig5WM6jnOxzQrJ69%2BPrJAND%2FhE9k%3D&reserved=0 ---------------------------------------------------------------------- For information about J forums see https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&data=02%7C01%7C%7Cd1c0760e39a54021416508d55b94d80d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636515617191764814&sdata=ympE9UeLwrcs8QjHd70OSatPwYl5uSGRnR1i1%2FeIjCE%3D&reserved=0 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
