Given two force vectors, find out whether they are parallel, perpendicular or neither. Let the first vector be A = a_{1} i +a_{2} j + a_{3} k and the second vector be B = b_{1} i + b_{2} j + b_{3} k.
A.B = a_{1 }* b_{1} + a_{2 }* b_{2} + a_{3 }* b_{3}
A x B = (a2 * b3 - a_{3 }* b_{2}) i - (a_{1} * b_{3} - b_{1}* a_{3}) j + (a_{1 }* b_{2} - a_{2 }* b_{1}) k
|A|^{2} = a12 + a22 + a32
If A.B = 0, then A and B are perpendicular.
If |A X B|^{2} = 0, then A and B are parallel.
Example 1:
Input: A = 3i + 2j + k, B = 6i + 4j + 2k
Output: 1
Explanation: |A X B|^{2 }= 0
Example 2:
Input: A = 4i + 6j + k, B = i - 1j + 2k
Output: 2
Explanation: A.B = 0
 
Your Task:
You don't need to read or print anything. Your task is to complete the function find() which takes A and B vector as parameter and returns 1 if they are parallel to each other, 2 if they are perpendicular to each other or 0 otherwise. A and B vectors will contain (a1,a2,a3) and (b1,b2,b3) respectively.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
 
Constraints:
-100 <= Component <= 100

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
	def find(self, A, B):
		# Code here

Solutions:
class Solution:

	def find(self, A, B):
		par = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		per = [A[1] * B[2] - A[2] * B[1], A[0] * B[2] - A[2] * B[0], A[0] * B[1] - A[1] * B[0]]
		s = 0
		for i in per:
			s += i ** 2
		if s == 0:
			return 1
		elif par == 0:
			return 2
		else:
			return 0


class Solution:

	def find(self, A, B):
		if A[0] * B[0] + A[1] * B[1] + A[2] * B[2] == 0:
			return 2
		elif A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - B[0] * A[2]) + (A[0] * B[1] - A[1] * B[0]) == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		t1 = A[1] * B[2] - A[2] * B[1]
		t2 = A[0] * B[2] - B[0] * A[2]
		t3 = A[0] * B[1] - B[0] * A[1]
		sum_of_squares = t1 * t1 + t2 * t2 + t3 * t3
		res = ''
		if dot == 0:
			res = 2
		elif sum_of_squares == 0:
			res = 1
		else:
			res = 0
		return res


class Solution:

	def find(self, a, b):
		if a[0] * b[0] + a[1] * b[1] + a[2] * b[2] == 0:
			return 2
		elif a[1] * b[2] - a[2] * b[1] - (a[0] * b[2] - b[0] * a[2]) + (a[0] * b[1] - a[1] * b[0]) == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		axb = (A[1] * B[2] - A[2] * B[1]) ** 2 + (B[0] * A[2] - A[0] * B[2]) ** 2 + (A[0] * B[1] - A[1] * B[0]) ** 2
		if dot == 0:
			return 2
		elif axb == 0:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		PERPENDICULAR = 1
		PARALLEL = 2
		NONE = 0
		acum = 0
		N_A = len(A)
		for i in range(0, N_A):
			acum += A[i] * B[i]
		A_B = []
		A_B.append(A[1] * B[2] - A[2] * B[1])
		A_B.append(-(A[0] * B[2] - A[2] * B[0]))
		A_B.append(+(A[0] * B[1] - A[1] * B[0]))
		producto = pow(A_B[0], 2) + pow(A_B[1], 2) + pow(A_B[2], 2)
		if producto == 0:
			return PERPENDICULAR
		if acum == 0:
			return PARALLEL
		return NONE


class Solution:

	def find(self, A, B):
		per = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		plli = A[1] * B[2] - A[2] * B[1]
		pllj = A[0] * B[2] - A[2] * B[0]
		pllk = A[0] * B[1] - A[1] * B[0]
		pll = plli ** 2 + pllj ** 2 + pllk ** 2
		if pll == 0:
			return 1
		elif per == 0:
			return 2
		else:
			return 0


class Solution:

	def magnitude2(self, a):
		return a[0] ** 2 + a[1] ** 2 + a[2] ** 2

	def find(self, a, b):
		dot = 0
		for i in range(3):
			dot += a[i] * b[i]
		cross = [a[1] * b[2] - a[2] * b[1], a[0] * b[2] - a[2] * b[0], a[0] * b[1] - a[1] * b[0]]
		cross_mag2 = self.magnitude2(cross)
		if dot == 0:
			return 2
		elif cross_mag2 == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		cross = []
		cross.append(A[1] * B[2] - A[2] * B[1])
		cross.append(-1 * (A[0] * B[2] - B[0] * A[2]))
		cross.append(A[0] * B[1] - A[1] * B[0])
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		cross = [i ** 2 for i in cross]
		if dot == 0:
			return 2
		if sum(cross) == 0:
			return 1
		else:
			return 0


from math import sqrt

class Solution:

	def find(self, A, B):
		res = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		par_res = (A[1] * B[2] - A[2] * B[1]) ** 2 + (A[0] * B[2] - B[0] * A[2]) ** 2 + (A[0] * B[1] - A[1] * B[0]) ** 2
		if res == 0:
			return 2
		if par_res == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		cross = [A[1] * B[2] - A[2] * B[1], A[0] * B[2] - B[0] * A[2], A[0] * B[1] - A[1] * B[0]]
		res = cross[0] * cross[0] + cross[1] * cross[1] + cross[2] * cross[2]
		if dot == 0:
			return 2
		elif res == 0:
			return 1
		return 0


import math

class Solution:

	def find(self, A, B):
		ab = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		axb = math.pow(A[1] * B[2] - A[2] * B[1], 2) + math.pow(A[0] * B[2] - A[2] * B[0], 2) + math.pow(A[0] * B[1] - A[1] * B[0], 2)
		if ab == 0:
			return 2
		elif axb == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot_product = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		cross_product = [A[1] * B[2] - A[2] * B[1], A[2] * B[0] - A[0] * B[2], A[0] * B[1] - A[1] * B[0]]
		mag_cross_product_squared = cross_product[0] ** 2 + cross_product[1] ** 2 + cross_product[2] ** 2
		if dot_product == 0:
			return 2
		elif mag_cross_product_squared == 0:
			return 1
		else:
			return 0


import numpy as np

class Solution:

	def find(self, A, B):
		x = np.dot(A, B)
		y = np.cross(A, B) ** 2
		if x == 0:
			return 2
		elif sum(y) == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		per = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		if per == 0:
			return 2
		par = A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - A[2] * B[0]) + (A[0] * B[1] - A[1] * B[0])
		if par == 0:
			return 1
		return 0


class Solution:

	def dot(self, v1, v2):
		dot = 0
		for i in range(3):
			dot += v1[i] * v2[i]
		return dot

	def cross(self, v1, v2):
		cross = [0, 0, 0]
		cross[0] = v1[1] * v2[2] - v1[2] * v2[1]
		cross[1] = v1[2] * v2[0] - v1[0] * v2[2]
		cross[2] = v1[0] * v2[1] - v1[1] * v2[0]
		return cross

	def mod(self, v):
		mod = 0
		for i in range(3):
			mod += v[i] ** 2
		return mod

	def find(self, A, B):
		if self.mod(self.cross(A, B)) == 0:
			return 1
		elif self.dot(A, B) == 0:
			return 2
		return 0


class Solution:

	def find(self, A, B):
		AB = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		AxB = (A[1] * B[2] - A[2] * B[1]) ** 2 - (A[0] * B[2] - B[0] * A[2]) ** 2 + (A[0] * B[1] - A[1] * B[0]) ** 2
		if AB == 0:
			return 2
		if AxB == 0:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		c = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		d = 0
		for i in range(3):
			d += A[i] * B[(i + 1) % 3] - A[(i + 1) % 3] * B[i]
		if d == 0:
			return 1
		elif c == 0:
			return 2
		else:
			return 0


class Solution:

	def find(self, A, B):
		adotb = 0
		for i in range(3):
			adotb = adotb + A[i] * B[i]
		AXB = A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - A[2] * B[0]) + (A[0] * B[1] - A[1] * B[0])
		if adotb == 0:
			return 2
		elif AXB ** 2 == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		if not dot:
			return 2
		cross = (A[1] * B[2] - A[2] * B[1]) ** 2 + (A[0] * B[2] - A[2] * B[0]) ** 2 + (A[0] * B[1] - A[1] * B[0]) ** 2
		if not cross:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		adotb = 0
		for i in range(len(A)):
			adotb = adotb + A[i] * B[i]
		axb = A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - B[0] * A[2]) + (A[0] * B[1] - A[1] * B[0])
		axb = axb * axb
		if adotb == 0:
			return 2
		elif axb == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		cross = 0
		for i in range(3):
			cross += A[i] * B[(i + 1) % 3] - A[(i + 1) % 3] * B[i]
		if cross == 0:
			return 1
		elif dot == 0:
			return 2
		else:
			return 0


class Solution:

	def find(self, A, B):
		a1 = A[0]
		a2 = A[1]
		a3 = A[2]
		b1 = B[0]
		b2 = B[1]
		b3 = B[2]
		abc = a1 * b1 + a2 * b2 + a3 * b3
		a_b = a2 * b3 - a3 * b2 - (a1 * b3 - b1 * a3) + (a1 * b2 - a2 * b1)
		if abc == 0:
			return 2
		elif a_b == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		a1 = A[0]
		a2 = A[1]
		a3 = A[2]
		b1 = B[0]
		b2 = B[1]
		b3 = B[2]
		d = a1 * b1 + a2 * b2 + a3 * b3
		x1 = a2 * b3 - a3 * b2
		x2 = a1 * b3 - b1 * a3
		x3 = a1 * b2 - a2 * b1
		c = pow(x1, 2) + pow(x2, 2) + pow(x3, 2)
		if d == 0:
			return 2
		elif c == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		m = max(len(A), len(B))
		(a1, a2, a3) = (A[0], A[1], A[2])
		(b1, b2, b3) = (B[0], B[1], B[2])
		if a1 * b1 + a2 * b2 + a3 * b3 == 0:
			return 2
		if (a2 * b3 - a3 * b2) ** 2 + (a1 * b3 - b1 * a3) ** 2 + (a1 * b2 - a2 * b1) ** 2 == 0:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		DotProduct = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		CrossProduct = (A[1] * B[2] - A[2] * B[1]) * (A[1] * B[2] - A[2] * B[1]) - (A[0] * B[2] - A[2] * B[0]) * (A[0] * B[2] - A[2] * B[0]) + (A[0] * B[1] - A[1] * B[0]) * (A[0] * B[1] - A[1] * B[0])
		if CrossProduct == 0:
			return 1
		elif DotProduct == 0:
			return 2
		return 0


import math

class Solution:

	def find(self, A, B):
		perpen = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		parallel = int(math.pow(A[1] * B[2] - A[2] * B[1], 2) + math.pow(A[0] * B[2] - A[2] * B[0], 2) + math.pow(A[0] * B[1] - A[1] * B[0], 2))
		if parallel == 0:
			return '1'
		elif perpen == 0:
			return '2'
		else:
			return '0'


class Solution:

	def find(self, A, B):
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		cross = pow(A[0] * B[1] - A[1] * B[0] + (A[1] * B[2] - A[2] * B[1]) + (A[2] * B[0] - A[0] * B[2]), 2)
		if dot == 0:
			return 2
		elif cross == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, a, b):
		Sum = 0
		for i in range(len(A)):
			Sum += a[i] * b[i]
		if Sum == 0:
			return 2
		else:
			if (a[1] * b[2] - a[2] * b[1]) ** 2 + (a[0] * b[2] - b[0] * a[2]) ** 2 + (a[0] * b[1] - a[1] * b[0]) ** 2 == 0:
				return 1
			return 0


import math

class Solution:

	def find(self, A, B):
		A_B = A[1] * B[1] + A[2] * B[2] + A[0] * B[0]
		AxB = pow(A[1] * B[2] - A[2] * B[1], 2) + pow(A[0] * B[2] - A[2] * B[0], 2) + pow(A[0] * B[1] - A[1] * B[0], 2)
		if A_B == 0:
			return 2
		elif AxB == 0:
			return 1
		else:
			return 0


def dot(A, B):
	return sum((a * b for (a, b) in zip(A, B)))

def x(A, B):
	return [A[1] * B[2] - A[2] * B[1], A[0] * B[2] - B[0] * A[2], A[0] * B[1] - A[1] * B[0]]

def sq(A):
	return sum((a * a for a in A))

class Solution:

	def find(self, A, B):
		if dot(A, B) == 0:
			return 2
		if sq(x(A, B)) == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, a, b):
		perpendicular = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
		parallel_1 = a[1] * b[2] - a[2] * b[1] - (a[0] * b[2] - b[0] * a[2]) + (a[0] * b[1] - a[1] * b[0])
		parallel_2 = parallel_1 * parallel_1
		if perpendicular == 0:
			return 2
		elif parallel_2 == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, A, B):
		cross_p = A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - B[0] * A[2]) + (A[0] * B[1] - A[1] * B[0])
		mod = A[0] ** 2 + A[1] ** 2 + A[2] ** 2
		dot = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		if abs(cross_p ** 2) == 0:
			return 1
		elif dot == 0:
			return 2
		else:
			return 0


class Solution:

	def find(self, A, B):
		s = 0
		for i in range(3):
			s = s + A[i] * B[i]
		t = (A[1] * B[2] - A[2] * B[1]) ** 2 + (A[0] * B[2] - B[0] * A[2]) ** 2 + (A[0] * B[1] - A[1] * B[0]) ** 2
		if s == 0:
			return 2
		if t == 0:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		perpendicular = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		if perpendicular == 0:
			return 2
		parallel = A[1] * B[2] - A[2] * B[1] - (A[0] * B[2] - B[0] * A[2]) + (A[0] * B[1] - A[1] * B[0]) ** 2
		if parallel == 0:
			return 1
		return 0


class Solution:

	def find(self, A, B):
		AB = 0
		AxB = [0] * 3
		for i in range(len(A)):
			AB += A[i] * B[i]
			AxB[i] = A[i] * B[i + 1] - A[i + 1] * B[i] if i + 1 != len(A) else A[i] * B[0] - A[0] * B[i]
		if AB == 0:
			return 2
		elif sum(AxB) == 0:
			return 1
		else:
			return 0


class Solution:

	def find(self, a, b):
		if a[0] * b[0] + a[1] * b[1] + a[2] * b[2] == 0:
			return 2
		else:
			c1 = a[1] * b[2] - a[2] * b[1]
			c2 = -(a[0] * b[2] - b[0] * a[2])
			c3 = a[0] * b[1] - a[1] * b[0]
			if c1 ** 2 + c2 ** 2 + c3 ** 2 == 0:
				return 1
		return 0


class Solution:

	def find(self, A, B):
		if A[0] * B[0] + A[1] * B[1] + A[2] * B[2] == 0:
			return 2
		if A[1] * B[2] - A[2] * B[1] == 0 and A[0] * B[2] - A[2] * B[0] == 0 and (A[0] * B[1] - A[1] * B[0] == 0):
			return 1
		return 0


class Solution:

	def find(self, A, B):
		dot_product = 0
		cross_product = 0
		for i in range(3):
			dot_product = dot_product + A[i] * B[i]
		if dot_product == 0:
			return 2
		try:
			if A[0] / B[0] == A[1] / B[1] == A[2] / B[2]:
				return 1
			else:
				return 0
		except ZeroDivisionError:
			return 0


class Solution:

	def find(self, A, B):
		(a, b, c) = A
		(x, y, z) = B
		if a * x + b * y + c * z == 0:
			return 2
		elif b * z - c * y - (a * z - x * c) + (a * y - b * x) == 0:
			return 1
		else:
			return 0


import math

class Solution:

	def find(self, A, B):
		for itr in range(3):
			if A[itr] == 0:
				A[itr] = -99999
		if A[0] * B[0] + A[1] * B[1] + A[2] * B[2] == 0:
			return 2
		elif B[0] / A[0] == B[1] / A[1] and B[1] / A[1] == B[2] / A[2]:
			return 1
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, A, B):
		a1 = A[0]
		a2 = A[1]
		a3 = A[2]
		b1 = B[0]
		b2 = B[1]
		b3 = B[2]
		multi = a1 * b1 + a2 * b2 + a3 * b3
		CrossProduct = (A[1] * B[2] - A[2] * B[1]) * (A[1] * B[2] - A[2] * B[1]) - (A[0] * B[2] - A[2] * B[0]) * (A[0] * B[2] - A[2] * B[0]) + (A[0] * B[1] - A[1] * B[0]) * (A[0] * B[1] - A[1] * B[0])
		if CrossProduct == 0:
			return 1
		elif multi == 0:
			return 2
		return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, a, b):
		x = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
		y = (a[1] * b[2] - a[2] * b[1] - (a[0] * b[2] - b[0] * a[2]) + (a[0] * b[1] - a[1] * b[0])) ** 2
		if x == 0:
			return 2
		if y == 0:
			return 1
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, A, B):
		ab = A[0] * B[0] + A[1] * B[1] + A[2] * B[2] == 0
		axb = A[1] * B[2] - A[2] * B[1] == A[0] * B[2] - B[0] * A[2] == A[0] * B[2] - A[2] * B[0] == 0
		if ab == True:
			return 2
		elif axb == True:
			return 1
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, A, B):
		dproduct = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		a1 = A[1] * B[2] - A[2] * B[1]
		a2 = -(A[0] * B[2] - B[0] * A[2])
		a3 = A[0] * B[1] - A[1] * B[0]
		moda = a1 * a1 + a2 * a2 + a3 * a3
		if dproduct == 0:
			return 2
		elif moda == 0:
			return 1
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, A, B):

		def dot(a, b):
			dp = 0
			for i in range(3):
				dp += A[i] * B[i]
			return dp

		def cross(a, b):
			ans = [a[1] * b[2] - a[2] * b[1], -1 * (a[0] * b[2] - b[0] * a[2]), a[0] * b[1] - a[1] * b[0]]
			return ans

		def det(a):
			return (a[0] ** 2 + a[1] ** 2 + a[2] ** 2) ** (1 / 2)
		if dot(A, B) == 0:
			return 2
		elif det(cross(A, B)) ** 2 == 0:
			return 1
		else:
			return 0
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		ans = ob.find(A, B)
		print(ans)


class Solution:

	def find(self, A, B):
		p = A[0] * B[0] + A[1] * B[1] + A[2] * B[2]
		if p == 0:
			return 2
		d = A[1] * B[2] - A[2] * B[1]
		e = A[0] * B[2] - B[0] * A[2]
		f = A[0] * B[1] - A[1] * B[0]
		if d == 0 and e == 0 and (f == 0):
			return 1
		return 0