Closed ramAdam closed 7 years ago
If you need to generate the permutations you can look at the documentation here. More details can be found in the permutation iterator class. Method next()
produces next permutation every time it is called during iterating over all permutations.
@dpaukov thanks
anyone looking for the answer to the question above may find the following answer useful
/*permutation without repetition*/
ICombinatoricsVector<String> originalVector = Factory.createVector(new String[] { "apple", "orange", "banana" });
Generator<String> gen = Factory.createPermutationWithRepetitionGenerator(originalVector, 2);
for (ICombinatoricsVector<String> perm : gen){
if( !perm.hasDuplicates()) //filters all the ones without duplicates
System.out.println( perm );
}
@ramAdam your example above will return nothing, as you try to generate 3-permutations of the 2 elements set of ("apple", "orange")
. All the permutations will have duplicates in the example. Permutations' length shouldn't be greater than the cardinality of the set.
@dpaukov you are correct, i copy pasted the code from docs, forgot to edit the elements of the set . I edited the post again, could you please check now. Thanks
is it possible to do permutation without repetition with selected objects r ? P(n , r) = n! / (n - r)!
where n is the number of things to choose from, and we choose r of them Is there any API doc available for the library?