You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 anni fa
123456789101112131415
  1. from itertools import permutations
  2. places = set()
  3. mapping = {}
  4. for line in df.read_text().splitlines():
  5. A, _, B, _, val = line.split()
  6. places.update({A, B})
  7. mapping[A, B] = mapping[B, A] = int(val)
  8. length = lambda combo: sum(mapping[pair] for pair in zip(combo, combo[1:]))
  9. lengths = [length(combo) for combo in permutations(places)]
  10. ans1 = min(lengths)
  11. ans2 = max(lengths)