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

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

Към профила на Алекс Божинов

Резултати

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

Код

def calculate_final_vector(vector: tuple, colors: list):
x, y = vector
for color in colors:
# make sure the case is equal everywhere
color = color.upper()
if color == 'FFFFFF': # White
continue # do nothing
elif color == '000000': # Black
break # end
elif color == 'C0FFC0': # Light Green
x = x - 1 # right -1
elif color == '00C000': # Dark Green
x = x + 1 # right +1
elif color == 'FFFFC0': # Light Yellow
y = y - 1 # up -1
elif color == 'C0C000': # Dark Yellow
y = y + 1 # up +1
elif color == 'FFC0C0': # Light Red
x = x + 1 # left -1 (right +1)
elif color == 'C00000': # Dark Red
x = x - 1 # left +1
elif color == 'C0C0FF': # Light Blue
y = y + 1 # down +1
elif color == '0000C0': # Dark Blue
y = y - 1 # down -1
return x, y

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.138s

OK

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

Алекс обнови решението на 23.10.2022 20:33 (преди около 2 години)

+def calculate_final_vector(vector: tuple, colors: list):
+ x2 = vector[0]
+ y2 = vector[1]
+
+ for color in colors:
+ # make sure the case is equal everywhere
+ color = color.upper()
+
+ if color == 'FFFFFF': # White
+ continue # do nothing
+ elif color == '000000': # Black
+ break # end
+ elif color == 'C0FFC0': # Light Green
+ x2 = x2 - 1 # right -1
+ elif color == '00C000': # Dark Green
+ x2 = x2 + 1 # right +1
+ elif color == 'FFFFC0': # Light Yellow
+ y2 = y2 - 1 # up -1
+ elif color == 'C0C000': # Dark Yellow
+ y2 = y2 + 1 # up +1
+ elif color == 'FFC0C0': # Light Red
+ x2 = x2 + 1 # left -1 (right +1)
+ elif color == 'C00000': # Dark Red
+ x2 = x2 - 1 # left +1
+ elif color == 'C0C0FF': # Light Blue
+ y2 = y2 + 1 # down +1
+ elif color == '0000C0': # Dark Blue
+ y2 = y2 - 1 # down -1
+
+ final_vector = (x2, y2)
+ return final_vector

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

def calculate_final_vector(vector: tuple, colors: list):
- x2 = vector[0]
- y2 = vector[1]
+ x, y = vector
+
for color in colors:
# make sure the case is equal everywhere
color = color.upper()
if color == 'FFFFFF': # White
continue # do nothing
elif color == '000000': # Black
break # end
elif color == 'C0FFC0': # Light Green
- x2 = x2 - 1 # right -1
+ x = x - 1 # right -1
elif color == '00C000': # Dark Green
- x2 = x2 + 1 # right +1
+ x = x + 1 # right +1
elif color == 'FFFFC0': # Light Yellow
- y2 = y2 - 1 # up -1
+ y = y - 1 # up -1
elif color == 'C0C000': # Dark Yellow
- y2 = y2 + 1 # up +1
+ y = y + 1 # up +1
elif color == 'FFC0C0': # Light Red
- x2 = x2 + 1 # left -1 (right +1)
+ x = x + 1 # left -1 (right +1)
elif color == 'C00000': # Dark Red
- x2 = x2 - 1 # left +1
+ x = x - 1 # left +1
elif color == 'C0C0FF': # Light Blue
- y2 = y2 + 1 # down +1
+ y = y + 1 # down +1
elif color == '0000C0': # Dark Blue
- y2 = y2 - 1 # down -1
+ y = y - 1 # down -1
- final_vector = (x2, y2)
- return final_vector
+ return x, y