@zhiwei/

collisions

Python

No description

fork
loading
Files
  • main.py
main.py
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
def check(balls):
  r = False
  for i in balls:
    if(i == "R"):
      r = True
    if(r and i == "L"):
      return False
  return True
  

N = 5
Balls_direction = ["L", "R", "R", "L", "R"]

collisionCount = 0
while(not check(Balls_direction)):
  
  for i in range(N-1):
    if(Balls_direction[i] == "R" and Balls_direction[i+1] == "L"):
      Balls_direction[i] = "L"
      Balls_direction[i+1] = "R"
      collisionCount += 1
    
print(collisionCount)