Решение на Навигация на Piet от Евтим Иванов

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

Към профила на Евтим Иванов

Резултати

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

Код

import operator
colors_and_movements = {"C0FFC0":(-1,0), "00C000":(1,0),
"FFFFC0":(0,-1), "C0C000":(0,1),
"FFC0C0":(1,0), "C00000":(-1,0),
"C0C0FF":(0,1), "0000C0":(0,-1),
"FFFFFF":(0,0)}
def calculate_next_position(current_position, current_code):
return tuple(map(operator.add,current_position, colors_and_movements.get(current_code)))
def calculate_final_vector(start_position, list_of_hex_codes):
current_position = start_position
for code in list_of_hex_codes:
code = code.upper()
if code == "000000":
return current_position
else:
current_position = calculate_next_position(current_position,code)
return current_position

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.085s

OK

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

Евтим обнови решението на 24.10.2022 19:41 (преди около 2 години)

+import operator
+
+colors_and_movements = {"C0FFC0":(-1,0),"00C000":(1,0),
+ "FFFFC0":(0,-1),"C0C000":(0,1),
+ "FFC0C0":(1,0),"C00000":(-1,0),
+ "C0C0FF":(0,1),"0000C0":(0,-1),
+ "FFFFFF":(0,0),"000000":"End"}
+
+def calculate_next_position(current_position, current_code):
+ return tuple(map(operator.add,current_position, colors_and_movements.get(current_code)))
+
+def calculate_final_vector(start_position, list_of_hex_codes):
+ current_position = start_position
+ for code in list_of_hex_codes:
+ code = code.upper()
+ if code == "000000":
+ return current_position
+ else:
+ current_position = calculate_next_position(current_position,code)
+ return current_position

Евтим обнови решението на 24.10.2022 22:24 (преди около 2 години)

import operator
-colors_and_movements = {"C0FFC0":(-1,0),"00C000":(1,0),
- "FFFFC0":(0,-1),"C0C000":(0,1),
- "FFC0C0":(1,0),"C00000":(-1,0),
- "C0C0FF":(0,1),"0000C0":(0,-1),
- "FFFFFF":(0,0),"000000":"End"}
+colors_and_movements = {"C0FFC0":(-1,0), "00C000":(1,0),
+ "FFFFC0":(0,-1), "C0C000":(0,1),
+ "FFC0C0":(1,0), "C00000":(-1,0),
+ "C0C0FF":(0,1), "0000C0":(0,-1),
+ "FFFFFF":(0,0)}
def calculate_next_position(current_position, current_code):
return tuple(map(operator.add,current_position, colors_and_movements.get(current_code)))
def calculate_final_vector(start_position, list_of_hex_codes):
current_position = start_position
for code in list_of_hex_codes:
code = code.upper()
if code == "000000":
return current_position
else:
current_position = calculate_next_position(current_position,code)
return current_position