Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
math solution in Uncategorized category for Black Holes by DaveDiFranco
from math import acos, pi
from itertools import combinations
def checkio(data):
n=len(data)
oldn=n+1
while n>1 and n!=oldn:
oldn=n
combos = combinations(data,2)
combos = sorted(combos, key=dist)
for c in combos:
c1,c2 = c
x1,y1,r1=c1
x2,y2,r2=c2
if overlap(c)>.55:
R=ratio(c1,c2)
if R>1.2:
data[data.index(c1)]=(x1,y1,newarea(r1,r2))
data.remove(c2)
break
elif 1/R>1.2:
data[data.index(c2)]=(x2,y2,newarea(r1,r2))
data.remove(c1)
break
n=len(data)
return data
def dist(c):
c1,c2=c
x1,y1,r1=c1
x2,y2,r2=c2
return ((x1-x2)**2+(y1-y2)**2)**.5
#see http://mathworld.wolfram.com/Circle-CircleIntersection.html
def overlap(c):
c1,c2=c
x1,y1,r1=c1
x2,y2,r2=c2
d=dist(c)
if d==0: return 1
try:
a = (r1**2) * acos((d**2+r1**2-r2**2)/2/d/r1)
a += (r2**2) * acos((d**2+r2**2-r1**2)/2/d/r2)
a -= (((r1-r2-d)*(r2-r1-d)*(r1+r2-d)*(r1+r2+d))**.5)/2
except ValueError:
if d
Oct. 19, 2015