Решение на Навигация на Piet от Дуйгу Хасан

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

Към профила на Дуйгу Хасан

Резултати

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

Код

def calculate_final_vector(starting_point, hex_codes):
x, y = starting_point
hex_codes_upper = []
for code in hex_codes:
hex_codes_upper.append(code.upper())
for code in hex_codes_upper:
if code == "000000":
break
if code in ["C0FFC0", "C00000"]:
x = x - 1
if code in ["FFC0C0", "00C000"]:
x = x + 1
if code in ["FFFFC0", "0000C0"]:
y = y - 1
if code in ["C0C000", "C0C0FF"]:
y = y + 1
return x, y

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.080s

OK

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

Дуйгу обнови решението на 20.10.2022 12:12 (преди над 1 година)

+
+def calculate_final_vector(starting_point, hex_codes):
+ colour_dict_x_coordinate = {
+ "C0FFC0": -1,
+ "FFC0C0": 1,
+ "00C000": 1,
+ "C00000": -1,
+ }
+ colour_dict_y_coordinate = {
+ "FFFFC0": -1,
+ "C0C0FF": 1,
+ "C0C000": 1,
+ "0000C0": -1,
+ }
+ x, y = starting_point
+ hex_codes_upper = []
+ for code in hex_codes:
+ hex_codes_upper.append(code.upper())
+ for code in hex_codes_upper:
+ if code == "000000":
+ break
+ if code in colour_dict_x_coordinate:
+ x = x + colour_dict_x_coordinate[code]
+ continue
+ if code in colour_dict_y_coordinate:
+ y = y + colour_dict_y_coordinate[code]
+ result = (x, y)
+ return result

Дуйгу обнови решението на 24.10.2022 10:20 (преди над 1 година)

-
def calculate_final_vector(starting_point, hex_codes):
- colour_dict_x_coordinate = {
- "C0FFC0": -1,
- "FFC0C0": 1,
- "00C000": 1,
- "C00000": -1,
- }
- colour_dict_y_coordinate = {
- "FFFFC0": -1,
- "C0C0FF": 1,
- "C0C000": 1,
- "0000C0": -1,
- }
x, y = starting_point
hex_codes_upper = []
for code in hex_codes:
hex_codes_upper.append(code.upper())
for code in hex_codes_upper:
if code == "000000":
break
- if code in colour_dict_x_coordinate:
- x = x + colour_dict_x_coordinate[code]
+ if code in ["C0FFC0", "C00000"]:
- continue
+ x = x - 1
- if code in colour_dict_y_coordinate:
+ if code in ["FFC0C0", "00C000"]:
- y = y + colour_dict_y_coordinate[code]
+ x = x + 1
- result = (x, y)
+ if code in ["FFFFC0", "0000C0"]:
- return result
+ y = y - 1
+ if code in ["C0C000", "C0C0FF"]:
+ y = y + 1
+ return x, y