
#include "comb/perm-involution.h"

#include "perm/permq.h"

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


//% Generate all involutions (self-inverse permutations).

//#define TIMING // uncomment to disable printing


int
main(int argc, char **argv)
{
    ulong n = 5;
    NXARG(n, "Self-inverse permutations of n elements.");
    bool dfz= true; // whether to print dots for zeros

    perm_involution P(n);
    ulong ct = 0;

#ifdef TIMING
    while ( P.next() )  { ++ct; }

#else

    const ulong *x = P.data();
    do
    {
        cout << setw(4) << ct << ":";
        ++ct;

        P.print("  ", dfz);
        cout << endl;

        jjassert( is_involution( x, n) );
    }
    while ( P.next() );
#endif
    cout << " ct=" << ct << endl;

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

/*
Timing:
 time ./bin 18
arg 1: 18 == n  [Permutations of n elements.]  default=4
 ct=997313823
./bin 18  19.97s user 0.04s system 99% cpu 20.061 total
 ==> 997313823/19.97 == 49,940,602  permutations per second
*/


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

