Решение на Навигация на Piet от Георги Чобанов

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

Към профила на Георги Чобанов

Резултати

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

Код

def calculate_final_vector(starting_point, colours):
colours_dict = {
'00C000' : (1,0),
'C0FFC0' : (-1,0),
'C00000' : (-1,0),
'FFFFFF' : (0,0),
'000000' : (0,0),
'C0C000' : (0,1),
'FFFFC0' : (0,-1),
'FFC0C0' : (1,0),
'0000C0' : (0,-1),
'C0C0FF' : (0,1)
}
if len(starting_point) != 2:
return 'starting point length must be 2'
dist_point = list(starting_point)
for colour in colours:
if colour.upper() not in colours_dict:
return 'colour is not found'
for colour in colours:
if colour == '000000':
break
dist_point[0] += colours_dict[colour.upper()][0]
dist_point[1] += colours_dict[colour.upper()][1]
return tuple(dist_point)

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

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

OK

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

Георги обнови решението на 20.10.2022 11:47 (преди около 2 години)

+def calculate_final_vector(starting_point, colours):
+ colours_dict = {
+ '00C000' : [1,0],
+ 'C0FFC0' : [-1,0],
+ 'C00000' : [-1,0],
+ 'FFFFFF' : [0,0],
+ 'C0C000' : [0,1]
+ }
+ if len(starting_point) != 2:
+ return 'starting point length must be 2'
+ dist_point = list(starting_point)
+ for colour in colours:
+ if colour.upper() not in colours_dict:
+ return 'colour is not found'
+ for colour in colours:
+ dist_point[0] += colours_dict[colour.upper()][0]
+ dist_point[1] += colours_dict[colour.upper()][1]
+ return tuple(dist_point[:])

Георги обнови решението на 20.10.2022 11:50 (преди около 2 години)

def calculate_final_vector(starting_point, colours):
colours_dict = {
- '00C000' : [1,0],
- 'C0FFC0' : [-1,0],
- 'C00000' : [-1,0],
- 'FFFFFF' : [0,0],
- 'C0C000' : [0,1]
+ '00C000' : (1,0),
+ 'C0FFC0' : (-1,0),
+ 'C00000' : (-1,0),
+ 'FFFFFF' : (0,0),
+ 'C0C000' : (0,1)
}
if len(starting_point) != 2:
return 'starting point length must be 2'
dist_point = list(starting_point)
for colour in colours:
if colour.upper() not in colours_dict:
return 'colour is not found'
for colour in colours:
dist_point[0] += colours_dict[colour.upper()][0]
dist_point[1] += colours_dict[colour.upper()][1]
return tuple(dist_point[:])

Решението е супер с една малка забележка - няма нужда да правиш копие на dist_point преди да го прехвърлиш към tuple, не би следвало tuple(dist_point) да има страничен ефект. Пък дори и да имаше, на теб спира да ти пука за dist_point в този момент.

Георги обнови решението на 24.10.2022 09:46 (преди около 2 години)

def calculate_final_vector(starting_point, colours):
colours_dict = {
'00C000' : (1,0),
'C0FFC0' : (-1,0),
'C00000' : (-1,0),
'FFFFFF' : (0,0),
'C0C000' : (0,1)
}
if len(starting_point) != 2:
return 'starting point length must be 2'
dist_point = list(starting_point)
for colour in colours:
if colour.upper() not in colours_dict:
return 'colour is not found'
for colour in colours:
dist_point[0] += colours_dict[colour.upper()][0]
dist_point[1] += colours_dict[colour.upper()][1]
- return tuple(dist_point[:])
+ return tuple(dist_point)

Георги обнови решението на 25.10.2022 15:09 (преди около 2 години)

def calculate_final_vector(starting_point, colours):
colours_dict = {
'00C000' : (1,0),
'C0FFC0' : (-1,0),
'C00000' : (-1,0),
'FFFFFF' : (0,0),
- 'C0C000' : (0,1)
+ '000000' : (0,0),
+ 'C0C000' : (0,1),
+ 'FFFFC0' : (0,-1),
+ 'FFC0C0' : (1,0),
+ '0000C0' : (0,-1),
+ 'C0C0FF' : (0,1)
+
}
if len(starting_point) != 2:
return 'starting point length must be 2'
dist_point = list(starting_point)
for colour in colours:
if colour.upper() not in colours_dict:
return 'colour is not found'
for colour in colours:
dist_point[0] += colours_dict[colour.upper()][0]
dist_point[1] += colours_dict[colour.upper()][1]
- return tuple(dist_point)
+ return tuple(dist_point[:])

Георги обнови решението на 25.10.2022 15:15 (преди около 2 години)

def calculate_final_vector(starting_point, colours):
colours_dict = {
'00C000' : (1,0),
'C0FFC0' : (-1,0),
'C00000' : (-1,0),
'FFFFFF' : (0,0),
'000000' : (0,0),
'C0C000' : (0,1),
'FFFFC0' : (0,-1),
'FFC0C0' : (1,0),
'0000C0' : (0,-1),
'C0C0FF' : (0,1)
}
if len(starting_point) != 2:
return 'starting point length must be 2'
dist_point = list(starting_point)
for colour in colours:
if colour.upper() not in colours_dict:
return 'colour is not found'
for colour in colours:
+ if colour == '000000':
+ break
dist_point[0] += colours_dict[colour.upper()][0]
dist_point[1] += colours_dict[colour.upper()][1]
- return tuple(dist_point[:])
+ return tuple(dist_point)