fork download
  1. input = raw_input("Initial: ")
  2. input2 = raw_input("Command: ")
  3.  
  4. position = [int(input[0]), int(input[2]), input[4]]
  5.  
  6. bearings = "NESW"
  7. turns = {"L" : -1, "M": 0, "R" : 1}
  8. move = {"N" : [0, 1], "E" : [1, 0], "S" : [0, -1], "W" : [-1, 0]}
  9.  
  10. for c in input2:
  11. turn = turns[c];
  12. if (turn == 0):
  13. position[0] += move[position[2]][0]
  14. position[1] += move[position[2]][1]
  15. else:
  16. position[2] = bearings[(bearings.index(position[2]) + turn)%4]
  17.  
  18. print "Output: ", ','.join((str(s) for s in position))
Success #stdin #stdout 0.01s 7856KB
stdin
1,2,N
MRMLM
stdout
Initial: Command: Output:  2,4,N