Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Three Points Circle by Lukeram
import numpy
def checkio(data):
a = data.split(',')
for i in range( len(a) ):
if i % 2 == 0:
a[i]=int(a[i][1])
else:
a[i]=int(a[i][0:len(a[i])-1])
m=[ [a[0]**2+a[1]**2, a[1], 1],
[a[2]**2+a[3]**2, a[3], 1],
[a[4]**2+a[5]**2, a[5], 1]]
n=[ [a[0], a[0]**2+a[1]**2, 1],
[a[2], a[2]**2+a[3]**2, 1],
[a[4], a[4]**2+a[5]**2, 1]]
l=[ [a[0],a[1],1],
[a[2],a[3],1],
[a[4],a[5],1]]
x= numpy.linalg.det(m) / (2* numpy.linalg.det(l))
y= numpy.linalg.det(n) / (2* numpy.linalg.det(l))
r=( (a[0]-x)**2+(a[1]-y)**2 )**(1/2)
print (r)
r=round(r,2)
x=round(x,2)
y=round(y,2)
if r % 1 == 0:
r=int(r)
if x % 1 == 0:
x=int(x)
if y % 1 == 0:
y=int(y)
stra="(x"+str(-x)+")^2+(y"+str(-y)+")^2="+str(r)+"^2"
print (stra)
#replace this for solution
return stra
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("(3,7),(6,9),(9,7)") == "(x-6)^2+(y-5.75)^2=3.25^2"
assert checkio("(2,2),(6,2),(2,6)") == "(x-4)^2+(y-4)^2=2.83^2"
assert checkio("(6,6),(2,9),(1,6)") == "(x-3.5)^2+(y-6.83)^2=2.64^2"
Nov. 20, 2016