Решение на Навигация на Piet от Лиляна Белчева

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

Към профила на Лиляна Белчева

Резултати

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

Код

def calculate_final_vector(coordinates, listColours):
x, y = coordinates
for move in listColours:
checker = move.upper()
if checker == 'C0FFC0':
x -= 1
elif checker == '00C000':
x += 1
elif checker == 'FFFFC0':
y -= 1
elif checker == 'C0C000':
y += 1
elif checker == 'FFC0C0':
x += 1
elif checker == 'C00000':
x -= 1
elif checker == 'C0C0FF':
y += 1
elif checker == '0000C0':
y -= 1
elif checker == '000000':
break
else:
continue
return x, y

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.095s

OK

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

Лиляна обнови решението на 25.10.2022 01:53 (преди около 2 години)

+def calculate_final_vector(coordinates, listColours):
+ if len(coordinates) <= 1 or len(coordinates) > 2:
+ print("Not enough values to unpack")
+ return ()
+
+ x, y = coordinates
+ for move in listColours:
+ checker = move.upper()
+ if checker == 'C0FFC0':
+ x -= 1
+ elif checker == '00C000':
+ x += 1
+ elif checker == 'FFFFC0':
+ y -= 1
+ elif checker == 'C0C000':
+ y += 1
+ elif checker == 'FFC0C0':
+ x += 1
+ elif checker == 'C00000':
+ x -= 1
+ elif checker == 'C0C0FF':
+ y += 1
+ elif checker == '0000C0':
+ y -= 1
+ elif checker == '000000':
+ break
+ else:
+ continue
+
+ result = (x, y)
+ return result

Лиляна обнови решението на 25.10.2022 01:56 (преди около 2 години)

def calculate_final_vector(coordinates, listColours):
- if len(coordinates) <= 1 or len(coordinates) > 2:
+ if len(coordinates) != 2:
print("Not enough values to unpack")
return ()
x, y = coordinates
for move in listColours:
checker = move.upper()
if checker == 'C0FFC0':
x -= 1
elif checker == '00C000':
x += 1
elif checker == 'FFFFC0':
y -= 1
elif checker == 'C0C000':
y += 1
elif checker == 'FFC0C0':
x += 1
elif checker == 'C00000':
x -= 1
elif checker == 'C0C0FF':
y += 1
elif checker == '0000C0':
y -= 1
elif checker == '000000':
break
else:
continue
result = (x, y)
return result

Лиляна обнови решението на 25.10.2022 11:37 (преди около 2 години)

def calculate_final_vector(coordinates, listColours):
- if len(coordinates) != 2:
- print("Not enough values to unpack")
- return ()
-
x, y = coordinates
+
for move in listColours:
checker = move.upper()
if checker == 'C0FFC0':
x -= 1
elif checker == '00C000':
x += 1
elif checker == 'FFFFC0':
y -= 1
elif checker == 'C0C000':
y += 1
elif checker == 'FFC0C0':
x += 1
elif checker == 'C00000':
x -= 1
elif checker == 'C0C0FF':
y += 1
elif checker == '0000C0':
y -= 1
elif checker == '000000':
break
else:
continue
- result = (x, y)
- return result
+ return x, y