Решение на Навигация на Piet от Теодора Петкова

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

Към профила на Теодора Петкова

Резултати

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

Код

def calculate_final_vector(start_point, list_of_colors):
end_point = [start_point[0], start_point[1]]
for color in list_of_colors:
# up [1]+1 down [1]-1 left [0]-1 right [0]+1
match color.upper():
case 'C0FFC0': # right -1
end_point[0] -= 1
case 'FFFFC0': # up -1
end_point[1] -= 1
case 'FFC0C0':
end_point[0] += 1 # left -1
case 'C0C0FF': # down -1
end_point[1] += 1
case '00C000': # right +1
end_point[0] += 1
case 'C0C000': # up +1
end_point[1] += 1
case 'C00000': # left +1
end_point[0] -= 1
case '0000C0': # down +1
end_point[1] -= 1
case 'FFFFFF': # nop
continue
case '000000': # end
return end_point[0], end_point[1]
case _: # default
print('Error: {0} is not valid color and it is ignored'.format(color))
return end_point[0], end_point[1]

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.084s

OK

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

Теодора обнови решението на 23.10.2022 19:27 (преди около 2 години)

+def calculate_final_vector(start_point, list_of_colors):
+ end_point = [start_point[0], start_point[1]]
+
+ for color in list_of_colors:
+ # up [1]+1 down [1]-1 left [0]-1 right [0]+1
+ match color.upper():
+ case 'C0FFC0': # right -1
+ end_point[0] -= 1
+ case 'FFFFC0': # up -1
+ end_point[1] -= 1
+ case 'FFC0C0':
+ end_point[0] += 1 # left -1
+ case 'C0C0FF': # down -1
+ end_point[1] += 1
+ case '00C000': # right +1
+ end_point[0] += 1
+ case 'C0C000': # up +1
+ end_point[1] += 1
+ case 'C00000': # left +1
+ end_point[0] -= 1
+ case '0000C0': # down +1
+ end_point[1] -= 1
+ case 'FFFFFF': # nop
+ continue
+ case '000000': # end
+ return end_point[0], end_point[1]
+ case _: # default
+ print('Error: {0} is not valid color and it is ignored'.format(color))
+ return end_point[0], end_point[1]