Home
jcombinatorics is a library written in Java that provides permutations and combinations generators and utility functions.
Generating Permutations
for (int[] permutation : Permutations.of(2, 3, 7)) {
System.out.println(Arrays.toString(permutation));
}
Outputs:
[2, 3, 7]
[2, 7, 3]
[3, 2, 7]
[3, 7, 2]
[7, 2, 3]
[7, 3, 2]
for (int[] permutation : Permutations.of(2, 3, 7)) {
System.out.println(Arrays.toString(permutation));
} [2, 3, 7]
[2, 7, 3]
[3, 2, 7]
[3, 7, 2]
[7, 2, 3]
[7, 3, 2]Generating Combinations
for (String[] combination : Combinations.of("a", "b", "c", "d", "e").take(3)) {
System.out.println(Arrays.toString(combination));
}
Outputs:
[a, b, c]
[a, b, d]
[a, b, e]
[a, c, d]
[a, c, e]
[a, d, e]
[b, c, d]
[b, c, e]
[b, d, e]
[c, d, e]
for (String[] combination : Combinations.of("a", "b", "c", "d", "e").take(3)) {
System.out.println(Arrays.toString(combination));
} [a, b, c]
[a, b, d]
[a, b, e]
[a, c, d]
[a, c, e]
[a, d, e]
[b, c, d]
[b, c, e]
[b, d, e]
[c, d, e]