0

I have multiple choice menus in my program like so:

Which option do you want? (choose one)
    f: First option
    s: Second option
    t: Third option

The user then presses f, s or t to make their choice. For this example, I picked the letters manually, and it should be obvious how.

But in some cases there are conflicts: Suppose I had a Fourth option - I can't use f. Sensible choices include F, h and others, depending on UX philosophy.

Is there an algorithm that will, given a list of strings, generate a unique mnemonic letter to identify each string? By "mnemonic", I mean that the option should suggest the letter (as in my example), so that it is easy to remember which is which (as opposed to just mapping everything to a, b, c or x, y, z).

As I noted above, there are multiple ways of doing this, depending on what you prefer: Capitalized letters, letters within the first word, letters of secondary unique words, etc. For this question, I don't really care about these, so feel free to use your own rules - so long as the algorithm produces reasonably user-friendly results.

Superbest
  • 25,318
  • 14
  • 62
  • 134
  • Tagging `hash` because I'm essentially asking for a hash function, just with very specific and somewhat unusual requirements. – Superbest Nov 13 '15 at 22:34
  • I think you will have to manually make up a set of rules like copy=c, cut=x, paste=v and this with highest precedence, then other rules follow. Most important is consistency, so you have to look at all menus at once and not isolated or you could end up assigning different letters to the same option at different places. – maraca Nov 14 '15 at 03:26

1 Answers1

1

The baseline algorithm I've seen used is the following:

  1. Pick the first letter (as in your example). Keep track of which letters you pick.
  2. When the chosen letter is taken, pick the next letter if available.
  3. If there are no more letters, then pick one lexicographically (the first free letter from the alphabet)
  4. If there are no more letters, don't pick anything, the option won't be addressable. This makes sense with menus that are also clickable.

Of course, there are tweaks you can apply:

  • does your terminal/OS convention distinguish between upper case and lower case? You can use that after step 2 and before step 3 (if there are no more letters left to use, use an upper case letter).

  • can you use and detect alt, ctrl, win?

  • are there pre-assigned shortcuts you need to maintain (e.g. s to save)? Assign them before step one.

Sklivvz
  • 30,601
  • 24
  • 116
  • 172