Решение на Навигация на Piet от Румен Тошев

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

Към профила на Румен Тошев

Резултати

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

Код

def calculate_final_vector(cordinates, unfixed_colours):
fixed_colours = [i.upper() for i in unfixed_colours]
colour_to_command = {"C0FFC0": "DownX", "00C000": "UpX",
"FFFFC0": "DownY", "C0C000": "UpY",
"FFC0C0": "UpX", "C00000": "DownX",
"C0C0FF": "UpY", "0000C0": "DownY",
"FFFFFF": "Nothing", "000000": "Stop"}
temp_cordinates = [cordinates[0], cordinates[1]]
for colour in fixed_colours:
command = colour_to_command[colour]
if command == "Stop":
break
elif command == "Nothing":
continue
elif command == "DownX":
temp_cordinates[0] = temp_cordinates[0] - 1
elif command == "UpX":
temp_cordinates[0] = temp_cordinates[0] + 1
elif command == "DownY":
temp_cordinates[1] = temp_cordinates[1] - 1
elif command == "UpY":
temp_cordinates[1] = temp_cordinates[1] + 1
return tuple(temp_cordinates)

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.097s

OK

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

Румен обнови решението на 24.10.2022 20:54 (преди около 2 години)

+def calculate_final_vector(cordinates, colours_unfixed):
+ colours_fixed = [i.upper() for i in colours_unfixed]
+ dictionary = {"C0FFC0": "DownX", "00C000": "UpX",
+ "FFFFC0": "DownY", "C0C000": "UpY",
+ "FFC0C0": "UpX", "C00000": "DownX",
+ "C0C0FF": "UpY", "0000C0": "DownY",
+ "FFFFFF": "Nothing", "000000": "Stop"}
+ new_list = [cordinates[0], cordinates[1]]
+ for colour in colours_fixed:
+ command = dictionary[colour]
+ if command == "Stop":
+ break
+ elif command == "Nothing":
+ continue
+ elif command == "DownX":
+ new_list[0] = new_list[0] - 1
+ elif command == "UpX":
+ new_list[0] = new_list[0] + 1
+ elif command == "DownY":
+ new_list[1] = new_list[1] - 1
+ elif command == "UpY":
+ new_list[1] = new_list[1] + 1
+ return tuple(new_list)

Румен обнови решението на 25.10.2022 11:47 (преди около 2 години)

-def calculate_final_vector(cordinates, colours_unfixed):
- colours_fixed = [i.upper() for i in colours_unfixed]
- dictionary = {"C0FFC0": "DownX", "00C000": "UpX",
- "FFFFC0": "DownY", "C0C000": "UpY",
- "FFC0C0": "UpX", "C00000": "DownX",
- "C0C0FF": "UpY", "0000C0": "DownY",
- "FFFFFF": "Nothing", "000000": "Stop"}
- new_list = [cordinates[0], cordinates[1]]
- for colour in colours_fixed:
- command = dictionary[colour]
+def calculate_final_vector(cordinates, unfixed_colours):
+ fixed_colours = [i.upper() for i in unfixed_colours]
+ colour_to_command = {"C0FFC0": "DownX", "00C000": "UpX",
+ "FFFFC0": "DownY", "C0C000": "UpY",
+ "FFC0C0": "UpX", "C00000": "DownX",
+ "C0C0FF": "UpY", "0000C0": "DownY",
+ "FFFFFF": "Nothing", "000000": "Stop"}
+ temp_list_with_cordinates = [cordinates[0], cordinates[1]]
+ for colour in fixed_colours:
+ command = colour_to_command[colour]
if command == "Stop":
break
elif command == "Nothing":
continue
elif command == "DownX":
- new_list[0] = new_list[0] - 1
+ temp_list_with_cordinates[0] = temp_list_with_cordinates[0] - 1
elif command == "UpX":
- new_list[0] = new_list[0] + 1
+ temp_list_with_cordinates[0] = temp_list_with_cordinates[0] + 1
elif command == "DownY":
- new_list[1] = new_list[1] - 1
+ temp_list_with_cordinates[1] = temp_list_with_cordinates[1] - 1
elif command == "UpY":
- new_list[1] = new_list[1] + 1
- return tuple(new_list)
+ temp_list_with_cordinates[1] = temp_list_with_cordinates[1] + 1
+ return tuple(temp_list_with_cordinates)

Румен обнови решението на 25.10.2022 11:49 (преди около 2 години)

def calculate_final_vector(cordinates, unfixed_colours):
fixed_colours = [i.upper() for i in unfixed_colours]
colour_to_command = {"C0FFC0": "DownX", "00C000": "UpX",
"FFFFC0": "DownY", "C0C000": "UpY",
"FFC0C0": "UpX", "C00000": "DownX",
"C0C0FF": "UpY", "0000C0": "DownY",
"FFFFFF": "Nothing", "000000": "Stop"}
- temp_list_with_cordinates = [cordinates[0], cordinates[1]]
+ temp_cordinates = [cordinates[0], cordinates[1]]
for colour in fixed_colours:
command = colour_to_command[colour]
if command == "Stop":
break
elif command == "Nothing":
continue
elif command == "DownX":
- temp_list_with_cordinates[0] = temp_list_with_cordinates[0] - 1
+ temp_cordinates[0] = temp_cordinates[0] - 1
elif command == "UpX":
- temp_list_with_cordinates[0] = temp_list_with_cordinates[0] + 1
+ temp_cordinates[0] = temp_cordinates[0] + 1
elif command == "DownY":
- temp_list_with_cordinates[1] = temp_list_with_cordinates[1] - 1
+ temp_cordinates[1] = temp_cordinates[1] - 1
elif command == "UpY":
- temp_list_with_cordinates[1] = temp_list_with_cordinates[1] + 1
- return tuple(temp_list_with_cordinates)
+ temp_cordinates[1] = temp_cordinates[1] + 1
+ return tuple(temp_cordinates)