Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- a = [1,5,9,13,34,55]
- b = [3,4,6,15,40]
- c = [2,7,60,70]
- def get_distance(a_word, b_word, c_word):
- maxint = max(a_word, b_word, c_word)
- minint = min(a_word, b_word, c_word)
- return maxint - minint
- def find_shortest_bounds(a, b, c):
- a_dist = sys.maxint
- c_dist = sys.maxint
- final_a = None
- final_b = None
- final_c = None
- for a_word in a:
- b_dist = sys.maxint
- for b_word in b:
- for c_word in c:
- distance = get_distance(a_word, b_word, c_word)
- if distance > c_dist:
- break
- else:
- c_dist = distance
- final_c = c_word
- if c_dist >= b_dist:
- break
- else:
- b_dist = c_dist
- final_b = b_word
- if b_dist >= a_dist:
- break
- else:
- a_dist = b_dist
- final_a = a_word
- return a_dist, (final_a, final_b, final_c)
- def long_find_shortest_bounds(a,b,c):
- distance = sys.maxint
- cur_bounds = tuple()
- for a_word in a:
- for b_word in b:
- for c_word in c:
- cur_dist = get_distance(a_word, b_word, c_word)
- if cur_dist < distance:
- distance = cur_dist
- cur_bounds = (a_word, b_word, c_word)
- return distance, cur_bounds
- print find_shortest_bounds(a,b,c)
- print long_find_shortest_bounds(a,b,c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement