Question: How to find the English word that has a value closest to 1000000 if multiply its letters as a = 1...z = 26? Use a standard substitution cipher where a = 1...z = 26.  Find the English word that produces a value closest to 1 million when you multiply the letters together.

Answer: If you have access to a good source of words (ie. an\nentire on-line dictionary would be nice), you can simply\nuse brute force to search it.  I just used the rather\nmeager dictionary supplied on any Unix (/usr/dict/words)\nand discovered "Nicaragua" at 1000188.\n\nN=14 i=9 c=3 a=1 r=18 a=1 g=7 u=21 a=1\n\nThis is the same value as reported by a previous answer,\nalthough this word has the advantage that it shows up\nin the on-line dictionaries I tried, for example, the\nAmerican Heritage, at:\n\nhttp://education.yahoo.com/reference/dictionary/;_ylt=Aji3tkPEAxeRNiQ3Q7xKXfP0HYkC\n\nMy brute force search code follows:\n\n\n\n\n\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <ctype.h>\n\nstatic int\nvalue(char* wordbuff)\n{\n  int value = 1;\n  for (char *p=wordbuff; *p && (*p!='&#92;n'); p++) {\n    if (isalpha(*p))\n      value *= (tolower(*p) - 'a' + 1);\n  }\n  return value;\n}\n\nint\nmain(int argc, char* argv[])\n{\n  char wordbuff[100], bestword[100];\n  int bestvalue = 0;\n  char *filestr = argc>1 ? argv[1] : "/usr/dict/words";\n\n  FILE *f = fopen(filestr, "r");\n  if (!f)\n    perror("fopen"), exit(-1);\n\n  while (fgets(wordbuff, sizeof(wordbuff), f) != 0) {\n    int v = value(wordbuff);\n    if (abs(v - 1000000) < abs(bestvalue - 1000000)) {\n      strlcpy(bestword, wordbuff, sizeof(bestword));\n      bestvalue = v;\n    }\n  }\n  printf("%d for the word %s", bestvalue, bestword);\n  for (char *p=bestword; *p && (*p!='&#92;n'); p++) {\n    if (isalpha(*p))\n      printf("%c=%d ", *p, tolower(*p)-'a'+1);\n  }\n  printf("&#92;n");\n  return 0;\n}
This question from the Yahoo Q&A forum is categorized in the topic: Society & Culture