5
$\begingroup$

Suppose that the data is a collection of 3-tuples:

   data={{{0, 1, 1}, {0, 1, 1}, {0, 0, 1}}, {{1, 0, 0}, {0, 1, 0}, {1, 1, 
   1}}, {{1, 0, 1}, {0, 1, 0}, {0, 0, 0}}, {{1, 1, 1}, {1, 1, 1}, {1, 
   0, 0}}, {{1, 0, 1}, {1, 0, 0}, {0, 0, 0}}, {{1, 1, 1}, {1, 1, 
   1}, {0, 0, 0}}, {{0, 1, 0}, {0, 0, 0}, {0, 1, 0}}, {{0, 1, 1}, {0, 
   0, 1}, {0, 0, 1}}, {{0, 1, 1}, {1, 0, 1}, {1, 1, 1}}, {{0, 1, 
   1}, {0, 1, 1}, {1, 0, 0}}, {{1, 1, 0}, {0, 1, 1}, {0, 0, 0}}, {{0, 
   0, 0}, {1, 1, 1}, {1, 1, 0}}, {{1, 1, 1}, {1, 1, 1}, {1, 0, 
   0}}, {{0, 0, 0}, {0, 1, 0}, {0, 1, 0}}, {{0, 1, 0}, {0, 1, 0}, {1, 
   1, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 1, 0}, {1, 0, 
   1}, {0, 1, 1}}, {{0, 0, 1}, {0, 1, 0}, {0, 1, 1}}, {{1, 1, 1}, {1, 
   1, 0}, {1, 1, 1}}, {{0, 0, 1}, {0, 0, 1}, {0, 0, 1}}, {{1, 0, 
   0}, {0, 0, 1}, {1, 0, 0}}, {{1, 0, 1}, {1, 1, 0}, {1, 1, 0}}, {{1, 
   0, 1}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 1}, {1, 0, 0}, {0, 1, 
   0}}, {{1, 0, 1}, {0, 0, 0}, {1, 0, 1}}, {{0, 0, 0}, {0, 0, 0}, {0, 
   1, 1}}, {{0, 1, 0}, {0, 1, 0}, {1, 0, 1}}, {{1, 1, 1}, {1, 0, 
   0}, {1, 0, 0}}, {{1, 0, 0}, {0, 0, 0}, {0, 1, 1}}, {{0, 0, 0}, {1, 
   0, 1}, {1, 1, 0}}, {{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}, {{0, 1, 
   1}, {0, 1, 1}, {1, 0, 0}}, {{0, 0, 0}, {0, 0, 1}, {0, 0, 0}}}

How to find only those set of 3 tuples in the data where the 2nd and 3rd elements of their 1st 3-tuple equals the first and the second elements of the 2nd 3-tuple and that the 2nd and the 3rd elements of the 2nd 3-tuple equals the 1st and 2nd element of the 3rd 3-tuple.

$\endgroup$

3 Answers 3

5
$\begingroup$
Select[Most[Rest /@ #] == Rest[Most /@ #] &] @ data
{{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
 {{0, 1, 0}, {1, 0, 1}, {0, 1, 1}}, 
 {{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}}
$\endgroup$
9
$\begingroup$

If I understood you correctly, something like this would work

Cases[data,{{_,a_,b_},{a_,b_,c_},{b_,c_,_}}]

(* {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, 
    {{0, 1, 0}, {1, 0, 1}, {0, 1, 1}}, 
    {{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}} *)
$\endgroup$
2
$\begingroup$
Pick[
 data,
 MapThread[SameQ, {
   data[[All, ;; -2, {2, 3}]],
   data[[All, 2 ;;, {1, 2}]]
   }]
 ]

(* Out: {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 1, 0}, {1, 0, 1}, {0, 1, 
   1}}, {{1, 0, 1}, {0, 1, 1}, {1, 1, 1}}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.