0

I have a dictionary of

<id, List<Action>> 

Where the id is the person id and the list is a list of the actions that this person can do now.

From this dictionary i wish to create a

List<List<Action>> 

that will hold all of the permutations that the group can do.

For example if we have this:

<1, {(1,Left), (1,Right)}>
<2, {(2,Left), (2,Right), (2,Back)}>

I wish to generate this:

[{(1,Left),(2,Left)},
{(1,Left),(2,Right)},
{(1,Left),(2,Back)},
{(1,Right),(2,Left)},
{(1,Right),(2,Right)},
{(1,Right),(2,Back)}]

How can i do this?

With regards,

Aviel.

  • have you tried anything? Or looked at SO Documentation at [Cross join](http://stackoverflow.com/documentation/c%23/68/linq-queries/2994/joins-inner-left-right-cross-and-full-outer-joins#t=201701211426406127602) – Gilad Green Jan 21 '17 at 14:26
  • This technique is call "Control Break", and simply it consists in two loops (two or whatever), one for the first list and one inside the first one for the second list. Try something, add your code here and we are going to be able to help you. `for(var i = 0; i < firstList.Lenght; i++){ for(var j=0; j< secongList.lenght; j++) { newList.add(firstList[i] + secondList[j]) } }` – Facundo La Rocca Jan 21 '17 at 14:31
  • Hey ! thanks for the help, the problem is that i don't just have 2 persons, but alot more, when the person count changes from time to time, so it will not work with 2 fors, i think there is a need to a recursive method but i can't craft it myself. – Aviel Zohar Jan 21 '17 at 14:40
  • Replace `for` with `while`. I strongly recommend you to read a little bit about how **Control Break** works. You dont need to use recursive iterations, but of course this problem could be solved using recursive loops too. – Facundo La Rocca Jan 21 '17 at 14:43

0 Answers0