Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. from itertools import permutations
  5.  
  6. def sanitize(st):
  7.     _st = st
  8.     for ch in ["(", ")", "[", "]", "'"]:
  9.         _st = _st.replace(ch, "")
  10.     return _st.replace(", ", ",").replace("\\n", "|")
  11.  
  12. user_pos = []
  13. pois = []
  14. i = 0
  15. for line in sys.stdin:
  16.     if i == 0:
  17.         user_pos = line.split(",")
  18.         #user_pos = [float(v) for v in user_pos]
  19.         i = 1
  20.     else:
  21.         poi = line.split(",")
  22.         pois.append(poi)
  23.  
  24. possible_paths = map(list, permutations(pois))
  25. if len(pois) % 2 == 0:
  26.     for path in possible_paths:
  27.         path.append(path[-1])
  28. for path in possible_paths:
  29.     if path[0] != user_pos and path[1] != user_pos:
  30.         print sanitize("%s%s"%(str(user_pos), str(path))).replace("|,", "|").strip("|")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement