9 char buf
[50000]; // cheat, pre-inspect file
11 extern uint64_t doit(uint64_t);
14 output (uint64_t array
)
17 for (int i
= 0; i
< 16; i
++)
18 out
[i
] = ((array
& (0xfULL
<< ((15 - i
) * 4))) >> ((15 - i
) * 4)) + 'a';
22 int main(int argc
, char **argv
)
24 int limit
= 1000000000;
26 limit
= atoi (argv
[1]);
32 fread (buf
, 1, sizeof buf
, stdin
);
33 printf ("#include <stdint.h>\n");
34 printf ("uint64_t doit(uint64_t n)\n");
37 printf (" uint64_t a, b;\n");
43 sscanf(s
, "%d%n", &a
, &n
);
45 printf (" // s%d\n", a
);
46 printf (" n = (n >> %d) | (n << %d);\n", a
* 4, 64 - a
* 4);
50 sscanf(s
, "%d/%d%n", &a
, &b
, &n
);
52 printf (" // x%d/%d\n", a
, b
);
58 printf (" a = (n & (0xfULL << %d)) >> %d;\n",
59 (15 - a
) * 4, (b
- a
) * 4);
60 printf (" b = (n & (0xfULL << %d)) << %d;\n",
61 (15 - b
) * 4, (b
- a
) * 4);
62 printf (" n = (n & %#llx) | a | b;\n",
63 -1ULL ^ (0xfULL
<< ((15 - a
) * 4)) ^
64 (0xfULL
<< ((15 - b
) * 4)));
68 sscanf(s
, "%c/%c%n", &x
, &y
, &n
);
70 printf (" // p%c/%c\n", x
, y
);
73 printf (" for (i = 0; i < 64; i += 4) {\n");
74 printf (" if (((n & (0xfULL << i)) >> i) == %d)\n", x
);
75 printf (" n = (n & ~(0xfULL << i)) | (%dULL << i);\n", y
);
76 printf (" else if (((n & (0xfULL << i)) >> i) == %d)\n", y
);
77 printf (" n = (n & ~(0xfULL << i)) | (%dULL << i);\n", x
);
82 printf (" // %d ops\n", ops
);
83 printf (" return n;\n");
87 uint64_t array1
= 0x0123456789abcdefULL
;
88 uint64_t array2
= 0x0123456789abcdefULL
;
90 for (j
= 0; j
< limit
; j
++) {
92 printf ("after dance %d: %s\n", (cycle
? j
: j
* 2), output (array1
));
94 printf ("\b\b\b\b\b\b\b\b\b\b\b\b%10d", j
), fflush (stdout
);
95 array1
= doit (array1
);
96 if (!cycle
&& j
< limit
) {
97 array1
= doit (array1
);
98 array2
= doit (array2
);
99 if (array1
== array2
) {
100 printf ("cycle detected at %d\n", j
);
101 j
= limit
- limit
% (j
+ 1) - 1;
106 printf ("\nfinal string: %s\n", output (array1
));