fork download
  1. import sys,re,string
  2. j=''.join
  3. a=string.ascii_lowercase
  4. for l in sys.stdin:
  5. s,L=re.sub('[^a-z]','',l.lower()).strip(),[]
  6. for i,c in enumerate(s[:-1]):o=s[i+1:i+2]or c;b,d=a.index(c),a.index(o);L.extend(j(e[1])for e in[(c==o,[c,'Z',c]),(c<o,(a[b+1:d],[c,'R',o])[b+1==d]),(c>o,(a[d+1:b][::-1],[c,'L',o])[b-1==d])]if e[0])
  7. print(j(L))
Success #stdin #stdout 0.04s 9048KB
stdin
aa
ab
ba
bo
boa
att
brep
Optimizer
aabbcfcBBAa
stdout
aZa
aRb
bLa
cdefghijklmn
cdefghijklmnnmlkjihgfedcb
bcdefghijklmnopqrstZt
cdefghijklmnopqqponmlkjihgffghijklmno
oRpqrssrqponmlkjjkllkjjklmnopqrstuvwxyyxwvutsrqponmlkjihgffghijklmnopq
aZaaRbbZbbRcdeedcLbbZbbLaaZa