Advertisement
pacho_the_python

Untitled

Aug 26th, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from collections import deque
  2. num_str = input().split(", ")
  3. numbers_1 = deque(input().split(", "))
  4. numbers_2 = input().split(", ")
  5.  
  6. rotations = 0
  7. seat_matches = []
  8. while numbers_1 and numbers_2:
  9.     num_1 = numbers_1.popleft()
  10.     num_2 = numbers_2.pop()
  11.     current_sum = int(num_1) + int(num_2)
  12.     current_letter = chr(current_sum)
  13.     str_1 = str(num_1) + current_letter
  14.     str_2 = str(num_2) + current_letter
  15.     if str_1 in num_str:
  16.         seat_matches.append(str_1)
  17.         num_str.remove(str_1)
  18.     elif str_2 in num_str:
  19.         seat_matches.append(str_2)
  20.         num_str.remove(str_2)
  21.     else:
  22.         numbers_1.append(num_1)
  23.         numbers_2.insert(0, num_2)
  24.     rotations += 1
  25.     if rotations == 10 or len(seat_matches) == 3:
  26.         break
  27.  
  28. print(f"Seat matches: {', '.join(seat_matches)}")
  29. print(f"Rotations count: {rotations}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement