//-------------------------------------------------------------------------- // enigma1371.c (c) 2006 by Charles Petzold // // "Odd Big Base" by Susan Denham, New Scientist, 17 December 2005, page 52 // // ODD, BIG, BASE, NAB, and PRIME are all numbers in a base where letters // continue after the decimal digits. At least two are prime. // What is the base? // // Well, it's at least 29 (for the 'S') but not more than 36 (when we run // out of letters. //-------------------------------------------------------------------------- #include #include int ToDecimal(char * pNum, int base) { static char * digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char ch; int num = 0; while ((ch = *pNum++) != 0) num = base * num + strchr(digits, ch) - digits; return num; } int IsPrime(int i) { int j = 2; if (i < 2) return 0; while (j * j <= i) { if (i % j == 0) return 0; j += 1; } return 1; } int main(void) { static char * words[] = { "ODD", "BIG", "BASE", "NAB", "PRIME" }; int base, i, numprimes; for (base = 29; base <= 36; base++) { for (numprimes = 0, i = 0; i < sizeof(words) / sizeof(words[0]); i++) numprimes += IsPrime(ToDecimal(words[i], base)); if (numprimes > 1) printf("Base %i\n", base); } }