AlistairIsrael / jcombinatorics

JCombinatorics provides useful combinatorics algorithms (permutations & combinations) and functions for Java.

Home | Edit | New

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]

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]

Last edited by AlistairIsrael, Tue Oct 13 08:23:40 -0700 2009
Home | Edit | New
Versions: