Created
July 8, 2017 17:40
-
-
Save KevinTyrrell/094aa37a0430188e141da6764e870522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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