Abbreviations and acronyms are great when you want to save space (or typing). There exists a plethora of commonly used abbreviations in most languages and most people recognise and read them without any problems. But how do you best shorten a new name or phrase?
The Problem
We have a collection of drug descriptions, typically not more than a dozen distinct items. We need to create all combinations of these items and give them suitably short names. For example, given the set:
ALPHA
BETA
GAMMA
We could simply pick the first letter of each item to form the 7 distinct combinations:
A
B
G
AB
AG
BG
ABG
In the previous example all items were formed of a single word and they all started with different letters, so it is easy to identify which items are included in any given combination. Below are some examples of drug descriptions manually created by inspecting the source data:
HUMIRA
ENBREL
ORENCIA
KINERET
CIMZIA
SIMPONI
REMICADE
RITUXAN
ACTEMRA
XELJANZ
And the following set is also manually named variations of a single drug:
ADCIRCA QD
ADCIRCA NOT SPEC
ADCIRCA TID
ADCIRCA BID
ADCIRCA OD
But the source data can be really ugly, so it may look like this:
12 HOUR ANTIHIST/DECONGESTANT
12 HOUR NASAL RELIEF SPRAY
2 LITERS OF OXYGEN AT NIGHT
A THRU Z SELECT ORAL TABLET
A-METHAPRED 125 MG INJECTION SOLUTION RECONSTITUTED
ABILIFY MAINTENA 300 MG INTRAMUSCULAR SUSPENSION RECONSTITUTED
ACIDOPHILUS/BIFIDUS 100 MG ORAL WAFER
ACIDOPHILUS LACTOBACILLUS 10 BU/GM POWDER
BARIATRIC ADVANTAGE CALCIUM CITRATE CHEWY BITE 500 MG
BENADRYL-D ALLERGY/SINUS
BENAFIBER
BENAZEPRIL HCL
BENEFIBER PLUS B VITS & FA
BENFOTIAMINE CAPS
BENICAR HCT 40-12.5 MG ORAL TABLET
BENIFIBER
BENTALYN/HYCODAN 50/50 SUSP
BENZAC AC WASH
BENZALKONIUM CHLORIDE 50 % EXTERNAL SOLUTION
BENZEDREX
BENZOCAINE ORAL ANESTHETIC 20 % MOUTH/THROAT SOLUTION
Given the examples above, find an algorithm that takes a set of distinct items and returns an abbreviated form for each that uniquely identifies it. Note that there is no correct answer for this exercise, the quality of the solutions will be measured visually. Example:
Abbreviate'Gilgamesh' 'Ashur' 'Athoraya'
┌───┬───┬───┐
│Gil│Ash│Ath│
└───┴───┴───┘