Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
comment one by one solution in Clear category for Compass, Map and Spyglass by Sim0000
def navigation(seaside):
# distance function
d = lambda c1, c2: max(abs(pos[c2][1] - pos[c1][1]), abs(pos[c2][0] - pos[c1][0]))
# seaside size
Y, X = len(seaside), len(seaside[0])
# all items position
pos = {seaside[y][x] : (y, x) for y in range(Y) for x in range(X) if seaside[y][x]}
# return required distance
return d('Y', 'C') + d('Y', 'M') + d('Y', 'S')
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. 7, 2018