Решение на Навигация на Piet от Ангел Марински

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

Към профила на Ангел Марински

Резултати

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

Код

LIGHT_GREEN = 'C0FFC0'
LIGHT_YELLOW = 'FFFFC0'
LIGHT_RED = 'FFC0C0'
LIGHT_BLUE = 'C0C0FF'
DARK_GREEN = '00C000'
DARK_YELLOW = 'C0C000'
DARK_RED = 'C00000'
DARK_BLUE = '0000C0'
WHITE = "FFFFFF"
BLACK = "000000"
# Зелено - надясно ( x + 1)
# Жълто - нагоре (y + 1)
# Червено - наляво (x - 1)
# Синьо - надолу (y - 1)
# for more unit tests: https://pastebin.com/FJcWPmZ5
def calculate_final_vector(coordinates, movement):
acordinates = list(coordinates)
for move in movement:
move = str(move).upper()
if move == LIGHT_YELLOW:
acordinates[1] = acordinates[1] - 1
elif move == DARK_YELLOW:
acordinates[1] = acordinates[1] + 1
elif move == LIGHT_GREEN:
acordinates[0] = acordinates[0] - 1
elif move == DARK_GREEN:
acordinates[0] = acordinates[0] + 1
elif move == LIGHT_BLUE:
acordinates[1] = acordinates[1] + 1
elif move == DARK_BLUE:
acordinates[1] = acordinates[1] - 1
elif move == LIGHT_RED:
acordinates[0] = acordinates[0] + 1
elif move == DARK_RED:
acordinates[0] = acordinates[0] - 1
elif move == BLACK:
break
else:
continue
return tuple(acordinates)

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.086s

OK

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

Ангел обнови решението на 24.10.2022 17:00 (преди около 2 години)

+import string
+
+LIGHT_GREEN = 'C0FFC0'
+LIGHT_YELLOW = 'FFFFC0'
+LIGHT_RED = 'FFC0C0'
+LIGHT_BLUE = 'C0C0FF'
+
+DARK_GREEN = '00C000'
+DARK_YELLOW = 'C0C000'
+DARK_RED = 'C00000'
+DARK_BLUE = '0000C0'
+
+WHITE = "FFFFFF"
+BLACK = "000000"
+
+# Зелено - надясно ( x + 1)
+# Жълто - нагоре (y + 1)
+# Червено - наляво (x - 1)
+# Синьо - надолу (y - 1)
+
+# for more unit tests: https://pastebin.com/FJcWPmZ5
+
+
+def calculate_final_vector(coordinates, movement):
+ acordinates = list(coordinates)
+
+ for move in movement:
+ move = str(move).upper()
+ if move == LIGHT_YELLOW:
+ acordinates[1] = acordinates[1] - 1
+ elif move == DARK_YELLOW:
+ acordinates[1] = acordinates[1] + 1
+ elif move == LIGHT_GREEN:
+ acordinates[0] = acordinates[0] - 1
+ elif move == DARK_GREEN:
+ acordinates[0] = acordinates[0] + 1
+ elif move == LIGHT_BLUE:
+ acordinates[1] = acordinates[1] + 1
+ elif move == DARK_BLUE:
+ acordinates[1] = acordinates[1] - 1
+ elif move == LIGHT_RED:
+ acordinates[0] = acordinates[0] + 1
+ elif move == DARK_RED:
+ acordinates[0] = acordinates[0] - 1
+ elif move == BLACK:
+ break
+ else:
+ continue
+
+ temp = tuple(acordinates)
+ return temp

Ангел обнови решението на 25.10.2022 17:03 (преди около 2 години)

-import string
-
LIGHT_GREEN = 'C0FFC0'
LIGHT_YELLOW = 'FFFFC0'
LIGHT_RED = 'FFC0C0'
LIGHT_BLUE = 'C0C0FF'
DARK_GREEN = '00C000'
DARK_YELLOW = 'C0C000'
DARK_RED = 'C00000'
DARK_BLUE = '0000C0'
WHITE = "FFFFFF"
BLACK = "000000"
# Зелено - надясно ( x + 1)
# Жълто - нагоре (y + 1)
# Червено - наляво (x - 1)
# Синьо - надолу (y - 1)
# for more unit tests: https://pastebin.com/FJcWPmZ5
def calculate_final_vector(coordinates, movement):
acordinates = list(coordinates)
for move in movement:
move = str(move).upper()
if move == LIGHT_YELLOW:
acordinates[1] = acordinates[1] - 1
elif move == DARK_YELLOW:
acordinates[1] = acordinates[1] + 1
elif move == LIGHT_GREEN:
acordinates[0] = acordinates[0] - 1
elif move == DARK_GREEN:
acordinates[0] = acordinates[0] + 1
elif move == LIGHT_BLUE:
acordinates[1] = acordinates[1] + 1
elif move == DARK_BLUE:
acordinates[1] = acordinates[1] - 1
elif move == LIGHT_RED:
acordinates[0] = acordinates[0] + 1
elif move == DARK_RED:
acordinates[0] = acordinates[0] - 1
elif move == BLACK:
break
else:
continue
- temp = tuple(acordinates)
- return temp
+ return tuple(acordinates)