How to calculate the max. number of combinations possible?

30,326

Solution 1

This is not a combination but permutation. The algorithm is n! where n is the number of elements.

Why ?

Because you have 3 values to place on three places, so for the first place You have three option, for second only two (becuase You already palace first string) and at the end You have only one option.

3 * 2 * 1 = 3! = 6

But if You can repeate those chooses than you have permutation with repetition

So for first place You can chose from 3 string and for the second also and so one

3 * 3 * 3 = 3^3 = 27

n^k - where n is the number of strings and k - the number of "locations"

And the code algorithm look like this:

function fact($n)
{
  if ($n == 0)
  {
    return 1;
  }
  else
  {
    return $n * fact($n - 1);
  }
}

This is a recursive example

Solution 2

If I remember correctly it's n! combinations.

so for 9 you would have

9*8*7*6*5*4*3*2 = 362880 combinations

Share:
30,326
gregory boero.teyssier
Author by

gregory boero.teyssier

https://ali.actor

Updated on July 09, 2022

Comments