9 #define NUM_DIGITS 1024
11 void mpz_mper(mpz_t num
);
13 bool inc_mper(char *num
);
15 char tmp_buf
[NUM_DIGITS
] = "";
18 uint64_t best_count
= 0;
20 uint64_t digit_best_count
= 0; //what the best is
21 mpz_t digit_count
; //how many times we've hit the best
27 char guess
[NUM_DIGITS
] = "01";
30 mpz_init(digit_count
);
37 mpz_set_str(ans
, guess
, 10);
39 while(mpz_cmp_ui(ans
, 9) > 0)
45 if(count
> best_count
)
47 clock_t found
= clock();
48 double time_spent
= (double)(found
- start
) / CLOCKS_PER_SEC
;
50 printf("(%f)\t%lu steps: %s <------\n", time_spent
, count
, guess
);
53 if (count
> digit_best_count
)
55 digit_best_count
= count
;
56 mpz_set_ui(digit_count
, 1);
58 else if(count
== digit_best_count
)
60 mpz_add_ui(digit_count
, digit_count
, 1);
62 }while(inc_mper(guess
));
65 void mpz_mper(mpz_t num
)
67 int sz
= gmp_snprintf(tmp_buf
, NUM_DIGITS
, "%Zd", num
);
71 printf("\n=== can't fit num in tmp_buf! ===\n\n");
78 while(tmp_buf
[i
] != '\0')
80 mpz_mul_ui(num
, num
, tmp_buf
[i
] - 0x30);
86 bool inc_mper(char *num
)
96 printf("\n=== ran out of digits ===\n\n");
103 clock_t found
= clock();
104 double time_spent
= (double)(found
- start
) / CLOCKS_PER_SEC
;
105 //printf("(%f)\t%lu digits best: %u\n", time_spent, i+1, best_count);
107 gmp_printf("(%f) finished %lu digits. %Zd nums with count: %lu\n", time_spent
, i
, digit_count
, digit_best_count
);
108 mpz_set_ui(digit_count
, 0);
109 digit_best_count
= 0;
114 char new_num
= ++num
[i
];