
#include "comb/mixedradix-gslex.h"

#include "aux1/copy.h" // fill()

#include "demo/nextarg.h" // NXARG()
#include "fxttypes.h"
#include "fxtalloca.h"
#include "fxtio.h"
#include "fxtiomanip.h"
#include "jjassert.h"

//% Mixed radix numbers in gslex (generalized subset lex) order.

//#define TIMING // uncomment to disable printing

int
main(int argc, char **argv)
{
    ulong n = 3;
    NXARG(n,"Number of digits");

    ulong rr = 4;
    NXARG(rr, "Base (radix) of digits (0==>falling factorial, 1==>rising factorial)");

    ALLOCA(ulong, r, n);
    fill(r, n, rr);
    RESTARGS("Optionally supply radix for all digits (rr ignored)");
    if ( argc>3)  jjassert( argc == (int)n+3 );
    for (ulong k=3;  k<(ulong)argc; ++k)  r[k-3] = atol(argv[k]);

    mixedradix_gslex M(n, rr, (argc>3? r:0) );
    M.print_nines("Nines: ");
    cout << endl;

//    M.last();
    ulong ct = 0;
    do
    {
#ifndef TIMING
        cout << " " << setw(4) << ct << ":  ";
        M.print("    ", 1 );
        cout << setw(6) << M.to_num();
        cout << endl;
#endif // TIMING
        ++ct;
    }
    while ( M.next() );
//    while ( M.prev() );

    cout << " ct = " << ct << endl;

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

/*
Timing:
 time ./bin 30 2  ## binary is worst case
 ct = 1073741824
./bin 30 2  8.72s user 0.04s system 99% cpu 8.768 total
 ==>  1073741824/8.72 == 123,135,530 second

 time ./bin 16 4
 ct = 4294967296
./bin 16 4  21.69s user 0.11s system 99% cpu 21.803 total
 ==>  4294967296/21.69 == 198,016,011 per second

 time ./bin 10 8
 ct = 1073741824
./bin 10 8  4.83s user 0.03s system 99% cpu 4.866 total
 ==> 1073741824/4.83 == 222,306,795 per second

 time ./bin 8 16
 ct = 4294967296
./bin 8 16  15.71s user 0.08s system 99% cpu 15.790 total
 ==>  4294967296/15.71 == 273,390,661 per second

*/

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

