We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6aa2df3 commit 05a9bfbCopy full SHA for 05a9bfb
1 file changed
Circular Moves
@@ -0,0 +1,40 @@
1
+# check if given set of moves is circular on not
2
+def checkCircularMove(str1):
3
+ x = 0
4
+ y = 0
5
+ N=0
6
+ E=1
7
+ S=2
8
+ W=3
9
+ dir1 =N
10
+
11
+ for move in str1:
12
+ if move == 'R':
13
+ dir1 = int((dir1 + 1) % 4)
14
+ if move == 'L':
15
+ dir1 = int((4 + dir1 - 1) % 4)
16
17
18
+ if move == 'M':
19
+ if dir1 == N:
20
+ y = y + 1
21
+ if dir1 == S:
22
+ y = y - 1
23
+ if dir1 == E:
24
+ x = x + 1
25
+ if dir1 == W:
26
+ x = x - 1
27
+ if x == 0 and y == 0:
28
+ return True
29
+ else:
30
+ return False
31
32
33
+if __name__ == '__main__':
34
+ # str = "MMRMMRMMRMMR"
35
+ str = "ML"
36
37
+ if checkCircularMove(str):
38
+ print("Sequence of moves are circular")
39
40
+ print("Sequence of moves are not circular")
0 commit comments