Given two circles C1 of radius R1 and C2 of radius R2,centered at (X1,Y1) and (X2,Y2) respectively.Find out whether they touch(at one or more than one points).
Example 1:
Input:
X1=3
Y1=4
R1=5
X2=14
Y2=18
R2=8
Output:
0
Explanation:
The circles centred at (3,4) and (14,18)
and having radii 5 and 8 respectively
do not touch each other.
Example 2:
Input:
X1=3
Y1=4
R1=5
X2=14
Y2=18
R2=18
Output:
1
Explanation:
The circles centred at (3,4) and (14,18)
and having radii 5 and 18 respectively
touch each other at two points.
Your Task:
You don't need to read input or print anything.Your Task is to complete the function circleTouch() which takes 6 integers X1,Y1,R1,X2,Y2 and R2 as input parameters and returns 0 if the circle does not touch each other at all.Otherwise it returns 1.
Expected Time Complexity:O(1)
Expected Auxillary Space:O(1)
Constraints:
-10^{4}<=X1,Y1,X2,Y2<=10^{4}
1<=R1,R2<=10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def circleTouch(self,X1,Y1,R1,X2,Y2,R2):
        #code here

Solutions:
import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distance = int(math.sqrt((X2 - X1) ** 2 + (Y2 - Y1) ** 2))
		if distance < R1 + R2:
			return 1
		else:
			return 0


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		res = 0
		v1 = (X2 - X1) ** 2
		v2 = (Y2 - Y1) ** 2
		d = math.sqrt(v1 + v2)
		if d < R1 + R2:
			res = 1
		return res


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		limit = ((X1 - X2) ** 2 + (Y1 - Y2) ** 2) ** 0.5
		if R1 + R2 > limit:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, x1, y1, r1, x2, y2, r2):
		d = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** (1 / 2)
		if d <= r1 - r2:
			return 1
		elif d <= r2 - r1:
			return 1
		elif d < r1 + r2:
			return 1
		elif d == r1 + r2:
			return 1
		else:
			return 0


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		d = math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2))
		if d == R1 + R2 or d < R1 + R2 or d <= abs(R1 - R2):
			return 1
		else:
			return 0


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		(DX, DY, R) = (abs(X1 - X2), abs(Y1 - Y2), R1 + R2)
		D2 = DX ** 2 + DY ** 2
		D = math.sqrt(D2)
		if D > R:
			return 0
		else:
			return 1


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		sq = math.sqrt((X2 - X1) * (X2 - X1) + (Y1 - Y2) * (Y1 - Y2))
		if sq > R1 + R2:
			return 0
		return 1


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		d = math.sqrt(math.pow(Y2 - Y1, 2) + math.pow(X2 - X1, 2))
		if d <= R1 + R2:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		if (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1) >= (R1 + R2) ** 2:
			return 0
		return 1


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		dif = (X2 - X1) ** 2 + (Y2 - Y1) ** 2
		sumr = (R1 + R2) ** 2
		return int(dif <= sumr)


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distanceBetweenCentresSquared = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)
		sumOfRadiiSquared = (R2 + R1) * (R2 + R1)
		return int(distanceBetweenCentresSquared <= sumOfRadiiSquared)


from math import sqrt

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		dist = sqrt((X2 - X1) ** 2 + (Y2 - Y1) ** 2)
		if dist > R1 + R2:
			return 0
		return 1


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		dist = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)
		rsum = (R2 + R1) * (R2 + R1)
		return int(dist <= rsum)


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distance = (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2)
		distance = distance ** 0.5
		if distance == R1 + R2:
			return 1
		elif distance < R1 + R2:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		r1 = R1
		r2 = R2
		d = int((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2)) ** (1 / 2)
		if d <= r1 - r2:
			return 1
		elif d <= r2 - r1:
			return 1
		elif d < r1 + r2:
			return 1
		elif d == r1 + r2:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		X3 = X1 - X2
		Y3 = Y1 - Y2
		z = (X3 ** 2 + Y3 ** 2) ** 0.5
		if z > R1 + R2:
			return 0
		else:
			return 1


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		x3 = X1 - X2
		x = x3 * x3
		y3 = Y1 - Y2
		y = y3 * y3
		z = x + y
		d = math.sqrt(z)
		if int(R1 + R2) >= d:
			return 1
		else:
			return 0


from math import *

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		x = (X1 - X2) ** 2
		y = (Y1 - Y2) ** 2
		distance = sqrt(x + y)
		if distance <= R1 + R2:
			return 1
		else:
			return 0


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		sumRadii = R1 + R2
		centres = math.sqrt((X2 - X1) ** 2 + (Y2 - Y1) ** 2)
		if centres > sumRadii:
			return 0
		else:
			return 1


class Solution:

	def circleTouch(self, x1, y1, r1, x2, y2, r2):
		d = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5
		if d <= r1 + r2:
			return 1
		return 0


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		r1 = R1
		r2 = R2
		d = math.sqrt(int((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2)))
		if d <= r1 - r2:
			return 1
		elif d <= r2 - r1:
			return 1
		elif d < r1 + r2:
			return 1
		elif d == r1 + r2:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distance = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)
		sumR = (R1 + R2) * (R1 + R2)
		return int(distance <= sumR)


class Solution:

	def circleTouch(self, x1, y1, r1, x2, y2, r2):
		dis = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		return int(dis < r1 + r2)


class Solution:
	import math

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		F = (X1 - X2) ** 2
		S = (Y1 - Y2) ** 2
		D = (F + S) ** (1 / 2)
		if D <= R1 + R2:
			return 1
		return 0


class Solution:
	import math

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		c = (X1 - X2) ** 2
		f = (Y1 - Y2) ** 2
		d = (c + f) ** (1 / 2)
		if d <= R1 + R2:
			return 1
		else:
			return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		dist = (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2)
		sum = (R1 + R2) * (R1 + R2)
		return int(sum >= dist)


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		X = (X2 - X1) ** 2
		Y = (Y2 - Y1) ** 2
		d1 = (X + Y) ** 0.5
		d2 = R1 + R2
		if d1 == d2 or d1 > d2:
			return 0
		else:
			return 1


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distance = ((X2 - X1) ** 2 + (Y2 - Y1) ** 2) ** 0.5
		sum_radius = R1 + R2
		if distance <= sum_radius:
			return 1
		return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		d = pow(pow(X2 - X1, 2) + pow(Y2 - Y1, 2), 0.5)
		c = R1 + R2
		return 0 if d > c else 1


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		ct = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)
		sm = (R1 + R2) * (R1 + R2)
		return int(ct <= sm)


class Solution:

	def circleTouch(self, x1, y1, R1, x2, y2, R2):
		a = int(((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5)
		b = R1 + R2
		if a >= b:
			return 0
		else:
			return 1


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		d = (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2)
		s = (R1 + R2) * (R1 + R2)
		return int(d <= s)


class Solution:

	def circleTouch(self, x1, y1, R1, x2, y2, R2):
		distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** (1 / 2)
		if distance <= R1 + R2:
			return 1
		return 0


class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		dist = pow(pow(X2 - X1, 2) + pow(Y2 - Y1, 2), 0.5)
		centres = R1 + R2
		return int(dist <= centres)


import math

class Solution:

	def circleTouch(self, X1, Y1, R1, X2, Y2, R2):
		distance = ((X1 - X2) ** 2 + (Y1 - Y2) ** 2) ** 0.5
		R = R1 + R2
		if distance > R:
			return 0
		return 1


class Solution:

	def circleTouch(self, x1, y1, r1, x2, y2, r2):
		dist = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		r = r1 + r2
		if dist > r:
			return 0
		else:
			return 1