Created
March 26, 2018 06:19
-
-
Save venuktan/52131fb43349a548a51d5e0ed867666e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def minArea(x, y, k): | |
# def eucledian_dist(a,b): | |
# return sqrt(sum( (a - b)**2 for a, b in zip(a, b))) | |
# d = eucledian_dist(x,y) | |
def avg(l): | |
return sum (l) / float (len (l)) | |
def stats(x, y): | |
x_min = min (x) | |
x_max = max (x) | |
y_min = min (y) | |
y_max = max (y) | |
return x_min, x_max, y_min, y_max | |
while k < len (x): | |
x_min, x_max, y_min, y_max = stats (x, y) | |
if (x_max - x_min) > (y_max - y_min): | |
min_idx = x.index (x_min) | |
else: | |
min_idx = y.index (y_min) | |
del x[min_idx] | |
del y[min_idx] | |
x_min, x_max, y_min, y_max = stats (x, y) | |
sq_xmin = x_min - 1 | |
sq_xmax = x_max + 1 | |
sq_ymin = y_min - 1 | |
sq_ymax = y_max + 1 | |
w = sq_xmax - sq_xmin | |
h = sq_ymax - sq_ymin | |
if w > h: | |
sq_xmax += w - h | |
return w ** 2 | |
elif h > w: | |
sq_ymax += h - w | |
return h ** 2 | |
return k |
Author
venuktan
commented
Mar 26, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment