Skip to content

Instantly share code, notes, and snippets.

@KevinTyrrell
Created July 8, 2017 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinTyrrell/094aa37a0430188e141da6764e870522 to your computer and use it in GitHub Desktop.
Save KevinTyrrell/094aa37a0430188e141da6764e870522 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class Combinatorics
{
public static void main(String[] args)
{
final String[][] champs = new String[][] {
{ "Support#1", "Support#2", "Support#3" },
{ "Bruiser#1" },
{ "ADC#1", "ADC#2" }
};
final int types = champs.length;
final int maxPerType = Arrays.stream(champs).mapToInt(e -> e.length).max().getAsInt();
final int maxPerm = (int)Math.pow(types, maxPerType);
final int combo[] = new int[types];
next:
for (int perm = 0; perm < maxPerm; perm++, combo[0]++)
{
final StringBuilder b = new StringBuilder("Team: ");
for (int i = 0; i < types; i++)
{
// Carry over if needed.
if (i + 1 < types && combo[i] >= maxPerType)
{
combo[i + 1]++;
combo[i] %= maxPerType;
}
if (combo[i] >= champs[i].length) continue next;
b.append(champs[i][combo[i]]).append(' ');
}
System.out.println(b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment