ответ здесь 2.
Код: Выделить всё
#shortest distance between two point, with x representing distance
import numpy as np
map= input()
lst = []
#filtering out commas
for points in map:
if points.isalpha()==True:
lst.append(points)
#converting list of points to array
axis= np.array(lst)
#turning 1d array to 5d
twoD_axis= axis.reshape(5,5)
#to collect index of array with "p"
row=[]
#to collect index of "p" in array
column=[]
count=-1
#iterating through array,checking for "p"and using "count" to get index of array with "p"
for i in twoD_axis:
count+=1
if "p" in i:
#keeping index of p in "row"
row.append(count)
count_2=-1
#iterating through array with "p",using "count" to get index of first "p"
for i in twoD_axis[row[0]]:
count_2+=1
if i=="p":
#keeping index of first p in "column"
column.append(count_2)
count_3=-1
#iterating through array with "p",using "count" to get index of second "p"
for i in twoD_axis[row[1]]:
count_3+=1
if i=="p":
#keeping index of second p in "column"
column.append(count_3)
#subtracting indexes of ps, to get number of xs going down
vertical= row[1]-row[0]
#subtracting indexes of ps, to get number of xs going left or right
horizontal= column[1]-column[0]
#summming all xs
print(vertical+horizontal)
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-on-a-map