Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Compass, Map and Spyglass by kuzdras
def navigation(seaside):
for row in range(len(seaside)):
for column in range(len(seaside[row])):
if seaside[row][column] == "Y":
y = [row, column]
elif seaside[row][column] == "C":
c = [row, column]
elif seaside[row][column] == "M":
m = [row, column]
elif seaside[row][column] == "S":
s = [row, column]
route = 0
for a in [c, m, s]:
route += max((abs(y[0] - a[0])), (abs(y[1] - a[1])))
return route
if __name__ == '__main__':
print("Example:")
print(navigation([['Y', 0, 0, 0, 'C'],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
['M', 0, 0, 0, 'S']]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert navigation([['Y', 0, 0, 0, 'C'],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
['M', 0, 0, 0, 'S']]) == 11
assert navigation([[ 0, 0, 'C'],
[ 0, 'S', 0],
['M','Y', 0]]) == 4
assert navigation([[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 'M', 0, 'S', 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 'C', 0, 0, 0],
[ 0, 'Y',0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0]]) == 9
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 21, 2018
Comments: