Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math, check
- def distance (x1,y1, x2,y2):
- return math.sqrt( ((x1-x2) ** 2) + ((y1-y2) ** 2))
- # min_dist(x1, y1, x2, y2, x3, y3) consumes 6 float values
- # (x1 to x3, and y1 to y3) where each pair of xy with the same numbers
- # represents a coordinate of the house's condition. The function returns
- # the closest house from the two houses
- # min_dist: Float Float Float Float Float Float
- # -> (anyof "House1" "House2" "House3")
- # Examples:
- def min_dist(x1, y1, x2, y2, x3, y3):
- h1_h2 = distance(x1, y1, x2, y2)
- h1_h3 = distance(x1, y1, x3, y3)
- h2_h3 = distance(x2, y2, x3, y3)
- sum_h1 = h1_h2 + h1_h3
- sum_h2 = h1_h2 + h2_h3
- sum_h3 = h1_h3 + h2_h3
- print(sum_h1, sum_h2, sum_h3)
- if min(sum_h1, sum_h2, sum_h3) == sum_h1:
- return "House 1"
- elif min(sum_h1, sum_h2, sum_h3) == sum_h2:
- return "House 2"
- elif min(sum_h1, sum_h2, sum_h3) == sum_h3:
- return "House 3"
- elif sum_h1 == sum_h2 and sum_h2 == sum_h3:
- return "House 1"
- # Test 8
- check.expect("Q1T8", min_dist(0, 0, 0.5, 0.5 * math.sqrt(3), 1, 0), "House 1")
- # Test 9
- check.expect("Q1T9", min_dist(0.5, 0.5 * math.sqrt(3), 0, 0, 1, 0), "House 1")
- # Test 8
- check.expect("Q1T8", min_dist(1, 0, 0.5, 0.5 * math.sqrt(3), 0, 0), "House 1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement