How can I permute pairs across a set?
Posted
by
sila
on Programmers
See other posts from Programmers
or by sila
Published on 2011-11-19T08:52:57Z
Indexed on
2011/11/19
18:14 UTC
Read the original article
Hit count: 263
c#
|algorithms
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?
© Programmers or respective owner