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

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

Към профила на Николай Натов

Резултати

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

Код

DIRECTIONS = {
"C0FFC0" : (-1, 0), # Light Green
"00C000" : ( 1, 0), # Dark Green
"FFFFC0" : ( 0, -1), # Light Yellow
"C0C000" : ( 0, 1), # Dark Yellow
"FFC0C0" : ( 1, 0), # Light Red
"C00000" : (-1, 0), # Dark Red
"C0C0FF" : ( 0, 1), # Light Blue
"0000C0" : ( 0, -1), # Dark Blue
"FFFFFF" : ( 0, 0) # White
}
def calculate_final_vector(start_point, colors):
for color in colors:
if color == "000000":
break
direction = DIRECTIONS[color.upper()]
start_point = (start_point[0] + direction[0], start_point[1] + direction[1])
return start_point

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.089s

OK

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

Николай обнови решението на 20.10.2022 17:15 (преди около 2 години)

+DIRECTIONS = {
+ "C0FFC0" : (-1, 0), # Light Green
+ "00C000" : ( 1, 0), # Dark Green
+ "FFFFC0" : ( 0, -1), # Light Yellow
+ "C0C000" : ( 0, 1), # Dark Yellow
+ "FFC0C0" : ( 1, 0), # Light Red
+ "C00000" : (-1, 0), # Dark Red
+ "C0C0FF" : ( 0, 1), # Light Blue
+ "0000C0" : ( 0, -1), # Dark Blue
+ "FFFFFF" : ( 0, 0) # White
+}
+
+def calculate_final_vector(startPoint, colors):
+ for color in colors:
+ if color == "000000":
+ break
+
+ direction = DIRECTIONS[color.upper()]
+ startPoint = (startPoint[0] + direction[0], startPoint[1] + direction[1])
+
+ return startPoint

Николай обнови решението на 24.10.2022 10:18 (преди около 2 години)

DIRECTIONS = {
"C0FFC0" : (-1, 0), # Light Green
"00C000" : ( 1, 0), # Dark Green
"FFFFC0" : ( 0, -1), # Light Yellow
"C0C000" : ( 0, 1), # Dark Yellow
"FFC0C0" : ( 1, 0), # Light Red
"C00000" : (-1, 0), # Dark Red
"C0C0FF" : ( 0, 1), # Light Blue
"0000C0" : ( 0, -1), # Dark Blue
"FFFFFF" : ( 0, 0) # White
}
-def calculate_final_vector(startPoint, colors):
+def calculate_final_vector(start_point, colors):
for color in colors:
if color == "000000":
break
direction = DIRECTIONS[color.upper()]
- startPoint = (startPoint[0] + direction[0], startPoint[1] + direction[1])
+ start_point = (start_point[0] + direction[0], start_point[1] + direction[1])
- return startPoint
+ return start_point