When you have a set of objects S, and you want to build efficient mappings between S and {1, ..., |S|} that preserve some ordering over S (say, lexicographic ordering on S corresponds to ascending order in the integers), you're looking for
ranking & unranking algorithms.
You can find ranking/unranking algorithms for combinations in this node: Re: Sampling from Combination Space. It's just an implementation of algorithms I found in a textbook (source given in that node). I believe the ranking is with respect to lexicographic ordering, but I don't remember for sure. (In that thread, the ordering of the combinations was irrelevant) Also the textbook probably has implementation details (like running time complexity). It may not be online anymore, but if you want I can send you a copy of my PDF.
Hopefully this does what you need, or at least gives you a place to start. You'll certainly have to adapt it to use alphabet A..Z instead of 1..26, and get the off-by-one things the way you need.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.