K
K
kr_ilya2020-05-20 13:19:49
Python
kr_ilya, 2020-05-20 13:19:49

How to get the number of possible combinations of elements with repetitions?

There is a string of 64 characters, you need to get the number of all possible combinations of these characters, 14 elements each.
For simplicity, I understand, let's take the string ABC and make all possible combinations of 3 elements from it

What will happen

AAA
AAB
AAC
ABA
ABB
ABC
ACA
ACB
ACC
BAA
BAB
BAC
BBA
BBB
BBC
BCA
BCB
BCC
CAA
CAB
CAC
CBA
CBB
CBC
CCA
CCB
CCC

Total 27 combinations
Same in python
import itertools
for i in itertools.product('ABC', repeat=3):
  print(''.join(i))


But I need to get the count of all combinations.
For this I did the following
q = 0
for i in itertools.product('ABC', repeat=3):
  q+=1
print(q)

Everything works fine, but when I tried to do the same for the string
_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

And to generate not 3 elements, but 14 each, then the script started to run for an insanely long time.
(I waited 1.5 minutes and knocked out). I'm assuming this is because the script generates combinations.

Then I found a calculator . But for the example with the string ABC and 3 elements, he brought out only 10 combinations. (Apparently he counts without repetitions or somehow, without a clue)

So I would like to ask if there is any script (optionally in Python, you can use node, php) or a formula by which you can calculate the number of combinations with repetitions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-05-20
@kr_ilya

basics of combinatorics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question