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

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

Към профила на Рая Симеонова

Резултати

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

Код

def calculate_final_vector(starting_point, hex_codes):
hex_codes_movements = {
'C0FFC0': (-1, 0), # light green
'00C000': (1, 0), # dark green
'FFFFC0': (0, -1), # light yellow
'C0C000': (0, 1), # dark yellow
'FFC0C0': (1, 0), # light red
'C00000': (-1, 0), # dark red
'C0C0FF': (0, 1), # light blue
'0000C0': (0, -1), # dark blue
'FFFFFF': (0, 0), # white
}
current_x, current_y = starting_point
for hex_code in hex_codes:
hex_code_upper_case = hex_code.upper()
if hex_code_upper_case == '000000':
break
if hex_code_upper_case in hex_codes_movements:
movement = hex_codes_movements[hex_code_upper_case]
current_x += movement[0]
current_y += movement[1]
return current_x, current_y

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

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

OK

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

Рая обнови решението на 24.10.2022 18:40 (преди около 2 години)

+def calculate_final_vector(starting_point, hex_codes) :
+
+ hex_codes_movements = {
+ 'C0FFC0': (-1, 0), #light green
+ '00C000': (1, 0), #dark green
+ 'FFFFC0': (0, -1), #light yellow
+ 'C0C000': (0, 1), #dark yellow
+ 'FFC0C0': (1, 0), #light red
+ 'C00000': (-1, 0), #dark red
+ 'C0C0FF': (0, 1), #light blue
+ '0000C0': (0, -1), #dark blue
+ 'FFFFFF': (0, 0), #white
+ }
+
+ current_x, current_y = starting_point
+
+ for hex_code in hex_codes:
+ hex_code_upper_case = hex_code.upper()
+
+ if hex_code_upper_case == '000000':
+ return (current_x, current_y)
+
+ if hex_code_upper_case in hex_codes_movements:
+ movement = hex_codes_movements[hex_code_upper_case]
+ current_x += movement[0]
+ current_y += movement[1]
+
+ return (current_x, current_y)

Рая обнови решението на 25.10.2022 02:31 (преди около 2 години)

-def calculate_final_vector(starting_point, hex_codes) :
+def calculate_final_vector(starting_point, hex_codes):
hex_codes_movements = {
- 'C0FFC0': (-1, 0), #light green
- '00C000': (1, 0), #dark green
- 'FFFFC0': (0, -1), #light yellow
- 'C0C000': (0, 1), #dark yellow
- 'FFC0C0': (1, 0), #light red
- 'C00000': (-1, 0), #dark red
- 'C0C0FF': (0, 1), #light blue
- '0000C0': (0, -1), #dark blue
- 'FFFFFF': (0, 0), #white
+ 'C0FFC0': (-1, 0), # light green
+ '00C000': (1, 0), # dark green
+ 'FFFFC0': (0, -1), # light yellow
+ 'C0C000': (0, 1), # dark yellow
+ 'FFC0C0': (1, 0), # light red
+ 'C00000': (-1, 0), # dark red
+ 'C0C0FF': (0, 1), # light blue
+ '0000C0': (0, -1), # dark blue
+ 'FFFFFF': (0, 0), # white
}
current_x, current_y = starting_point
for hex_code in hex_codes:
hex_code_upper_case = hex_code.upper()
if hex_code_upper_case == '000000':
- return (current_x, current_y)
+ break
if hex_code_upper_case in hex_codes_movements:
movement = hex_codes_movements[hex_code_upper_case]
current_x += movement[0]
current_y += movement[1]
- return (current_x, current_y)
+ return current_x, current_y