Compressed days of the week

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. 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.


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.


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

Tags:

Code Golf