apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.9k stars 435 forks source link

Unique combinations from a collection #183

Open peterbayerle opened 2 years ago

peterbayerle commented 2 years ago

I noticed there’s a method for counting the unique permutations of a collection - how come there is no equivalent for combinations? For example the unique combinations of length 2 of “aabc” are “aa”, “ab”, “ac”, “bc”. If others think this would be useful Id be interested in trying to implement it !

An equivalent would be more_itertools.distinct_combinations(collection, k) in Python

dabrahams commented 1 year ago

I think this is in there now. But it's misnamed. It should have "subsets" in the name (and no, it doesn't matter that it doesn't create a Set data structure).