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

Add combinatorial generation algorithms #607

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

Conversation

danielsword
Copy link

This PR is intended to satisfy some of the requests made in #485.

What's there:

  • Methods for:
    • Generating all combinations for a given set and subset size, without replacement.
    • Generating all permutations for a given set, without replacement.
    • Inverting a permutation.
  • Some tests.

Missing:

  • Variations
  • Repetitions

I'm happy to work on the missing pieces, but would appreciate any feedback first!

@danielsword
Copy link
Author

I'm specifically (and very) interested in any feedback related to some of the comments in the code about lazy evaluation.

For example:

var permutations = Combinatorics.GenerateAllPermutations(n).ToList();

is just going to end disastrously for anybody who tries it.

@eriove
Copy link
Contributor

eriove commented Nov 22, 2018

I've experienced the same problem with IEnumerable's that shouldn't be enumerated from end to end. One way of solving it would be to return a concrete type with an implementation of ToList() which throws an exception for larger numbers of permutations. That would at least prevent the most causal mistakes. That also gives you the opportunity to use Debugger Display Attributes to prevent the enumeration to crash Visual Studio when the watch window tries to enumerate the permutations.

@cdrnet cdrnet added this to the v5 milestone Mar 6, 2022
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.

3 participants