I'm struggling with this algorithm I need to write. I'm using C#.
Say I have a List<Bag>
and I have a List<Lunch>
.
I need to write an algorithm which will enumerate all permutations of lunches in all bags.
For example, say there are 3 lunches and 2 bags:
// Permutation 1
Bag 1, Lunch 1
Bag 2, Lunch 1
// Permutation 2
Bag 1, Lunch 1
Bag 2, Lunch 2
// Permutation 3
Bag 1, Lunch 1
Bag 2, Lunch 3
// Permutation 4
Bag 1, Lunch 2
Bag 2, Lunch 1
// Permutation 5
Bag 1, Lunch 2
Bag 2, Lunch 2
// Permutation 6
Bag 1, Lunch 2
Bag 2, Lunch 3
// Permutation 7
Bag 1, Lunch 3
Bag 2, Lunch 1
// Permutation 8
Bag 1, Lunch 3
Bag 2, Lunch 2
// Permutation 9
Bag 1, Lunch 3
Bag 2, Lunch 3
The two permutations Bag 1 Lunch 1 and Bag 2 Lunch 2
and Bag 1 Lunch 2 and Bag 2 Lunch 1
are different because the bags have different capacities, hence they would both need to be enumerated.
The number of bags and lunches can be any number.
I have created a class called BagLunch
which contains a bag and lunch pair. The example list I've given above would be stored in a List<BagLunch>
.
Thank you.