I hope to have your help, if I have
listp = Permutations[Range[7]];
With the following functions, I delete the lists that contain {7,2}
and {2,7}
of the variable listp
filtro[num_List]:=If[Position[num,7]==Position[num,2]+1,False,True];
sfir[num_List]:=If[Position[num,7]==Position[num,2]-1,False,True];
For example in listp
is the permutation {1,4,2,7,6,3,5}
, which should be deleted from listp
, since it contains {2,7}
, also permutation {5,1,6,4 , 3,2,7}
should be deleted from listp
for the same reason. To make all permutations like those mentioned above be removed from listp
I do the following:
ek = Select[listp, filtro];
{Length[listp], Length[ek]}
As you can see 720 permutations of listp have been eliminated, I have only used {2,7} as a criterion, now if I use {7,2} let's see how many permutations are eliminated
do = Select[ek, sfir];
{Length[listp], Length[ek], Length[do]}
You will have already noticed that 720 permutations were erased, in total 1440 permutations of listp
have been eliminated.
What I did in the previous section was simply delete all the permutations of {2,7}
which are
Permutations[{2,7}]
The problem is that for each permutation I had to build a function, besides I want to erase other permutations, which I enlist so that you know what they are.
Permutations[{1,3,5}];
Permutations[{2,4,6,7}];
If I have counted correctly, I would have to do 30 functions to erase all the permutations that I want from listp
. I would like to ask you to please help me carry out this listp
debugging, since I thought about using the DeleteCases
command but I did not know how to assign the permutations that I want to delete within that command, maybe you know an alternative method to achieve my goal. Any help is welcome since I am stuck in this part. Thanks in advance.