java - All possible permutations of 2D array -


yesterday asked question appeared duplicate, one, however, pretty sure not duplicate, 1 teeny bit more advanced. title not explain of it, carry on reading.

let pretend have 2d array so:

{{true, false}, {true, false}, {true, false}, ...} 

now, let loop through possible permutations of it:

{{false, true}, {true, false}, {true, false}, ...} {{true, false}, {false, true}, {true, false}, ...} {{true, false}, {true, false}, {false, true}, ...} {{false, true}, {true, false}, {false, true}, ...} 

and forth...

since adds level it, confuses mind. know length of inner arrays two, never change. is:

boolean[][] b = new boolean[i][2]; 

what best way accheive possible permutations of 2d array, using java?

thank you,

this can apparently done in same way other permutation takes place, need loop on list permutation applied to, , go on possible combinations of different elements recursively.

private void permute(list<list<boolean>> list, int t) {     for(int = 0; < list.size(); ++)     {         collections.swap(list.get(i), 0, 1);         permute(list, t + 1);         collections.swap(list.get(i), 1, 0);     }      if(t == list.size() - 1)         system.out.println("another permutation."); } 

and covers whole things, of sudden have mapped out possible combinations of problem explained above.

now let assume have 3 booleans instead of 2 switch in 2d manner, of sudden things more complicated.

kind regards,


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -