How can I permute pairs across a set?
- by sila
I am writing a bet settling app in C# and WinForms. I have 6 selections, 4 of them have won. I know that using the following formula from Excel:
=FACT(selections)/(FACT(selections-doubles))/FACT(doubles)
This is coded into my app and working well: I can work out how many possible doubles (e.g., AB, AC, AD, AE, BC, BD, BE, etc.) need to be resolved.
But what I can't figure out is how to do the actual calculation. How can I efficiently code it so that every combination of A, B, C, and D has been calculated?
All my efforts thus far on paper have proved to be ugly and verbose: is there an elegant solution to this problem?