Post your dubs-checking algorithms. We have a lot spread out but it might be nice to collect all the good ones in a single thread. Revised version of an earlier one I wrote:
/* Actual dubs checking: four lines of code. */ int check(int num, int base) { int count = 0, digit = num % base; while (num % base == digit) { count++; num /= base; } return count; } void print_(int num, int b) { int n = 0; do { n++; }while(num/=b); int i = n; for(; i > 2; i--) { putchar(alphabet[num/(int)pow(b,i) % b]); } } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s <postnum>\n", argv[0]); return 1; }
int postnum = atoi(argv[1]), base, result;
if (postnum <= 0) { fprintf(stderr, "Invalid post number: %s\n", argv[1]); return 1; }
for (base = 2; base < postnum && base < MAX_BASE; base++) { result = check(postnum, base); if (result < 2) continue;
if (result >= 10) { printf("* %ds in base %d: ", result, base); } else { printf("* %s in base %d: ", names[result], base); }