void x(void); void perm(int n, char a[n]){ // This routine permutes the n characters starting at a and for // each permutation, calls x. // The characters are finally left as they were found. char t = a[0]; int j=n; while(j--) { char u = a[j]; a[0] = u; a[j] = t; if(n<3) x(); else perm(n-1, a+1); a[j] = u;} a[0] = t;} typedef unsigned long int P; #define C const #include #include #include char u[16]; P cn = 0, cx=0; char C * C a = "0123456789abcdef"; P sw[] = {0x0123456789ABCDEF, 0x021346578A9BCEDF, 0x041526378C9DAEBF, 0x08192A3B4C5D6E7F, 0x123C485A697BDE, 0X14283A596C7DBE, 0X24356879ACBD, 0X36587A9C, 0X3456789ABC, 0}; void x(){char y[16]; memcpy(y, u, 16); P * c = sw; while(*c){P p = *(c++); while(p){int j = p&255; p >>= 8; if(j) {int k = j&15, i = j>>4; if(y[i]>y[k]){char t = y[i]; y[i] = y[k]; y[k] = t;}}}} if(memcmp(y, a, 16)) {if(0) ++cn; else { {for(int j = 0; j<16; ++j) printf ("%c%c%c ", u[j], y[j], a[j]);} exit(printf("Foo\n"));}} if(!(cx++& ((1L<<20)-1)))printf("%s %ld %ld\n", u, cx>>20, cn);} int main(){memcpy(u, a, 16); perm(16, u); printf("%ld errors\n", cn); return 0;}