viligen

paint_colors

Jan 19th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. from collections import deque
  2.  
  3. main_colors = {"red", "yellow", "blue"}
  4. secondary_colors = {"orange", "purple", "green"}
  5.  
  6. subcolors_dict = {"orange": ["red", "yellow"], "purple": ["red", "blue"], "green": ["yellow", "blue"]}
  7.  
  8. collected_colors = []
  9.  
  10.  
  11. text = deque(input().split())
  12.  
  13. while text:
  14.     start_string = text.popleft()
  15.     end_string = text.pop() if text else ""
  16.  
  17.     variant_1 = start_string + end_string
  18.     variant_2 = end_string + start_string
  19.  
  20.     if variant_1 in main_colors or variant_1 in secondary_colors:
  21.         collected_colors.append(variant_1)
  22.         continue
  23.     elif variant_2 in main_colors or variant_2 in secondary_colors:
  24.         collected_colors.append(variant_2)
  25.         continue
  26.  
  27.     else:
  28.         if start_string[:-1]:
  29.             text.insert(len(text) // 2, start_string[:-1])
  30.         if end_string[:-1]:
  31.             text.insert(len(text) // 2, end_string[:-1])
  32.  
  33.  
  34. for color in collected_colors:
  35.     if color in secondary_colors:
  36.         for needed_color in subcolors_dict[color]:
  37.             if needed_color not in collected_colors:
  38.                 while color in collected_colors:
  39.                     collected_colors.remove(color)
  40.                 break
  41.  
  42. print(collected_colors)
  43.  
  44.  
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment