Advertisement
kosievdmerwe

Untitled

Jan 9th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. DIRS = [
  2.     (1,0),
  3.     (0,1),
  4.     (-1,0),
  5.     (0,-1),
  6. ]
  7.  
  8.  
  9. class Solution:
  10.     def isRobotBounded(self, instructions: str) -> bool:
  11.         d = 0
  12.         px = py = 0
  13.         for c in instructions:
  14.             if c == "G":
  15.                 px += DIRS[d][0]
  16.                 py += DIRS[d][1]
  17.             else:
  18.                 d += 1 if c == "L" else 3
  19.                 d %= 4
  20.        
  21.         #print(d, px, py)
  22.        
  23.         if px == py == 0:
  24.             return True
  25.         if d == 0:
  26.             return False
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement