dankogai / js-combinatorics

power set, combination, permutation and more in JavaScript
MIT License
742 stars 97 forks source link

Combination with repetition #26

Closed PhilWaldmann closed 6 years ago

PhilWaldmann commented 8 years ago

combinations with repetition are currently not supported, right? Something like that would be awesome!

Combinatorics.combinationWithRep(['a', 'b', 'c'], 4)
/*
=> [ 
  [ 'a', 'a', 'a', 'a' ],
  [ 'a', 'a', 'a', 'b' ],
  [ 'a', 'a', 'a', 'c' ],
  [ 'a', 'a', 'b', 'b' ],
  [ 'a', 'a', 'b', 'c' ],
  [ 'a', 'a', 'c', 'c' ],
  [ 'a', 'b', 'b', 'b' ],
  [ 'a', 'b', 'b', 'c' ],
  [ 'a', 'b', 'c', 'c' ],
  [ 'a', 'c', 'c', 'c' ],
  [ 'b', 'b', 'b', 'b' ],
  [ 'b', 'b', 'b', 'c' ],
  [ 'b', 'b', 'c', 'c' ],
  [ 'b', 'c', 'c', 'c' ],
  [ 'c', 'c', 'c', 'c' ] 
 ]
*/
blanchg commented 7 years ago

baseN essentially does this, just not in the order you are indicating