[Question]
  [
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 become `SMTW` because the first S couldn't
possible be Saturday, as that would make the output unsorted (same for the
T). However, `ThFrSa` should become `ThFS`, as both Tuesday and Thursday come
before Friday and reducing it down to `TFS` would create ambiguity.
* If the output is now `MTWTF`, output `D` instead (which stands for
"week**day**s"). Similarly, `SS` should become `E` for week**end**. Finally,
`SMTWTFS` should become `A` for **all** days.
The input and output must both be a single string.
Since this is [code-golf](/questions/tagged/code-golf "show questions tagged '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
```
  
[Answer]
# [Retina](https://github.com/mbuettner/retina), 152 88
Massively golfed with @Martin's and @randomra's help! Thanks both of you!
```
^
SuMoTuWeThFrSa
([A-Z].)(?!.*\1)
T`l``Su\B|\BSa|o|r|u?We.?.?|uTh
^MTWTF$
D
SS
E
.{7}
A
```
[Try it online.](http://retina.tryitonline.net/#code=bWBeClN1TW9UdVdlVGhGclNhCihbQS1aXS4pKD8hLipcMSkKClRgbGBgU3VcQnxcQlNhfG98cnx1P1dlLj8uP3x1VGgKbWBeTVRXVEYkCkQKU1MKRQouezd9CkE&input=U3VUdQpTdVR1U2EKVHVUaFNhClN1CldlVGgKV2VUdQpGcldlTW8KVGhUdQpUaFR1TW9GcldlClN1TW9XZVR1VGhGcgpTdVR1V2UKU3VXZVRoClR1VGhTdQpTYQpGclRoCkZyVHUKU2FXZVN1CldlClNhU3UKVGhNb1NhU3VGclR1V2U) A couple of the lines start with `m``  with this online interpreter link. This is so the program works with multiple input lines (to run all tests in one shot). However, multiple input lines is not a requirement, so these are not included above or in my score.
[Answer]
# JavaScript (ES7), ~~187~~ ~~178~~ ~~168~~ ~~157~~ 143 bytes
```
x=>({SMTWTFS:'A',SS:'E',MTWTF:'D'}[x=[for(a of'Su M Tu W Th F Sa'.split` `)if(x.match(a))x.match({S:/.../,T:/W|T.*T/}[b=a[0]])?b:a].join``]||x)
```
The regex tests helped make quick work of the special day rules, and while less than ideal, the object map does it's work. I'm certain I can squeeze a few more out of this though.
[Answer]
# Python 3, 321 Bytes
```
def w(n,a=lambda b,c,d:b.replace(c[0],d).replace(c[1],d)):d=''.join([[o[0],o][o[0]in'ST']for o in['Su','Mo','Tu','We','Th','Fr','Sa']if o in[n[i:i+2]for i in range(0,len(n),2)]]);d=[d,a(d,['Tu','Th'],'T')][('W'in d)+('TuT'in d)];l=len(d);d=[d,a(d,['Su','Sa'],'S')][l>2];return[[[d,'A'][l>8],'E'][d=='SS'],'D'][d=='MTWTF']
```
[Test on ideone](http://ideone.com/fbkYWO)
[Answer]
# JavaScript (ES6), 197 bytes
```
s=>eval(`n=0;d="SuMoTuWeThFrSa";s.match(/../g).map(t=>n|=1<<d.search(t)/2);o="";for(i=0;i<7;i++)n&1<<i?o+=d.substr(i*2,n<2|n==64|(!(n&8|(n&20)>19)&&i==2|i==4)?2:1):0;n-127?n-62?n-65?o:"E":"D":"A"`)
```
## Explanation
Encodes each day as a bit and stores the input as a number `n`. Bit 0 = Sunday ... bit 6 = Saturday. This allows the ambiguity rule checking code to be a lot shorter due to the bit-wise operations and being able to compare the entire combination with a number that is always less than 128.
```
s=>
  eval(`                   // eval enables the for loop without {} or return
    n=0;                   // n = input encoded as a number
    d="SuMoTuWeThFrSa";    // d = day strings
    s.match(/../g).map(t=> // for each day string t in the input
      n|=1<<d.search(t)/2  // set the bit in n that corresponds to the day
    );
    o="";                  // o = output string
    for(i=0;i<7;i++)       // for each day i from Sunday to Monday
      n&1<<i?              // if the day was in the input
        o+=d.substr(i*2,   // add the day string to the output
          n<2              // Sunday by itself is ambiguous
          |n==64           // Saturday by itself is ambiguous
          |(!(n&8          // Without Wednesday...
            |(n&20)>19     // ...or both Tuesday and Thursday,
            )&&i==2|i==4)  // ...Tuesday or Thursday are ambiguous
          ?2:1             // 2 characters if ambiguous, else 1
        )
      :0;
    n-127?                 // n == 127 = All days (A)
      n-62?                // n == 62 = All week days (D)
        n-65?              // n == 65 = All weekend days (E)
          o                // else output the constructed string
        :"E"
      :"D"
    :"A"
  `)
```
## Test
```
var solution = s=>eval(`n=0;d="SuMoTuWeThFrSa";s.match(/../g).map(t=>n|=1<<d.search(t)/2);o="";for(i=0;i<7;i++)n&1<<i?o+=d.substr(i*2,n<2|n==64|(!(n&8|(n&20)>19)&&i==2|i==4)?2:1):0;n-127?n-62?n-65?o:"E":"D":"A"`)
```
```
<input type="text" id="input" value="FrTh" />
<button onclick="result.textContent=solution(input.value)">Go</button>
<pre id="result"></pre>
```
]