Removing "reversal duplicates" from a list

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Removing "reversal duplicates" from a list

Postby nicholas.small on Wed Jun 30, 2021 11:55 am

I have a nested numeric vector (though, of course, it could just as easily be a matrix) in which each item and its reversal are present; I wish to eliminate one of each of these paired items. The best (only) solution I have come up with is repeated application, using power, of
{1⌽⍵~⊂⌽⊃⍵}. Any suggestions?

Thanks,

Nicholas
nicholas.small
 
Posts: 11
Joined: Tue Mar 30, 2021 8:45 pm

Re: Removing "reversal duplicates" from a list

Postby Veli-Matti on Wed Jun 30, 2021 8:44 pm

Hi,
if I understood you right, you have nested vector of vectors, something like
      ⍪vec←{⍵[?⍨≢⍵]}↑,/10{{⍵(⌽⍵)}(??⊢)⍺}¨⍳5
10 3 6 9
9 3 6 10 4 1 7
10 8 3 7 6 5 1 9 4 2
7 1 4 10 6 3 9
1 8 10 6 2 9 4 3
3 4 9 2 6 10 8 1
2 4 9 1 5 6 7 3 8 10
1 6 8 3 2 10
10 2 3 8 6 1
9 6 3 10

..and you want to remove one of the pairs (I suppose that there are no equal items when sorted), so I'd suggest something like (version 18.0 - if earlier, replace the leading ≠ with {(⍵⍳⍵)=⍳⍴⍵}):
      ≠((⊂⍋)⌷⊢)¨vec
1 1 1 0 1 0 0 1 0 0


-Veli-Matti
Veli-Matti
 
Posts: 75
Joined: Sat Nov 28, 2009 3:12 pm

Re: Removing "reversal duplicates" from a list

Postby nicholas.small on Wed Jun 30, 2021 9:43 pm

Veli-Matti,
Each of the items in my nested array is an arrangement of the digits 2/⍳n. In the case of n=7, there are 380; here are the first 8, together with their reversals:

1 4 1 5 6 7 4 2 3 5 2 6 3 7
1 4 1 6 7 3 4 5 2 3 6 2 7 5
1 5 1 4 6 7 3 5 4 2 3 6 2 7
1 5 1 4 7 3 6 2 4 3 2 5 7 6
1 5 1 6 3 7 2 4 3 2 6 5 4 7
1 5 1 6 3 7 4 5 3 2 6 4 2 7
1 5 1 6 4 7 3 5 2 4 3 2 6 7
1 5 1 6 7 2 4 5 2 3 6 4 7 3
7 3 6 2 5 3 2 4 7 6 5 1 4 1
5 7 2 6 3 2 5 4 3 7 6 1 4 1
7 2 6 3 2 4 5 3 7 6 4 1 5 1
6 7 5 2 3 4 2 6 3 7 4 1 5 1
7 4 5 6 2 3 4 2 7 3 6 1 5 1
7 2 4 6 2 3 5 4 7 3 6 1 5 1
7 6 2 3 4 2 5 3 7 4 6 1 5 1
3 7 4 6 3 2 5 4 2 7 6 1 5 1

The object is to eliminate either the first half or the second half of these rows/items.

Thank you for your suggestion - I knew there was a primitive corresponding to nub but could not remember what it was and I must refresh my knowledge of function trains. However, you can see that it solves a different problem.

The data arose in connection with an obscure problem concerned with change ringing on handbells. You might like to see if you can spot how the numbers are constrained (clue: add 0 0 at the start of each of the 16 rows).

Nicholas
nicholas.small
 
Posts: 11
Joined: Tue Mar 30, 2021 8:45 pm

Re: Removing "reversal duplicates" from a list

Postby Veli-Matti on Thu Jul 01, 2021 7:19 am

OK, now I see it (vaguely).
Usually knowing the data helps a little bit :)

There might be some raw force approaches available (i.e. trad fns) - the best I can imagine now is something like:
      z←clean x;b;i

:For i :In ⍳≢b←1⊣¨x←(≠x)/x
:If ~i⊃b ⋄ :Continue ⋄ :End
b←b\(b/x)≢¨⊂⌽i⊃x
:EndFor

z←b/x


But perhaps if you _know_ that all the items are reversed (and there are no duplicates), you could take the first value from each item, and proceed with that (e.g. if you sort the firsts and see that half of them are smaller than the others).

-Veli-Matti
Veli-Matti
 
Posts: 75
Joined: Sat Nov 28, 2009 3:12 pm

Re: Removing "reversal duplicates" from a list

Postby nicholas.small on Thu Jul 01, 2021 10:56 am

That certainly does the job, incidentally selecting the same items as my function.

Thanks,

Nicholas
nicholas.small
 
Posts: 11
Joined: Tue Mar 30, 2021 8:45 pm

Re: Removing "reversal duplicates" from a list

Postby nicholas.small on Thu Jul 01, 2021 8:51 pm

I've thought of a more accessable was of describing the puzzle which gave rise to this thread. I shall post it in Chat.

Nicholas
nicholas.small
 
Posts: 11
Joined: Tue Mar 30, 2021 8:45 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest