I want to detect if a set of pairs, for example a={{2,5},{6,3},{1,4},{8,7}}
contains a given pair, for example tabu={{4,1},{2,6}}
but don´t be relevant the order inside pair (pair {i,j}
is equal to {j,i}
), so in this case.... YES!!! "a has an element of tabu.
That´s the only target.
So, Are there any function to do this directly?
I was thinking in a variable tabustatus = True
if the big contains any pair of tabu
, or tabustatus = False
otherwise. Ordering previously the pairs for avoid the sort issue(no matter) any similar to:
a = {{1, 2}, {4, 3}, {3, 2}, {5, 2}};
tabu = {{2, 6}, {4, 1}};
asortg = Table[Sort[a[[i]], Greater], {i, 1, Length[a]}];
asortl = Table[Sort[a[[i]], Less], {i, 1, Length[a]}];
tabusortg = Table[Sort[tabu[[i]], Greater], {i, 1, Length[tabu]}];
tabusortl = Table[Sort[tabu[[i]], Less], {i, 1, Length[tabu]}];
Print["a...........", a];
Print["a - Greater.", asortg];
Print["a - Less....", asortl];
Print["----------------------"];
Print["tabu...........", tabu];
Print["tabu - Greater.", tabusortg];
Print["tabu - Less.....", tabusortl];
Print["----------------------"];
tabustatus = False;
Do[Do[Print["i..", i, " j..", j];If[asortl[[i]] == tabusortl[[j]], Print[asortl[[i]], " - ", tabusortl[[j]]]; tabustatus = True; Break[], False]; If[tabustatus == True, Break[]], {i, 1, Length[asortl]}]; If[tabustatus == True, Break[]], {j, 1, Length[tabu]}];
Print["Tabu Status...", tabustatus];
In this case, I would need to add any Breaks[]
to exit If
... Do
...Do
... without continue searching,... since one time one is found,... TABUSTATUS=TRUE
, We don´t need to continue searching.
Any faster and less tedious alternative?