0

I'd like to generate all possible unique combinations of a set of characters. For example, with the set [a,b], we'd get [[a,a],[a,b],[b,b]]. I've been looking to find even a formula giving me the number of possibilities, without success... Is it possible ? Of course I could bruteforce the answer, but that's not efficiency, nor even possible once we start ramping up the numbers.

Thanks for your time.

ouai
  • 1
  • 1
    It looks like you're asking for the number of solutions to "Sum of $n$ non-negative integers is $n$'. Can you take it from here? – Calvin Lin Nov 20 '20 at 19:02

1 Answers1

0

I think you are looking for the formula for the number of combinations (order matters) with repetition of elements, where the number of objects chosen is the same as number of objects given. This is given by $\frac{(k+n-1)!}{(k)!(n-1)!}$. When they are equal you can just reduce this to $\frac{(2n-1)!}{n!(n-1)!}$, which for $n=2$ (like with the example you posted) is $\frac{3!}{2!1!} = 3$.