Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compositions #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Compositions #142

wants to merge 3 commits into from

Conversation

densmojd
Copy link

@densmojd densmojd commented Sep 27, 2023

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
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

All modified lines are covered by tests ✅

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%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant