Skip to content

Commit 05a9bfb

Browse files
authored
Circular Moves
Initial File
1 parent 6aa2df3 commit 05a9bfb

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Circular Moves

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
else:
40+
print("Sequence of moves are not circular")

0 commit comments

Comments
 (0)