log2.c 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <assert.h>
  2. #include <stdio.h>
  3. typedef unsigned long long ullong;
  4. char seen[64];
  5. ullong rbg = 0x1e0298f7a7e;
  6. int
  7. bit()
  8. {
  9. int bit;
  10. bit = rbg & 1;
  11. rbg >>= 1;
  12. return bit;
  13. }
  14. int
  15. search(ullong n, int b, ullong *out)
  16. {
  17. int i, x;
  18. ullong y, z;
  19. if (b == 64) {
  20. *out = n;
  21. return 1;
  22. }
  23. x = 63 & ((n << (63 - b)) >> 58);
  24. assert(!(x & 0) && x <= 62);
  25. y = bit();
  26. for (i=0; i<2; i++) {
  27. z = x | (y << 5);
  28. if (!seen[z]) {
  29. seen[z] = (63-b)+1;
  30. if (search(n | (y << b), b+1, out))
  31. return 1;
  32. seen[z] = 0;
  33. }
  34. y ^= 1;
  35. }
  36. return 0;
  37. }
  38. int
  39. main()
  40. {
  41. ullong out;
  42. int i;
  43. if (search(0, 0, &out)) {
  44. printf("0x%llx\n", out);
  45. for (i=0; i<64; i++) {
  46. printf((i&7) == 0 ? "\t" : " ");
  47. printf("%2d,", seen[i]-1);
  48. if ((i&7) == 7)
  49. printf("\n");
  50. }
  51. } else
  52. puts("not found");
  53. }