Advertisement
Kaloyankerr

01. Paint Colors

Oct 20th, 2020
2,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. from collections import deque
  2.  
  3. data = deque(input().split())
  4.  
  5. all_colors = ['red', 'yellow', 'blue', 'orange', 'purple', 'green']
  6. second_colors = ['orange', 'purple', 'green']
  7.  
  8. colors_to_combine = {
  9.     'orange': ['red', 'yellow'],
  10.     'purple': ['red', 'blue'],
  11.     'green': ['yellow', 'blue']
  12. }
  13. colors = []
  14.  
  15. while data:
  16.     first_col = data.popleft()
  17.     if data:
  18.         second_col = data.pop()
  19.  
  20.         if (first_col + second_col) in all_colors:
  21.             colors.append(first_col + second_col)
  22.         elif (second_col + first_col) in all_colors:
  23.             colors.append(second_col + first_col)
  24.         else:
  25.             first_col = first_col[0:-1]
  26.             second_col = second_col[0:-1]
  27.  
  28.             if first_col:
  29.                 data.insert(len(data) // 2, first_col)
  30.             if second_col:
  31.                 data.insert(len(data) // 2, second_col)
  32.         continue
  33.  
  34.     if first_col in all_colors:
  35.         colors.append(first_col)
  36.  
  37.  
  38. for col in colors:
  39.     if col in second_colors:
  40.         not_color = False
  41.         for i in colors_to_combine[col]:
  42.             if i not in colors:
  43.                 not_color = True
  44.                 break
  45.  
  46.         if not_color:
  47.             colors.remove(col)
  48.  
  49. print(colors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement