Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt, floor
- def tour(friends, friend_towns, home_to_town_distances):
- print(friends, friend_towns, home_to_town_distances)
- total_km = 0
- friends = [x for x in friends for j in range(len(friend_towns)) if x in friend_towns[j] ]
- friend_towns = [x for x in friend_towns if x[0] in friends]
- for i in range(len(friends)):
- for j in range(len(friend_towns)):
- if friends[i] in friend_towns[j]:
- if i == 0:
- total_km += home_to_town_distances[friend_towns[j][1]]
- break
- else:
- total_km += sqrt(home_to_town_distances[friend_towns[j][1]] ** 2 -
- home_to_town_distances[friend_towns[j - 1][1]] ** 2)
- break
- total_km += home_to_town_distances[friend_towns[j][1]]
- return floor(total_km)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement