Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
numpy.ndarray.max solution in 3rd party category for Compass, Map and Spyglass by Jay-Jay-D
from numpy import array, argwhere, abs
def navigation(seaside):
"""
Your task is to count the sum of the number of steps required to pick up all 3 items - ('C' - compass), ('M' - map),
('S' - spyglass) from your starting position. So the result will be the sum of distance from Y to C, from Y to M and
from Y to S (not Y-C-M-S).
Note that you can walk in 8 directions - left, right, up, down and sideways (on the diagonal in any direction).
Your starting position is 'Y'.
:param seaside: Array with the objects placements.
:return: The length of the path.
"""
map_as_matrix = array(seaside)
origin = argwhere(map_as_matrix == 'Y')[0]
path_length = 0
for mark in ['C', 'M', 'S']:
destination = argwhere(map_as_matrix == mark)[0]
travel = abs(origin - destination)
path_length += travel.max()
return int(path_length)
Sept. 8, 2018
Comments: