Advertisement
Guest User

Untitled

a guest
Dec 14th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from math import sqrt, floor
  2.  
  3.  
  4. def tour(friends, friend_towns, home_to_town_distances):
  5.     print(friends, friend_towns, home_to_town_distances)
  6.     total_km = 0
  7.     friends = [x for x in friends for j in range(len(friend_towns)) if x in friend_towns[j] ]
  8.     friend_towns = [x for x in friend_towns if x[0] in friends]
  9.     for i in range(len(friends)):
  10.         for j in range(len(friend_towns)):
  11.             if friends[i] in friend_towns[j]:
  12.                 if i == 0:
  13.                     total_km += home_to_town_distances[friend_towns[j][1]]
  14.                     break
  15.                 else:
  16.                     total_km += sqrt(home_to_town_distances[friend_towns[j][1]] ** 2 -
  17.                                      home_to_town_distances[friend_towns[j - 1][1]] ** 2)
  18.                     break
  19.  
  20.     total_km += home_to_town_distances[friend_towns[j][1]]
  21.     return floor(total_km)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement