-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoscow_problem.py
More file actions
35 lines (30 loc) · 814 Bytes
/
moscow_problem.py
File metadata and controls
35 lines (30 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
data = input('Enter data: ')
counter = 0
side = 'L'
for i in range(1, len(data)):
if (data[i - 1] == 'B'):
print(str(i) + ' crossed B')
counter += 1
#elif (((side == data[i - 1]) and (side == data[i])) or ((side == data[i - 1]) and (data[i] == 'B'))):
elif (((side == data[i - 1]) and (side == data[i]))):
if (side == 'L'):
side = 'R'
elif (side == 'R'):
side = 'L'
print(str(i) + ' changed to ' + side)
counter += 1
elif(side == data[i - 1]):
print(str(i) + ' crossed on side ' + side)
counter += 1
if ((side == 'R') and ((data[len(data) - 1] == 'B') or (data[len(data) - 1] == 'R'))):
counter += 1
if ((side == 'L') and ((data[len(data) - 1] == 'B') or (data[len(data) - 1] == 'L'))):
counter += 1
print(counter)
# Test data
# RRLRBRRLLR
# 4
# RRLRBRRLLRBRBRB
# 8
# LLBLRRBRL
# 5