Getting all indexes of duplicates in list
I'm looking to compare multiple numbers and getting the indexes of those equal to each other. I'm thinking a list-approach using [zl] objects is the fastest way to do it but I can't find a combination that works.
What I'm hoping to do is something like:
Input: A A B A C D
Output (indexes): 1 2 4
Or,
Input: D A A B C B
Output: 2 3 4 6
Any help would be greatly appreciated. If it's not possible with [zl] any other method is welcome as well. The numbers are coming in separately from multiple [counter]s. But I haven't been able to figure out any other method that's not going to be a mess of patch chords and a favela of objects.
here one option using coll
the key is to collect repetitions into same coll line
using list items as coll indexes, and their list position index(es) as data
when coll dumps only lines with more than 1 item get collected into list
you asked indexing from 1 up.
if you want to use zero based replace listfunnel 1
with listfunnel (defaults to zero)
P.S.
for large lists one would maybe need to increase del 0 time
Damn, thank you :) I never would have arrived at this on my own.
I have some tinkering and picking it apart to fully understand what's happening but it's working.
Thank you so much :)
there is no mistery in that patch.
- send list to listfunnel to index the list items and reverse output pairs so that
list item is first, index second
- merge message to coll adds index(es) of each list item at same
coll address or index, so that if for example "A" is repeated 3 times in the list at list indexes 1 3 & 7
A B A c d e A T
coll line becomes
A, 1 3 7 ;
- coll dump output runs through zl slice 1 which means that only if there were more than 1
occurences of a list item (repetitions), something would come out of second outlet of
zl slice 1
when that happens both outputs of zl slice 1 get combined into list
and appended to the list at the end.
---------
few objects like
t b l clear set or t l zlclear
wipe leftovers from last list input before passing the list.
if zl reg is empty, nothing can trigger the join output