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

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

Към профила на Стилиян Иванов

Резултати

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

Код

def calculate_final_vector(point, colours):
'''Piet navigation implementation'''
result = point
for colour in colours:
match colour.lower():
case 'c0ffc0' | 'c00000':
result = (result[0] - 1, result[1])
case '00c000' | 'ffc0c0':
result = (result[0] + 1, result[1])
case 'ffffc0' | '0000c0':
result = (result[0], result[1] - 1)
case 'c0c000' | 'c0c0ff':
result = (result[0], result[1] + 1)
case 'ffffff':
continue
case '000000':
break
return result

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

........
----------------------------------------------------------------------
Ran 8 tests in 0.087s

OK

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

Стилиян обнови решението на 24.10.2022 23:54 (преди над 1 година)

+def calculate_final_vector(point, colours):
+ '''Piet navigation implementation'''
+ for colour in colours:
+ match colour.lower():
+ case 'c0ffc0' | 'c00000':
+ point = (point[0] - 1, point[1])
+ case '00c000' | 'ffc0c0':
+ point = (point[0] + 1, point[1])
+ case 'ffffc0' | '0000c0':
+ point = (point[0], point[1] - 1)
+ case 'c0c000' | 'c0c0ff':
+ point = (point[0], point[1] + 1)
+ case 'ffffff':
+ continue
+ case '000000':
+ break
+ return point

Стилиян обнови решението на 25.10.2022 17:39 (преди над 1 година)

def calculate_final_vector(point, colours):
'''Piet navigation implementation'''
+ result = point
for colour in colours:
match colour.lower():
case 'c0ffc0' | 'c00000':
- point = (point[0] - 1, point[1])
+ result = (result[0] - 1, result[1])
case '00c000' | 'ffc0c0':
- point = (point[0] + 1, point[1])
+ result = (result[0] + 1, result[1])
case 'ffffc0' | '0000c0':
- point = (point[0], point[1] - 1)
+ result = (result[0], result[1] - 1)
case 'c0c000' | 'c0c0ff':
- point = (point[0], point[1] + 1)
+ result = (result[0], result[1] + 1)
case 'ffffff':
continue
case '000000':
break
- return point
+ return result