1 // Copyright (C) 2021 Harry Godden (hgn)
4 //=======================================================================================================================
6 // Algorithm 1: Generate non-repeating combinations of size M in set of N
9 // hgn_comb_init( 3, p );
13 // something with p[0], p[1], p[2]
15 // while( hgn_comb( 3, 5, p ) );
17 // Output of p each iteration:
29 void csr_comb_init( int const M
, int p
[] );
30 int csr_comb( int M
, int N
, int p
[] );
33 //=======================================================================================================================
37 void csr_comb_init( int const M
, int p
[] )
39 for( int i
= 0; i
< M
; i
++ )
45 int csr_comb( int M
, int N
, int p
[] )
47 for( int j
= M
-1; j
>= 0; --j
)
49 if( p
[j
] < N
-(M
-j
) ) // Can J be incremented?
52 for( int k
= j
+1; k
< M
; k
++ ) // Adjust following indexes