Решение на Навигация на Piet от Стоян Михайлов

Обратно към всички решения

Към профила на Стоян Михайлов

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def calculate_final_vector(starting_point, colors):
end_point_coordinates = [starting_point[0], starting_point[1]]
# first coordinate == X, second == Y
moves_for_color = {
"c0ffc0": (-1, 0), # light green
"ffffc0": (0, -1), # light yellow
"ffc0c0": (1, 0), # light red
"c0c0ff": (0, 1), # light blue
"00c000": (1, 0), # dark green
"c0c000": (0, 1), # dark yellow
"c00000": (-1, 0), # dark red
"0000c0": (0, -1), # dark blue
"ffffff": (0, 0) # white
}
for color in colors:
if color == "000000":
return tuple(end_point_coordinates)
move = moves_for_color[color.lower()]
end_point_coordinates[0] += move[0]
end_point_coordinates[1] += move[1]
return tuple(end_point_coordinates)

Лог от изпълнението

........
----------------------------------------------------------------------
Ran 8 tests in 0.120s

OK

История (1 версия и 1 коментар)

Стоян обнови решението на 24.10.2022 23:33 (преди над 1 година)

+def calculate_final_vector(starting_point, colors):
+ end_point_coordinates = [starting_point[0], starting_point[1]]
+ # first coordinate == X, second == Y
+ moves_for_color = {
+ "c0ffc0": (-1, 0), # light green
+ "ffffc0": (0, -1), # light yellow
+ "ffc0c0": (1, 0), # light red
+ "c0c0ff": (0, 1), # light blue
+ "00c000": (1, 0), # dark green
+ "c0c000": (0, 1), # dark yellow
+ "c00000": (-1, 0), # dark red
+ "0000c0": (0, -1), # dark blue
+ "ffffff": (0, 0) # white
+ }
+
+ for color in colors:
+ if color == "000000":
+ return tuple(end_point_coordinates)
+
+ move = moves_for_color[color.lower()]
+ end_point_coordinates[0] += move[0]
+ end_point_coordinates[1] += move[1]
+
+ return tuple(end_point_coordinates)