So I have been researching how to take n items, r at a time. Speed is important as right now my processor is the bottle neck, not the hard drive (to my surprise).
So right now my n is: H, B, C, N, P, O, S, Se, F, Cl, Br, I, F
and i want to take it 5 at a time.
I looked up the fastest way to do this an stumbled upon programming god Donald Knuth's algorithm of combinations in C, listed below.
Problem is I can't figure it out and documentation I can understand is scarce. His "art of computer programming" book is way to technical for me.
First off, it is a void main, so it doesn't even compile for me, even if i change it to int and return 0.
Second, is the "visit:" etc actually code? I commented it out because I didn't think it is or never came across it.
Thanks!
Code:#include <stdio.h>
#include <stdlib.h>
void main(void)
{
int i, j=1, k, n, *c, x;
printf( "Enter n,k: ");
scanf( "%d,%d", &n, &k);
c = malloc( (k+3) * sizeof(int));
for (i=1; i <= k; i++)
{
c[i] = i;
c[k+1] = n+1;
c[k+2] = 0;
j = k;
}
/*
visit:
for (i=k; i >= 1; i--) printf( "%3d", c[i]);
printf( "\n");
if (j > 0) {x = j+1; goto incr;}
if (c[1] + 1 < c[2])
{
c[1] += 1;
goto visit;
}
j = 2;
do_more:
c[j-1] = j-1;
x = c[j] + 1;
if (x == c[j+1]) {j++; goto do_more;}
if (j > k) exit(0);
incr:
c[j] = x;
j--;
goto visit;
*/
}