fork(6) download
  1. import re
  2.  
  3. def expand(alg):
  4.  
  5. def inv_move(m):
  6. return m if m.endswith('2') else m[:-1] if m.endswith("'") else m+"'"
  7. def inv(alg):
  8. return ' '.join(inv_move(m) for m in reversed(alg.split()))
  9. def foo(m):
  10. A, op, B = m.groups()
  11. return ' '.join([A, B, inv(A)] + ([inv(B)] if op == ',' else []))
  12.  
  13. prev = None
  14. while alg != prev:
  15. prev, alg = alg, re.sub(r"\[\s*([^][,:]+)\s*([,:])\s*([^][,:]+)\s*]", foo, alg)
  16. return alg
  17.  
  18. print(expand("[R' D R,[U:L]]"))
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
R' D R U L U' R' D' R U L' U'