I have an array which is for example of a length of 4 elemnts
no I want to know how to calculate the possible combinations when using 3 digets out of it.
eg:
3 6 2
3 6 8
6 2 8
8 3 2
my array is : 3 6 2 8
there are 4 possibilitys, but how can I count them programaticly ?
Well, it seems that what you are actually looking for is
Choose(n,k), which is the number of ways to chosekelements out ofncandidates.The formula for it is basically
Choose(n,k) = n! / (k! * (n-k)!)The rational behind it is:
Number of ways to sort
nitems (n! possibilities) and then choose firstk. After you have chosen you don’t care for the order of the firstkitems (k!possibilities) and the lastn-kitems ((n-k)!possibilities).In your example,
Choose(4,3) = 4!/(3!*1!) = 4, as expected.