Avatar of Lennart Ericson
Lennart Ericson
Flag for Sweden

asked on 

how do I get all combinations of a set of constants?

Suppose we have six constants: 1 through 6.

I would like to have a formula to get all combinations of of them,

I give an example of what I mean:

1 and 2 and 3 and 4 and 5 and 6
1 and 2 and 3 and 4 and 5, but not 6
1 and 2 and 3 and 4, but not 5 and 6
...
2 and 3 and 4 and 5 and 6, but not 1
3 and 4 and 5 and 6, but not 1 and 2
...
1 and 3 and 4 and 5 and 6, but not 2
1 and 4 and 5 and 6, but not 2 and 3
...
...
I Think you've got it.

Lastly, I'd put this in a php script to get the correct combination

if(1 and 2 and 3 and 4 and 5 and 6) {  do this  }
if(1 and 2 and 3 and 4 and 5)  {  do that  }

For me this is far over my training. Could you please lead me thorugh this.

Thanks.
AlgorithmsPHP

Avatar of undefined
Last Comment
Lennart Ericson

8/22/2022 - Mon