Say my list is
{1,2,3,4}
My title may not be descriptive enough but here is what i want to do..
I want my code to generate the following
{ (1,2) , (3,4) }
{ (1,3) , (2,4) }
{ (1,4) , (2,3) }
{ (2,1) , (4,3) }
{ (3,1) , (4,2) }
{ (4,1) , (3,2) }
i.e i want all the 4C2 combinations of the set.
Note: here the initial four elements is just an illustrative number.. the number may vary uptill 8 or 10.
Now, how do i write the code for it (in C or php).
Basically, i want to know the algorithm. not the whole of it., even a headstart will be good enough..
I just cant think of anything to start from.
Kindly help.
Thanks.
I guess i did not explain it well; actually i did not get the problem myself.
what i want is that, say i have 4 teams and i want to play every team against the other then how do i generate all the fixtures.
in my example above; considering 1,2,3,4 as 4 teams. and
{(1,2), (3,4)} as a set of fixtures and so on.
how do i do this.
hence what i need is to generate all the NC2/ (N/2) set of fixtures. (N=4 in this case)
If you want a headstart, the Python docs show the algorithm used for its implementation of a combinations function. Replace the range() with a plain for-loop and the yield with a printf and it should be easy to translate into C or PHP: http://docs.python.org/library/itertools.html#itertools.combinations
Note the combinations of four things taken two at a time yields:
(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4). Your sample output also includes the complement of each (i.e.(1, 2)is accompanied by(3, 4)).