Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import sys
  2.  
  3. a = [1,5,9,13,34,55]
  4. b = [3,4,6,15,40]
  5. c = [2,7,60,70]
  6.  
  7.  
  8. def get_distance(a_word, b_word, c_word):
  9. maxint = max(a_word, b_word, c_word)
  10. minint = min(a_word, b_word, c_word)
  11. return maxint - minint
  12.  
  13.  
  14. def find_shortest_bounds(a, b, c):
  15. a_dist = sys.maxint
  16. c_dist = sys.maxint
  17.  
  18. final_a = None
  19. final_b = None
  20. final_c = None
  21.  
  22. for a_word in a:
  23. b_dist = sys.maxint
  24. for b_word in b:
  25. for c_word in c:
  26. distance = get_distance(a_word, b_word, c_word)
  27. if distance > c_dist:
  28. break
  29. else:
  30. c_dist = distance
  31. final_c = c_word
  32. if c_dist >= b_dist:
  33. break
  34. else:
  35. b_dist = c_dist
  36. final_b = b_word
  37. if b_dist >= a_dist:
  38. break
  39. else:
  40. a_dist = b_dist
  41. final_a = a_word
  42. return a_dist, (final_a, final_b, final_c)
  43.  
  44.  
  45. def long_find_shortest_bounds(a,b,c):
  46. distance = sys.maxint
  47. cur_bounds = tuple()
  48. for a_word in a:
  49. for b_word in b:
  50. for c_word in c:
  51. cur_dist = get_distance(a_word, b_word, c_word)
  52. if cur_dist < distance:
  53. distance = cur_dist
  54. cur_bounds = (a_word, b_word, c_word)
  55. return distance, cur_bounds
  56.  
  57. print find_shortest_bounds(a,b,c)
  58. print long_find_shortest_bounds(a,b,c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement