
#include "comb/debruijn.h" // class debruijn
// demo-include "comb/necklace.h"

#include "mod/ipow.h"
#include "fxttypes.h"
#include "fxtio.h"
#include "jjassert.h"

#include "demo/nextarg.h"

//% Generating De Bruijn sequences.

int
main(int argc, char **argv)
{
    ulong m = 3;
    NXARG(m, "m-ary De Bruijn sequence")
    ulong n = 4;
    NXARG(n, "length = m**n")

    debruijn S(m, n);
    ulong ns = ipow(m, n);
    cout << "\n n = " << n
         << "  length = " << ns
         << ":" << endl;

    ulong i = S.first_string();
    do
    {
        cout << " ";
        for (ulong u=1; u<=i; ++u)  cout << S.a_[u];  // note: one-based array
        i = S.next_string();
    }
    while ( i );
    cout << endl;

    i = S.first_digit();
    ulong ct = 0;
    do
    {
        ++ct;
        cout << i;
        i = S.next_digit();
    }
    while ( i!=m );
    cout << endl;
    cout << " ct=" << ct << endl;
    jjassert( ct == ns );

    return 0;
}
// -------------------------

/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/comb"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/comb/debruijn-demo.cc"
/// make-target2: "1demo DSRC=demo/comb/debruijn-demo.cc DEMOFLAGS=-DTIMING"
/// End:

