Basically, I have an array containing 25 different people, I need to select 5 of these people and have every single combination possible, without using duplicates of the same person.
The only logical way I can think of doing it is by having 5 for loops and checking if person has already been used, although this seems like there's probably a better method involving recursion.
If anyone can help I'd be very appreciated.
Here's an example of my class;
public class Calculator {
final Person[] people = new Person[25]; //Pretend we have filled in this info already
public List<Group> generateList()
{
final List<Group> possible = new ArrayList<>();
for (int a = 0; a < 25; a++)
{
for (int b = 0; b < 25; b++)
{
for (int c = 0; c < 25; c++)
{
for (int d = 0; d < 25; d++)
{
for (int e = 0; e < 25; e++)
{
final Group next = new Group();
next.set = new Person[] {
people[a],
people[b],
people[c],
people[d],
people[e]
};
possible.add(next);
}
}
}
}
}
return possible;
}
class Group {
Person[] set = new Person[5];
}
class Person {
String name;
int age;
}
}
However I'm not sure the best way to do this and if that would even get every combination. I also know there's no duplicate checking here, which I'd do by checking;
if(b == a) continue;
Etc.
I would appreciate any help.