in reply to Re^8: Odometer pattern iterator (in C).
in thread Odometer pattern iterator (in C). (Updated.)

You cannot do this inplace:

for( j = i+1; j < M; ++j ) idx[ i ] += N - idx[ M - j + i ];

as you are overwriting values that are still needed. This corresponds to the "reversing" the string part of the regex. In addition, you misread the formula, there is no += involved.