2014-09-14

File Numbering

In some ways, Bengt is an old-fashioned fellow, and he has thus far kept all his "information", as he says, in little notebooks. Let's not even ask what that information is about. The notebooks are very pretty, but now he has started moving things to the computer. That means he has an ever-growing list of files, quite a few of them. Being the rational type, he gives each file a number as filename. The problem is, the computer lists the files alphabetically, not numerically. So 11 comes before 2, etc. Very annoying! One option is of course to use preceding zeros, something like "001", "002", etc. We could easily calculate how many zeros Bengt would need to guarantee the system working for the rest of his life, but we're not going to bother, because we know Bengt would never settle for such a compromise. He wants a system that lasts forever. We could solve that with something as simple as unary numbers - that is, "1", "11", "111"... But that would mean very quickly getting impractically long filenames, so we can't do that.

To summarise, what we need is a method that uses a finite number of symbols, to form an infinite non-repeating list of strings, where the strings are in alphabetical order. But we also need the length of the strings to be logarithmic, just like for ordinary numbers. How can that be done?