Php script to know how many possible combinations it is possible to have

Asked

Viewed 367 times

1

I would like to create a simple script, just to know number of possible combinations.

It would not be to see the list of combinations, but only how many digits you can have, and the numbers and letters can be rethought. Ex:

$Valores = "1, 2"; 
$Digito  = 2; //Quantidade de dígitos.

echo $Resultado = 6; //Possíveis combinações 1,2,12,21,22,11
  • Tiago, if I’m not mistaken, this is Combinatorial Analysis Algorithm. I’m sorry if I’m wrong. Have you checked if some of these questions attend to you?

  • @pss1support yes, it’s not the same thing.

  • @Maniero, how a direct question can get wider?

  • It is true, nor can it be broad, it is out of scope as [help/on-topic]

  • @Maniero, what is out of scope?

  • 1

    That’s math, just do it qnt_valores ^ qnt_digitos (pow() in the case of PHP) for each digit amount. Perhaps there is another way...

  • But the possible combinations have to have all the digits filled ? By your example it seems not. If you have to have it all filled out is as already said in comments: pow(count(explode(',',$Valores)),$Digito)

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.