An autogram is a sentence which describes its letters. For example, from Wikipedia:
This sentence employs two a’s, two c’s, two d’s, twenty-eight e’s, five f’s, three g’s, eight h’s, eleven i’s, three l’s, two m’s, thirteen n’s, nine o’s, two p’s, five r’s, twenty-five s’s, twenty-three t’s, six v’s, ten w’s, two x’s, five y’s, and one z.
These sentences are extremely difficult to create by hand, so surely a computer is best suited for the task, but how can this be done efficiently? What is an efficient algorithm for finding autograms with a given initial string? What about linked autograms, where the previous sentence describes the contents of the next? While this thread is about the same topic, it merely asks for existence, and all of the algorithms described there are much too slow in practice.
A naive approach would be to search through the sets of possible number combinations from, say, 0 to 40, for a possible solution. However, with 40^26 possibilities, this would take impossibly long.
We could improve our search, at the possible expense of missing a solution, by starting with some initial guess at the letter combinations, then searching only for autograms that deviate from our guess by 3 on either side. This still would take 6^26 times. Even at a million checks per second, this would take more than 5 million years to finish.
A further refinement comes from recognizing that a, b, c, d, j, k, m, p, q, and z never appear in any number-words, so those ten letters have their counts fixed by the initial string. We now have a mere 3 trillion combinations - still not great.
It might be better to start with an initial guess and...
- Create a new "autogram" which describes the letter counts of the previous autogram
- Check if we have repeated an autogram yet. If we have, and the loop is length 1, we are done. Otherwise, slightly modify the guess and go to step 1.
...but this has its fair share of limitations. Despite the seeming fruitlessness of this task, other people have found success. In fact, http://autograms.net/ even has a chain of twenty-five linked autograms. How?