Combinatoric Algorithms for Perl 6
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a WIP combinatorics library for Perl 6.

The goal of this module is to be something similar to Perl 5's Algorithm::Combinatorics, but implemented in NQP for fast performance. If you need combinatoric functions now, I'd recommend using that module via Inline::Perl5 if you can.

I'm happy to accept pull requests for more algorithms, even in pure Perl 6. I - or others - can always work towards translating them to NQP later.


This is a WIP module. Names and functions will change. Until this module is officially released, rely on this module in production at your own risk.



Also known as 'combinations with replacement', 'combinations with repetition', 'k-multicombinations', or 'multisubsets'

say multicombinations(<A B C D>, 2);
# OUTPUT: ((A A) (A B) (A C) (A D) (B B) (B C) (B D) (C C) (C D) (D D))


Also known as 'k-permutations of n', 'n choose k', 'partial permutations', or 'sequences without repetition'

say variations(<A B C D>, 2);
# OUTPUT: ((A B) (A C) (A D) (B A) (B C) (B D) (C A) (C B) (C D) (D A) (D B) (D C))