Given an input of a list of days of the week, output the shortest sorted representation of the list.
The format of the input is a string consisting of one or more of the
two-character substrings Su
(Sunday), Mo
(Monday), Tu
(etc.), We
, Th
,
Fr
, and Sa
. The input may not necessarily be given in sorted order.
To convert the input to the output format,
Sort the input by day of week, starting from Sunday (ex.
ThMoSaSuFrTuWe
->SuMoTuWeThFrSa
).Reduce the abbreviations down to one letter if it leaves no ambiguity. For example,
SuMoTuWe
should becomeSMTW
because the first S couldn't possible be Saturday, as that would make the output unsorted (same for the T). However,ThFrSa
should becomeThFS
, as both Tuesday and Thursday come before Friday and reducing it down toTFS
would create ambiguity.If the output is now
MTWTF
, outputD
instead (which stands for "weekdays"). Similarly,SS
should becomeE
for weekend. Finally,SMTWTFS
should becomeA
for all days.
The input and output must both be a single string.
Since this is code-golf, the shortest code in bytes wins.
Test cases:
In Out | In Out
-----------------------|--------------------
SuTu STu | SuTuWe STW
SuTuSa STuS | SuWeTh SWT
TuThSa TTS | TuThSu STT
Su Su | Sa Sa
WeTh WT | FrTh ThF
WeTu TW | FrTu TuF
FrWeMo MWF | SaWeSu SWS
ThTu TT | We W
ThTuMoFrWe D | SaSu E
SuMoWeTuThFr SMTWTF | ThMoSaSuFrTuWe A