I’m trying to make a computer RPG. I wish to allow party switching. I figured out a way to do it, but I’m not sure if it’d be worth the effort. To figure this out I decided to calculate the number of possible parties. After doing it, I realised - I’d forgotten how to do that. The only way I could remember [n*(n-1)*(n-2)] gave a total that counted ABC and CBA (etc) as separate groups.
But, for my purposes, they’re identical.
Could somebody remind me of the formula to calculate that, which I’ve forgotten in the 7 years since I last took math?
I don’t quite understand the background, but I think you’re asking “How many ways can I choose a group of 3 out of 10 (order doesn’t matter.)” Check out http://mathworld.wolfram.com/BinomialCoefficient.html which describes exactly this. Hopefully whatever you’re programming in will include a binomial function, if you need it.
The number of combinations is given by 22! / ( 3! * ( 22 - 3 )! ). ! is an operator called the factorial. I can’t think of how to word it, so I’ll show you:
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
n! = n * (n-1) * (n-2) * … * 1
The formula is this:
The number of combinations (where order is irrelevant) of r elements selected from a set of n units is given thus: [sub]n[/sub]C[sub]r[/sub] = n! ÷ ( r! * ( n - r )! )
The number of permutations (where order is relevant) of r elements selected from a set of n units is given thus: [sub]n[/sub]P[sub]r[/sub] = n! ÷ ( n - r )!
I missed it down there. Sorry. No slight intended.
And you are of course correct. I intended no slight on your method. It’s not something I would’ve deduced, as I am not particularly mathematically-inclined. I just wanted to provide him a way to have a computer or calculator figure it out.
Oh, no offense taken. It’s just that I too always forget these simple statistics formulas, so I write down a small group of numbers (in my case, I started with five) and wrote down the three-number combos possible from this. I noticed it went (3+2+1) + (2+1) + (1). So then I extrapolated.
Like I said, not the best method by any stretch, but reasonable if you’ve completely blanked on how to do it.