fork download
  1. s = "WRWRWWRRR"
  2. print(s)
  3. print()
  4.  
  5. for i in range(len(s)-1):
  6. for j in range(i+1,len(s)):
  7. if s[i] > s[j]:
  8. print("swap {} and {}".format(i,j))
  9. s = s[:i] + s[j] + s[i+1:j] + s[i] + s[j+1:]
  10. print(s)
  11. print()
  12.  
Success #stdin #stdout 0.04s 9604KB
stdin
Standard input is empty
stdout
WRWRWWRRR

swap 0 and 1
RWWRWWRRR

swap 1 and 3
RRWWWWRRR

swap 2 and 6
RRRWWWWRR

swap 3 and 7
RRRRWWWWR

swap 4 and 8
RRRRRWWWW