Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sum distance solution in Clear category for Compass, Map and Spyglass by HeNeArKr
def distance(pt1, pt2):
""" Return distance between points pt1 and pt2. """
return max(abs(pt1[0]-pt2[0]), abs(pt1[1]-pt2[1]))
def navigation(seaside):
""" Return sum of distances from 'Y' to each goal 'C', 'M', and 'S'.
Assumes all three goals are present.
"""
cells = {val: (r, c) for r, row in enumerate(seaside)
for c, val in enumerate(row) if str(val) in 'YCMS'}
return sum(distance(cells['Y'], cells[other]) for other in 'CMS')
Sept. 5, 2018
Comments: