Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Black holes solution in Uncategorized category for Black Holes by capback250
# migrated from python 2.7
from math import acos, hypot, sqrt, pi
def checkio(bholes):
if len(bholes) < 2:
return bholes
flag = True
while flag:
flag = False
for nextHole in [[x[0], x[1]] for x in sorted([[i, j, hypot(i[0] - j[0], i[1] - j[1])] for i in bholes for j in bholes if i != j], key=lambda c: (c[2], c[0]))]:
a, b = sorted(nextHole, key=lambda x: x[2])
print(a, b)
if eating(a, b):
bholes[bholes.index(a)] = eating(a, b)
bholes.remove(b)
flag = True
break
return bholes
def eating(h1, h2):
small, big = sorted([h1, h2], key=lambda x:x[2])
R, r, d = big[2], small[2], hypot(h1[0] - h2[0], h1[1] - h2[1])
S1, S2 = pi * r * r, pi * R * R
if r + R >= d and R <= r + d and d:
p1 = r * r * acos((d * d + r * r - R * R) / (2 * d * r))
p2 = R * R * acos((d * d + R * R - r * r) / (2 * d * R))
p3 = .5 * sqrt((-d + r + R) * (d + r - R) * (d - r + R) * (d + r + R))
intersect = p1 + p2 - p3
elif not d:
intersect = min(S1, S2)
elif R > r + d:
newR = round(sqrt((S1 + S2) / pi), 2)
return [big[0], big[1], newR]
elif d > r + R:
return False
proportion1, proportion2 = intersect * 100 / S1, intersect * 100 / S2
domination = abs(100 - S2 * 100 / S1)
if domination >= 20 and (proportion1 >= 55 or proportion2 >= 55) and d <= r + R:
newR = round(sqrt((S1+S2) / pi), 2)
return [big[0], big[1], newR]
return False
Feb. 20, 2016