All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.paukov.combinatorics.util.package.html Maven / Gradle / Ivy

Go to download

Very simple java library to generate permutations, combinations and other combinatorial sequences.

There is a newer version: 2.3
Show newest version




This package contains the utility classes and tools.

It is possible to generate non-overlapping sublists of length n of a given list

For example, if a list is (A, B, B, C), then the non-overlapping sublists of length 2 will be:

  1. ( (A), (B, B, C) )
  2. ( (B, B, C), (A) )
  3. ( (B), (A, B, C) )
  4. ( (A, B, C), (B) )
  5. ( (A, B), (B, C) )
  6. ( (B, C), (A, B) )
  7. ( (B, B), (A, C) )
  8. ( (A, C), (B, B) )
  9. ( (A, B, B), (C) )
  10. ( (C), (A, B, B) )

To do that you should use an instance of the complex combination generator

  // create a vector (A, B, B, C)
  ICombinatoricsVector<String> vector = Factory.createVector(new String[] { "A", "B", "B", "C" });

  // Create a complex-combination generator
  Generator<ICombinatoricsVector<String>> gen = new ComplexCombinationGenerator<String>(vector, 2);

  // Iterate the combinations
  for (ICombinatoricsVector<ICombinatoricsVector<String>> comb : gen) {
     System.out.println(ComplexCombinationGenerator.convert2String(comb) + " - " + comb);
  }

And the result

 ([A],[B, B, C]) - CombinatoricsVector=([CombinatoricsVector=([A], size=1), CombinatoricsVector=([B, B, C], size=3)], size=2)
 ([B, B, C],[A]) - CombinatoricsVector=([CombinatoricsVector=([B, B, C], size=3), CombinatoricsVector=([A], size=1)], size=2)
 ([B],[A, B, C]) - CombinatoricsVector=([CombinatoricsVector=([B], size=1), CombinatoricsVector=([A, B, C], size=3)], size=2)
 ([A, B, C],[B]) - CombinatoricsVector=([CombinatoricsVector=([A, B, C], size=3), CombinatoricsVector=([B], size=1)], size=2)
 ([A, B],[B, C]) - CombinatoricsVector=([CombinatoricsVector=([A, B], size=2), CombinatoricsVector=([B, C], size=2)], size=2)
 ([B, C],[A, B]) - CombinatoricsVector=([CombinatoricsVector=([B, C], size=2), CombinatoricsVector=([A, B], size=2)], size=2)
 ([B, B],[A, C]) - CombinatoricsVector=([CombinatoricsVector=([B, B], size=2), CombinatoricsVector=([A, C], size=2)], size=2)
 ([A, C],[B, B]) - CombinatoricsVector=([CombinatoricsVector=([A, C], size=2), CombinatoricsVector=([B, B], size=2)], size=2)
 ([A, B, B],[C]) - CombinatoricsVector=([CombinatoricsVector=([A, B, B], size=3), CombinatoricsVector=([C], size=1)], size=2)
 ([C],[A, B, B]) - CombinatoricsVector=([CombinatoricsVector=([C], size=1), CombinatoricsVector=([A, B, B], size=3)], size=2)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy