in reply to Re^7: Odometer pattern iterator (in C).
in thread Odometer pattern iterator (in C). (Updated.)
I attempted to adapt your Perl to C, but I made a mistake somewhere. I don't know if you can see the problem, but I can't and I need to move on:
U8 *firstIdx( U8 N, U8 M ) { U32 i; U8 *a = malloc( M ); for( i = N - M; i < N; ++i ) a[ i - M + 1 ] = i; return a; } U8 *nextIdx( U8 N, U8 M, U8 *idx ) { U32 i = M - 1, j; if( idx[ i ] == i ) return NULL; while( i > 0 && idx[ i ] - idx[ i - 1 ] == 1 ) i--; --idx[ i ]; for( j = i+1; j < M; ++j ) idx[ i ] += N - idx[ M - j + i ]; return idx; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: Odometer pattern iterator (in C).
by hdb (Monsignor) on May 29, 2015 at 15:12 UTC |