Антоан обнови решението на 22.10.2022 13:41 (преди около 2 години)
+def validate_colours(colours):
+ # This function will make all colours in the given list to be uppercase only
+ # as to allow dealing with randomized letter-casing
+ curr_index = 0
+ while curr_index < len(colours):
+ colours[curr_index] = colours[curr_index].upper()
+ curr_index += 1
+
+
+def calculate_final_vector(input_vector, colours):
+ LIGHT_GREEN = "C0FFC0"
+ DARK_GREEN = "00C000"
+ LIGHT_YELLOW = "FFFFC0"
+ DARK_YELLOW = "C0C000"
+ LIGHT_RED = "FFC0C0"
+ DARK_RED = "C00000"
+ LIGHT_BLUE = "C0C0FF"
+ DARK_BLUE = "0000C0"
+
+ # Since White doesn't do anything, we will skip it as a case and as a variable
+ # We will assume that all colours which are not special will go to the default case together with white
+ BLACK = "000000"
+
+ final_x = input_vector[0]
final_x, final_y = input_vector
Tuple unpacking. :)
+ final_y = input_vector[1]
+ validate_colours(colours)
+ # Negative direction - 1 = Opposite direction + 1, so we can group 5 unique cases including black
+
+ for curr_colour in colours:
+ if curr_colour == BLACK:
+ break
+ elif curr_colour == DARK_GREEN or curr_colour == LIGHT_RED:
+ final_x += 1
+ elif curr_colour == DARK_RED or curr_colour == LIGHT_GREEN:
+ final_x -= 1
+ elif curr_colour == DARK_YELLOW or curr_colour == LIGHT_BLUE:
+ final_y += 1
+ elif curr_colour == DARK_BLUE or curr_colour == LIGHT_YELLOW:
+ final_y -= 1
+
+ output_vector = final_x, final_y
return final_x, final_y
е напълно валидно.
+ return output_vector