3
$\begingroup$

I have the following list:

i=2
k=3
 list = Tuples[Tuples[{0, 1}, i], k]

{{{0, 0}, {0, 0}, {0, 0}}, {{0, 0}, {0, 0}, {0, 1}}, {{0, 0}, {0, 0}, {1, 0}}, {{0, 0}, {0, 0}, {1, 1}}, {{0, 0}, {0, 1}, {0,0}}, {{0, 0}, {0, 1}, {0, 1}}, {{0, 0}, {0, 1}, {1, 0}}, {{0, 0}, {0, 1}, {1, 1}}, {{0, 0}, {1, 0}, {0, 0}}, {{0, 0}, {1, 0}, {0, 1}}, {{0, 0}, {1, 0}, {1, 0}}, {{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {1, 1}, {0, 0}}, {{0, 0}, {1, 1}, {0, 1}}, {{0, 0}, {1, 1}, {1, 0}}, {{0, 0}, {1, 1}, {1, 1}}, {{0, 1}, {0, 0}, {0, 0}}, {{0, 1}, {0, 0}, {0, 1}}, {{0, 1}, {0, 0}, {1, 0}}, {{0, 1}, {0, 0}, {1, 1}}, {{0, 1}, {0, 1}, {0, 0}}, {{0, 1}, {0, 1}, {0, 1}}, {{0, 1}, {0, 1}, {1, 0}}, {{0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}, {0, 0}}, {{0, 1}, {1, 0}, {0, 1}}, {{0, 1}, {1, 0}, {1, 0}}, {{0, 1}, {1, 0}, {1, 1}}, {{0, 1}, {1, 1}, {0, 0}}, {{0, 1}, {1, 1}, {0, 1}}, {{0, 1}, {1, 1}, {1, 0}}, {{0, 1}, {1, 1}, {1, 1}}, {{1, 0}, {0, 0}, {0, 0}}, {{1, 0}, {0, 0}, {0, 1}}, {{1, 0}, {0, 0}, {1, 0}}, {{1, 0}, {0, 0}, {1, 1}}, {{1, 0}, {0, 1}, {0, 0}}, {{1, 0}, {0, 1}, {0, 1}}, {{1, 0}, {0, 1}, {1, 0}}, {{1, 0}, {0, 1}, {1, 1}}, {{1, 0}, {1, 0}, {0, 0}}, {{1, 0}, {1, 0}, {0, 1}}, {{1, 0}, {1, 0}, {1, 0}}, {{1, 0}, {1, 0}, {1, 1}}, {{1, 0}, {1, 1}, {0, 0}}, {{1, 0}, {1, 1}, {0, 1}}, {{1, 0}, {1, 1}, {1, 0}}, {{1, 0}, {1, 1}, {1, 1}}, {{1, 1}, {0, 0}, {0, 0}}, {{1, 1}, {0, 0}, {0, 1}}, {{1, 1}, {0, 0}, {1, 0}}, {{1, 1}, {0, 0}, {1, 1}}, {{1, 1}, {0, 1}, {0, 0}}, {{1, 1}, {0, 1}, {0, 1}}, {{1, 1}, {0, 1}, {1, 0}}, {{1, 1}, {0, 1}, {1, 1}}, {{1, 1}, {1, 0}, {0, 0}}, {{1, 1}, {1, 0}, {0, 1}}, {{1, 1}, {1, 0}, {1, 0}}, {{1, 1}, {1, 0}, {1, 1}}, {{1, 1}, {1, 1}, {0, 0}}, {{1, 1}, {1, 1}, {0, 1}}, {{1, 1}, {1, 1}, {1, 0}}, {{1, 1}, {1, 1}, {1, 1}}}

I would like to remove redundant element, like "{{0, 1}, {0, 0}, {0, 0}}" since they have the same value like "{{1, 0}, {0, 0}, {0, 0}}". The "{{0, 0}, {0, 0}, {0, 0}}" element should be removed as well. Elements like "{{1, 1}, {0, 0}, {0, 0}}" are not equal to "{{0, 0}, {1, 1}, {0, 0}}" though. Note that the inner subsets are of size $i$ which are elements in subsets of size $k$.

Maybe the list should be created differently? How can I make this happen? The goal is to get it for any $i$ and $k$ in general.

For example, instead of

list = Tuples[Tuples[{0, 1}, 2], 2]
{{{0, 0}, {0, 0}}, {{0, 0}, {0, 1}}, {{0, 0}, {1, 0}}, {{0, 0}, {1, 
   1}}, {{0, 1}, {0, 0}}, {{0, 1}, {0, 1}}, {{0, 1}, {1, 0}}, {{0, 
   1}, {1, 1}}, {{1, 0}, {0, 0}}, {{1, 0}, {0, 1}}, {{1, 0}, {1, 
   0}}, {{1, 0}, {1, 1}}, {{1, 1}, {0, 0}}, {{1, 1}, {0, 1}}, {{1, 
   1}, {1, 0}}, {{1, 1}, {1, 1}}}  

a possible output is:

{{{0, 0}, {1, 0}}, {{0, 0}, {1, 1}}, {{1, 0}, {0, 0}}, {{1, 0}, {1, 
   0}}, {{1, 0}, {1, 1}}, {{1, 1}, {0, 0}}, {{1, 1}, {1, 0}}, {{1, 
   1}, {1, 1}}}
$\endgroup$
2
  • 1
    $\begingroup$ Please show your desired output. $\endgroup$ Jul 25, 2020 at 19:37
  • $\begingroup$ @PaulCommentary added an example, thanks. $\endgroup$
    – Y.L
    Jul 25, 2020 at 19:46

1 Answer 1

4
$\begingroup$
With[{i = 2, k = 3},
 DeleteCases[
  Tuples[DeleteDuplicatesBy[Tuples[{0, 1}, i], Sort], k],
  ConstantArray[0, {k, i}]
 ]]

Result:

{{{0, 0}, {0, 0}, {0, 1}}, {{0, 0}, {0, 0}, {1, 1}}, {{0, 0}, {0, 
   1}, {0, 0}}, {{0, 0}, {0, 1}, {0, 1}}, {{0, 0}, {0, 1}, {1, 
   1}}, {{0, 0}, {1, 1}, {0, 0}}, {{0, 0}, {1, 1}, {0, 1}}, {{0, 
   0}, {1, 1}, {1, 1}}, {{0, 1}, {0, 0}, {0, 0}}, {{0, 1}, {0, 0}, {0,
    1}}, {{0, 1}, {0, 0}, {1, 1}}, {{0, 1}, {0, 1}, {0, 0}}, {{0, 
   1}, {0, 1}, {0, 1}}, {{0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 1}, {0,
    0}}, {{0, 1}, {1, 1}, {0, 1}}, {{0, 1}, {1, 1}, {1, 1}}, {{1, 
   1}, {0, 0}, {0, 0}}, {{1, 1}, {0, 0}, {0, 1}}, {{1, 1}, {0, 0}, {1,
    1}}, {{1, 1}, {0, 1}, {0, 0}}, {{1, 1}, {0, 1}, {0, 1}}, {{1, 
   1}, {0, 1}, {1, 1}}, {{1, 1}, {1, 1}, {0, 0}}, {{1, 1}, {1, 1}, {0,
    1}}, {{1, 1}, {1, 1}, {1, 1}}}

For the 2,2 case, the result is:

{{{0, 0}, {0, 1}}, {{0, 0}, {1, 1}}, {{0, 1}, {0, 0}}, {{0, 1}, {0, 
   1}}, {{0, 1}, {1, 1}}, {{1, 1}, {0, 0}}, {{1, 1}, {0, 1}}, {{1, 
   1}, {1, 1}}}

... which is the same as your expected output, if you're willing to apply Map[Sort,expected,{2}] to change {1,0} into {0,1}

$\endgroup$
3
  • $\begingroup$ Beautiful @flinty, just how do I apply the Map[Sort,expected,{2}] is I need to? Thank you! $\endgroup$
    – Y.L
    Jul 25, 2020 at 20:53
  • $\begingroup$ What do you mean? I only put that in in case you're worried about the order in each sub-sub-list. You could do Map[Reverse,result,{2}] if you want the results in the same order too. $\endgroup$
    – flinty
    Jul 25, 2020 at 20:54
  • $\begingroup$ The "Reverse" fixed it. Thank you so much. $\endgroup$
    – Y.L
    Jul 25, 2020 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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