perlquestion
Limbic~Region
All,
<br />
The formula to determine the number of combinations (C) from a group of items (N) when choosing a fixed number of items at a time (K) is C = N! / K! * (N - K)!
<p>
So if I had a list of 5 items and I chose 2 at a time, I would have 10 combinations 120 / 2 * 6
</p>
<CODE>
ABCDE = AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
</CODE>
<p>
Assuming:
<ul>
<li>1. The total number of items N is known</li>
<li>2. The number at a time K is known</li>
<li>3. The number of combinations C is known</li>
<li>4. All items of N are unique</li>
<li>5. All items of N are in ascending order</li>
<li>6. Combinations will be generated as shown above (or the reverse as shown above)</li>
</ul>
It should be possible to use a bitstring the size of C to represent each combination. My question is what algorithm could I use to convert say 'CD' to 8 (or 7 if 0 based) and flip that bit. The converse algorithm (taking the bit and obtaining the combination) is not needed but feel free to have fun.
</p>
<div class="pmsig"><div class="pmsig-180961">
<p>
Cheers - [Limbic~Region|L~R]
</p>
</div></div>