Answer the question
In order to leave comments, you need to log in
Number of combinations of JavaScript numbers?
How to find the number of combinations of numbers from a string from 4 to 12 characters. Condition: the number of separating points is 3, the characters between the points are from 1 to 3, the numbers do not change places. For example, String '1234'. Possible combinations: '1.2.3.4' Number of combinations = '1. The string '12345'. Possible combinations: '1.2.3.45', '1.2.34.5', '1.23.4.5', '12.3.4.5' Number of combinations = '4'
Answer the question
In order to leave comments, you need to log in
1) Use the formula from probability theory to find the number of combinations.
2) You can make a recursion. Exit from it - the number of calls is equal to the number of combinations. Add the resulting line to the tail.
In stupid it is possible to count up 2 nested cycles.
ans = 0;
for (i = 1; i <= 3; ++i) {
for (j = 1; j <= 3; ++j) {
mn = max(n - i - j - 3, 1);
mx = n - i - j - 1;
if (mn <= mx)
ans += mx - mn + 1;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question