Combinatorics.jl
Combinatorics.jl copied to clipboard
Compositions
This PR provides functionality for generating compositions, specifically two different types of compositions:
- (strong) compositions of n into k parts, i.e., all the arrays of k positive integers that sum to n
- weak compositions of n into k parts, i.e., all the arrays of k non-negative integers that sum to n
This PR partially addresses #101, although the composition in that case seems to be the union of all compositions of n into k parts (as defined above) over all possible k (k <= n).
The algorithm for weak compositions relies on the relationship between weak compositions and combinations (I think it comes from TAoCP, but I've long since lost the reference) and uses the existing Combinations iterator. The algorithm for compositions relies on the fact that adding one to each element of a weak composition of n into k parts yields a composition of n + k into k parts.
Codecov Report
All modified lines are covered by tests :white_check_mark:
Comparison is base (
ac70c46) 96.97% compared to head (3b3446c) 97.13%.
Additional details and impacted files
@@ Coverage Diff @@
## master #142 +/- ##
==========================================
+ Coverage 96.97% 97.13% +0.15%
==========================================
Files 7 8 +1
Lines 728 767 +39
==========================================
+ Hits 706 745 +39
Misses 22 22
| Files | Coverage Δ | |
|---|---|---|
| src/compositions.jl | 100.00% <100.00%> (ø) |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.