
#include "comb/perm-rev2.h"

#include "comb/comb-print.h"
#include "comb/mixedradix.h"

#include "fxtio.h"
#include "demo/nextarg.h"
#include "fxttypes.h"
#include "jjassert.h"


//% Permutations by prefix reversions, CAT algorithm.

//#define TIMING // uncomment to disable printing



int
main(int argc, char **argv)
{
    ulong n = 4;
    NXARG(n, "Number of elements to permute n>0");
    jjassert( n>0 );
    bool dfz= true; // whether to print dots for zeros

    perm_rev2 P(n);
    P.first();

    ulong ct = 0;
    ulong e;
    do
    {
        ++ct;
#ifndef TIMING
        cout << setw(4) << ct << ":";
        P.print("    ", dfz);
//        print_mixedradix("    ", P.d_+2, n-3, dfz);
        cout << endl;
#endif
        e = P.next();
    }
    while ( e!=n );


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

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

/*
Timing:

 time ./bin 13
./bin 13  24.07s user 0.04s system 100% cpu 24.099 total
 ==> 13!/24.07 == 258,704,644 per second
 == 8.5 cycles per update

fix-arrays:
 time ./bin 13
./bin 13  32.94s user 0.06s system 100% cpu 32.992 total
 ==> 13!/32.94 == 189,041,311 per second


BENCHARGS=13

*/

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

