Given coordinates of 2 points on a cartesian plane, find the distance between them rounded up to nearest integer. 
Example 1:
Input: 0 0 2 -2
Output: 3
Explanation: Distance between (0, 0) 
and (2, -2) is 3.
Example 2:
Input: -20 23 -15 68
Output: 45
Explanation: Distance between (-20, 23) 
and (-15, 68) is 45.
Your Task:
You don't need to read or print anything. Your task is to complete the function distance() which takes x1, y1, x2 and y2 as input parameter and returns the distance between the given two points.
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
Constraints:
-1000 <= x1, y1, x2, y2 <= 1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Geometry

Mathematics

Starter code: #User function Template for python3

class Solution:
	def distance(self, x1, y1, x2, y2):
		# Code here

Solutions:
class Solution:

	def distance(self, x1, y1, x2, y2):
		a = (x1 - x2) ** 2
		b = (y1 - y2) ** 2
		return round((a + b) ** 0.5)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		return int(round(math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)), 0))


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		distance = round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))
		return distance


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		x_dif = x2 - x1
		y_dif = y2 - y1
		sq1 = x_dif ** 2
		sq2 = y_dif ** 2
		dis1 = sq1 + sq2
		dis2 = math.sqrt(dis1)
		dis2 = round(dis2)
		return dis2


class Solution:

	def distance(self, x1, y1, x2, y2):
		return int(((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 + 0.5)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		A = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		if abs(A - math.ceil(A)) > abs(A - math.floor(A)):
			return math.floor(A)
		else:
			return math.ceil(A)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		result = round(((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2))
		return result


class Solution:

	def distance(self, x1, y1, x2, y2):
		a = round(((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2))
		return a


class Solution:

	def distance(self, x1, y1, x2, y2):
		c = round(((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5)
		return c


import math
import numpy as np

class Solution:

	def distance(self, x1, y1, x2, y2):
		return int(round(math.sqrt(np.square(x1 - x2) + np.square(y1 - y2)), 0))


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		dis = math.pow(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2), 0.5)
		return round(dis)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		(dx, dy) = (abs(x1 - x2), abs(y1 - y2))
		d2 = dx ** 2 + dy ** 2
		d = math.sqrt(d2)
		return round(d)


class Solution:

	def distance(self, x1, y1, x2, y2):
		import math
		num1 = x2 - x1
		num2 = y2 - y1
		num1 *= num1
		num2 *= num2
		num = num1 + num2
		num = math.sqrt(num)
		num = round(num)
		return num


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		sum = (x2 - x1) ** 2 + (y2 - y1) ** 2
		ans = sum ** 0.5
		if ans - int(ans) > 0.5:
			return math.ceil(ans)
		else:
			return math.floor(ans)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
		p = d - int(d)
		q = int(d + 1) - d
		if p > q:
			return int(d + 1)
		else:
			return int(d)


from math import sqrt, ceil, floor

class Solution:

	def distance(self, x1, y1, x2, y2):
		ans = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
		lower = floor(ans)
		higher = ceil(ans)
		if abs(lower - ans) < abs(higher - ans):
			return lower
		else:
			return higher


class Solution:

	def distance(self, x1, y1, x2, y2):
		xf = x1 - x2
		x3 = xf * xf
		yf = y1 - y2
		y3 = yf * yf
		d = x3 + y3
		ans = d ** (1 / 2)
		h = int(ans)
		i = ans - h
		if i >= 0.5:
			return h + 1
		else:
			return h


class Solution:

	def distance(self, x1, y1, x2, y2):
		d = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) ** 0.5
		return round(d)


from math import sqrt

class Solution:

	def distance(self, x1, y1, x2, y2):
		dist = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
		return int(round(dist))


from math import sqrt

class Solution:

	def distance(self, x1, y1, x2, y2):
		n1 = pow(x2 - x1, 2)
		n2 = pow(y2 - y1, 2)
		n = sqrt(n1 + n2)
		s = round(n, 0)
		return int(s)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		x = (x1 - x2) ** 2
		y = (y1 - y2) ** 2
		return round((x + y) ** 0.5)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		l = (x2 - x1) ** 2
		p = (y2 - y1) ** 2
		a = math.sqrt(l + p)
		return round(a)


class Solution:

	def distance(self, x1, y1, x2, y2):
		ans = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
		if ans - int(ans) >= 0.5:
			return int(ans) + 1
		else:
			return int(ans)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		X = x1 - x2
		Y = y1 - y2
		z = (X ** 2 + Y ** 2) ** 0.5
		return round(z)


import math

class Solution:

	def distance(self, x1, y1, x2, y2):
		x3 = x2 - x1
		x = x3 * x3
		y3 = y2 - y1
		y = y3 * y3
		z = x + y
		return int(round(math.sqrt(z)))


class Solution:

	def distance(self, x1, y1, x2, y2):
		d = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5
		td = int(d)
		if d - td >= 0.5:
			return td + 1
		return td


import math as m

class Solution:

	def distance(self, x1, y1, x2, y2):
		return int(round(m.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)))


class Solution:

	def distance(self, x1, y1, x2, y2):
		d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		k = int(d)
		if d == k:
			return k
		elif d - k >= 0.5:
			return k + 1
		elif d - k < 0.5:
			return k