Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Babysteps solution in Clear category for Compass, Map and Spyglass by Tical_1000
def navigation(seaside):
coord = {}
objects = ["Y", "C", "M", "S"]
count = 0
for area in seaside:
for obj in objects:
if obj in area:
coord[obj] = (count, area.index(obj))
count += 1
res = 0
for obj in objects[1:4]:
res += max(
abs(coord["Y"][0] - coord[obj][0]),
abs(coord["Y"][1] - coord[obj][1])
)
return res
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!")
Feb. 12, 2019
Comments: