Решение на Навигация на Piet от Йоанна Кръстева

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

Към профила на Йоанна Кръстева

Резултати

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

Код

colors_dictionary = {
'C0FFC0': 'decrease_first',
'FFFFC0': 'decrease_second',
'00C000': 'increase_first',
'C0C000': 'increase_second',
'FFC0C0': 'increase_first',
'C00000': 'decrease_first',
'C0C0FF': 'increase_second',
'0000C0': 'decrease_second',
'000000': 'end'
}
def calculate_final_vector(starting_vector, colors):
converted_tuple = list(starting_vector)
for color in colors:
operation = colors_dictionary.setdefault(color.upper(), "Do nothing!")
if operation == 'increase_first':
converted_tuple[0] += 1
elif operation == 'decrease_first':
converted_tuple[0] -= 1
elif operation == 'increase_second':
converted_tuple[1] += 1
elif operation == 'decrease_second':
converted_tuple[1] -= 1
elif operation == 'end':
break
else:
continue
return tuple(converted_tuple)

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.081s

OK

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

Йоанна обнови решението на 24.10.2022 12:45 (преди около 2 години)

+
+colors_dictionary = dict({
+ 'C0FFC0': 'decrease_first',
+ 'FFFFC0': 'decrease_second',
+ '00C000': 'increase_first',
+ 'C0C000': 'increase_second',
+ 'FFC0C0': 'increase_first',
+ 'C00000': 'decrease_first',
+ 'C0C0FF': 'increase_second',
+ '0000C0': 'decrease_second',
+ '000000': 'end'
+})
+
+
+def calculate_final_vector(starting_vector, colors):
+ converted_tuple = list(starting_vector)
+ for color in colors:
+ operation = colors_dictionary.setdefault(color.upper(), "Do nothing!")
+ if operation == 'increase_first':
+ converted_tuple[0] += 1
+ elif operation == 'decrease_first':
+ converted_tuple[0] -= 1
+ elif operation == 'increase_second':
+ converted_tuple[1] += 1
+ elif operation == 'decrease_second':
+ converted_tuple[1] -= 1
+ elif operation == 'end':
+ break
+ else:
+ continue
+ starting_vector = tuple(converted_tuple)
+ return starting_vector
+

Йоанна обнови решението на 24.10.2022 22:49 (преди около 2 години)

-colors_dictionary = dict({
+colors_dictionary = {
'C0FFC0': 'decrease_first',
'FFFFC0': 'decrease_second',
'00C000': 'increase_first',
'C0C000': 'increase_second',
'FFC0C0': 'increase_first',
'C00000': 'decrease_first',
'C0C0FF': 'increase_second',
'0000C0': 'decrease_second',
'000000': 'end'
-})
+}
def calculate_final_vector(starting_vector, colors):
converted_tuple = list(starting_vector)
for color in colors:
operation = colors_dictionary.setdefault(color.upper(), "Do nothing!")
if operation == 'increase_first':
converted_tuple[0] += 1
elif operation == 'decrease_first':
converted_tuple[0] -= 1
elif operation == 'increase_second':
converted_tuple[1] += 1
elif operation == 'decrease_second':
converted_tuple[1] -= 1
elif operation == 'end':
break
else:
continue
- starting_vector = tuple(converted_tuple)
- return starting_vector
+ return tuple(converted_tuple)
-

Йоанна обнови решението на 24.10.2022 22:50 (преди около 2 години)

colors_dictionary = {
'C0FFC0': 'decrease_first',
'FFFFC0': 'decrease_second',
'00C000': 'increase_first',
'C0C000': 'increase_second',
'FFC0C0': 'increase_first',
'C00000': 'decrease_first',
'C0C0FF': 'increase_second',
'0000C0': 'decrease_second',
'000000': 'end'
}
def calculate_final_vector(starting_vector, colors):
converted_tuple = list(starting_vector)
for color in colors:
operation = colors_dictionary.setdefault(color.upper(), "Do nothing!")
if operation == 'increase_first':
converted_tuple[0] += 1
elif operation == 'decrease_first':
converted_tuple[0] -= 1
elif operation == 'increase_second':
converted_tuple[1] += 1
elif operation == 'decrease_second':
converted_tuple[1] -= 1
elif operation == 'end':
break
else:
continue
- return tuple(converted_tuple)
+ return tuple(converted_tuple)