Given the co-effecients of X,Y and Z in a system of simultaneous equations. Find the values of X,Y and Z.
 a1X + b1Y + c1Z = d1
 a2X + b2Y + c2Z = d2
 a3X + b3Y + c3Z = d3
Example 1:
Input: 
Arr = {{5, 4, 2, 0},
       {1, 4, 2, 0},
       {4, 2, 9, 0}}
Output: {0, 0, 0} 
Explanation: After calculating with these
given coefficient the value of X, Y, Z is
0, 0, 0.
Example 2:
Input: 
Arr = {{4.2, 6, 7, 10},
       {1, 2, 3, 12},
       {3, 2, 2, 20}}
Output: {3, 4, -1}
Explanation: After calculating with these
given coefficient the value of X, Y, Z is
3, 4, -1. 
Your Task:  
You dont need to read input or print anything. Complete the function myCalculator() which takes Arr as input parameter and returns 0 in case the system is inconsistent and 1 in case the system is consistent and has infinitely many solutions. In case the system is consistent and has a unique solution, return 3 space separated integers denoting the floor values of X, Y and Z respectively.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
-100 <= Arr[i][j] <=100

Source: geeksforgeeks | Difficulty: MEDIUM_HARD
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:

	def myCalculator(self, Arr):

		# code here



Solutions:
import math

class Solution:

	def delta(self, Arr, i, j, k):
		ans = Arr[0][i] * Arr[1][j] * Arr[2][k]
		ans += Arr[0][j] * Arr[1][k] * Arr[2][i]
		ans += Arr[0][k] * Arr[1][i] * Arr[2][j]
		ans -= Arr[0][i] * Arr[1][k] * Arr[2][j]
		ans -= Arr[0][j] * Arr[1][i] * Arr[2][k]
		ans -= Arr[0][k] * Arr[1][j] * Arr[2][i]
		return ans

	def myCalculator(self, Arr):
		d = self.delta(Arr, 0, 1, 2)
		p = self.delta(Arr, 3, 1, 2)
		q = self.delta(Arr, 0, 3, 2)
		r = self.delta(Arr, 0, 1, 3)
		if d == 0:
			if p == 0 and r == 0 and (q == 0):
				return [1]
			else:
				return [0]
		return [int(p // d), int(q // d), int(r // d)]


class Solution:

	def myCalculator(self, arr):

		def matrixMul(mat, flag, i, arr):
			if flag:
				for j in range(3):
					(mat[j][i], arr[j][-1]) = (arr[j][-1], mat[j][i])
			res = 0
			res += mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1])
			res -= mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0])
			res += mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0])
			if flag:
				for j in range(3):
					(mat[j][i], arr[j][-1]) = (arr[j][-1], mat[j][i])
			return res
		a = []
		for i in range(3):
			a.append(arr[i][:-1])
		p = matrixMul(a, False, -1, arr)
		q = matrixMul(a, True, 0, arr)
		r = matrixMul(a, True, 1, arr)
		s = matrixMul(a, True, 2, arr)
		if p == 0 and (q != 0 or r != 0 or s != 0):
			return 0
		if p == 0 and r == 0 and (q == 0) and (s == 0):
			return 1
		return [int(q // p), int(r // p), int(s // p)]


class Solution:

	def myCalculator(self, Arr):
		[[a1, b1, c1, d1], [a2, b2, c2, d2], [a3, b3, c3, d3]] = Arr
		D = a1 * (b2 * c3 - b3 * c2) + a2 * (b3 * c1 - b1 * c3) + a3 * (b1 * c2 - b2 * c1)
		if D != 0:
			x = d1 * (b2 * c3 - b3 * c2) + d2 * (c1 * b3 - c3 * b1) + d3 * (b1 * c2 - b2 * c1)
			y = d1 * (c2 * a3 - c3 * a2) + d2 * (a1 * c3 - a3 * c1) + d3 * (c1 * a2 - c2 * a1)
			z = d1 * (a2 * b3 - a3 * b2) + d2 * (b1 * a3 - a1 * b3) + d3 * (a1 * b2 - a2 * b1)
			return [int(x // D), int(y // D), int(z // D)]
		else:
			return [0]


import numpy

class Solution:

	def myCalculator(self, arr):
		a = numpy.array([arr[0][:3], arr[1][:3], arr[2][:3]])
		b = numpy.array([arr[0][3], arr[1][3], arr[2][3]])
		if numpy.linalg.det(a) == 0:
			return 0
		else:
			x = numpy.dot(numpy.linalg.inv(a), b)
			return [*map(int, numpy.floor(x))]


import numpy

class Solution:

	def myCalculator(self, arr):
		m1 = arr[0][:3]
		m2 = arr[1][:3]
		m3 = arr[2][:3]
		a = numpy.array([m1, m2, m3])
		b = numpy.array([arr[0][3], arr[1][3], arr[2][3]])
		if numpy.linalg.det(a) == 0:
			return 0
		x = numpy.dot(numpy.linalg.inv(a), b)
		x = list(map(int, numpy.floor(x)))
		return x


import numpy as np

class Solution:

	def myCalculator(self, Arr):
		(m, n, l) = (Arr[0], Arr[1], Arr[2])
		matrix = np.matrix([[n[0], n[1], n[2]], [m[0], m[1], m[2]], [l[0], l[1], l[2]]])
		delta = np.linalg.det(matrix)
		if delta == 0:
			return [0]
		else:
			y = np.linalg.inv(matrix)
			b = np.array([n[3], m[3], l[3]])
			x = np.dot(y, b)
			x = np.floor(x)
			x = np.array(x)
			return (int(x[0][0]), int(x[0][1]), int(x[0][2]))


def cum(a):
	p = a[0][0] * (a[1][1] * a[2][2] - a[2][1] * a[1][2])
	q = a[1][0] * (a[0][1] * a[2][2] - a[0][2] * a[2][1])
	r = a[2][0] * (a[0][1] * a[1][2] - a[0][2] * a[1][1])
	return p - q + r

def var(d, p):
	if p / d < 0:
		return int(p / d) - 1
	else:
		return int(p / d)

class Solution:

	def myCalculator(self, arr):
		a = [arr[0][0:3], arr[1][0:3], arr[2][0:3]]
		v = [arr[0][3], arr[1][3], arr[2][3]]
		ax = [[v[0], a[0][1], a[0][2]], [v[1], a[1][1], a[1][2]], [v[2], a[2][1], a[2][2]]]
		bx = [[a[0][0], v[0], a[0][2]], [a[1][0], v[1], a[1][2]], [a[2][0], v[2], a[2][2]]]
		cx = [[a[0][0], a[0][1], v[0]], [a[1][0], a[1][1], v[1]], [a[2][0], a[2][1], v[2]]]
		d = cum(a)
		dx = cum(ax)
		dy = cum(bx)
		dz = cum(cx)
		return [var(d, dx), var(d, dy), var(d, dz)]