codeparrot/xlcost-text-to-code huggingface dataset:
Check whether two straight lines are parallel or not | Function to check if two lines are parallel or not ; If slopes are equal ; Driver Code ; Function Call
def parallel ( a1 , b1 , c1 , a2 , b2 , c2 ) : NEW_LINE INDENT if ( ( - ( a1 / b1 ) ) == ( - ( a2 / b2 ) ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a1 = - 2 ; b1 = 4 ; c1 = 5 ; NEW_LINE a2 = - 6 ; b2 = 12 ; c2 = 6 ; NEW_LINE parallel ( a1 , b1 , c1 , a2 , b2 , c2 ) ; NEW_LINE DEDENT
Calculate area and height of an isosceles triangle whose sides are radii of a circle | Python3 program for the above approach ; Function to convert given angle from degree to radian ; Function to calculate height and area of the triangle OAB ; Stores the angle OAB and OBA ; Stores the angle in radians ; Stores the height ; Print height of the triangle ; Stores the base of triangle OAB ; Stores the area of the triangle ; Print the area of triangle OAB ; Driver Code
from math import sin , cos NEW_LINE def Convert ( degree ) : NEW_LINE INDENT pi = 3.14159265359 NEW_LINE return ( degree * ( pi / 180 ) ) NEW_LINE DEDENT def areaAndHeightOfTraingle ( radius , a ) : NEW_LINE INDENT if ( a >= 180 or a == 0 ) : NEW_LINE INDENT print ( " Not ▁ possible " ) NEW_LINE return NEW_LINE DEDENT base_angle = ( 180 - a ) / 2 NEW_LINE radians = Convert ( base_angle ) NEW_LINE height = sin ( radians ) * radius NEW_LINE print ( " Height ▁ of ▁ triangle ▁ " , round ( height , 1 ) ) NEW_LINE base = cos ( radians ) * radius NEW_LINE area = base * height NEW_LINE print ( " Area ▁ of ▁ triangle ▁ " , round ( area , 4 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT R , angle = 5 , 120 NEW_LINE areaAndHeightOfTraingle ( R , angle ) NEW_LINE DEDENT
Radius of a circle having area equal to the sum of area of the circles having given radii | Function to calculate radius of the circle having area equal to sum of the area of two circles with given radii ; Area of first circle ; Area of second circle ; Area of third circle ; Radius of third circle ; Driver code ; Given radius ; Prints the radius of the required circle
def findRadius ( r1 , r2 ) : NEW_LINE INDENT a1 , a2 , a3 , r3 = 0 , 0 , 0 , 0 ; NEW_LINE a1 = 3.14 * r1 * r1 ; NEW_LINE a2 = 3.14 * r2 * r2 ; NEW_LINE a3 = a1 + a2 ; NEW_LINE r3 = ( ( a3 / 3.14 ) ** ( 1 / 2 ) ) ; NEW_LINE return r3 ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT r1 = 8 ; r2 = 6 ; NEW_LINE print ( int ( findRadius ( r1 , r2 ) ) ) ; NEW_LINE DEDENT
Minimum number of Cuboids required to form a Cube | Function to calculate and return LCM of a , b , and c ; Find GCD of a and b ; Find LCM of a and b ; LCM ( a , b , c ) = LCM ( LCM ( a , b ) , c ) ; Finding LCM of a , b , c ; return LCM ( a , b , c ) ; Function to find the minimum number of cuboids required to make the volume of a valid cube ; Find the LCM of L , B , H ; Volume of the cube ; Volume of the cuboid ; Minimum number cuboids required to form a cube ; Driver Code ; Given dimensions of cuboid ; Function Call
def find_lcm ( a , b , c ) : NEW_LINE INDENT g = __gcd ( a , b ) ; NEW_LINE LCM1 = ( a * b ) // g ; NEW_LINE g = __gcd ( LCM1 , c ) ; NEW_LINE LCM = ( LCM1 * c ) // g ; NEW_LINE return LCM ; NEW_LINE DEDENT def minimumCuboids ( L , B , H ) : NEW_LINE INDENT lcm = find_lcm ( L , B , H ) ; NEW_LINE volume_cube = lcm * lcm * lcm ; NEW_LINE volume_cuboid = L * B * H ; NEW_LINE print ( ( volume_cube // volume_cuboid ) ) ; NEW_LINE DEDENT def __gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT else : NEW_LINE INDENT return __gcd ( b , a % b ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 1 ; B = 1 ; H = 2 ; NEW_LINE minimumCuboids ( L , B , H ) ; NEW_LINE DEDENT
Check if given polygon is a convex polygon or not | Utility function to find cross product of two vectors ; Stores coefficient of X direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of X direction of vector A [ 2 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 2 ] A [ 0 ] ; Return cross product ; Function to check if the polygon is convex polygon or not ; Stores count of edges in polygon ; Stores direction of cross product of previous traversed edges ; Stores direction of cross product of current traversed edges ; Traverse the array ; Stores three adjacent edges of the polygon ; Update curr ; If curr is not equal to 0 ; If direction of cross product of all adjacent edges are not same ; Update curr ; Driver code
def CrossProduct ( A ) : NEW_LINE INDENT X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] ) NEW_LINE Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] ) NEW_LINE X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] ) NEW_LINE Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] ) NEW_LINE return ( X1 * Y2 - Y1 * X2 ) NEW_LINE DEDENT def isConvex ( points ) : NEW_LINE INDENT N = len ( points ) NEW_LINE prev = 0 NEW_LINE curr = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT temp = [ points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] ] NEW_LINE curr = CrossProduct ( temp ) NEW_LINE if ( curr != 0 ) : NEW_LINE INDENT if ( curr * prev < 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT prev = curr NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE if ( isConvex ( points ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT
Program to find all possible triangles having same Area and Perimeter | Function to print sides of all the triangles having same perimeter & area ; Stores unique sides of triangles ; i + j + k values cannot exceed 256 ; Find the value of 2 * s ; Find the value of 2 * ( s - a ) ; Find the value of 2 * ( s - b ) ; Find the value of 2 * ( s - c ) ; If triplets have same area and perimeter ; Store sides of triangle ; Sort the triplets ; Inserting in set to avoid duplicate sides ; Print sides of all desired triangles ; Driver Code ; Function call
def samePerimeterAndArea ( ) : NEW_LINE INDENT se = [ ] NEW_LINE for i in range ( 1 , 256 , 1 ) : NEW_LINE INDENT for j in range ( 1 , 256 , 1 ) : NEW_LINE INDENT for k in range ( 1 , 256 , 1 ) : NEW_LINE INDENT peri = i + j + k NEW_LINE mul1 = - i + j + k NEW_LINE if ( k > 100 ) : NEW_LINE break NEW_LINE if ( j > 100 ) : NEW_LINE break NEW_LINE if ( i > 100 ) : NEW_LINE break NEW_LINE mul2 = i - j + k NEW_LINE mul3 = i + j - k NEW_LINE if ( 16 * peri == mul1 * mul2 * mul3 ) : NEW_LINE INDENT v = [ i , j , k ] NEW_LINE v . sort ( reverse = False ) NEW_LINE se . append ( v ) NEW_LINE se . sort ( reverse = False ) NEW_LINE DEDENT DEDENT DEDENT DEDENT temp = [ ] NEW_LINE temp . append ( se [ 0 ] ) NEW_LINE temp . append ( se [ 6 ] ) NEW_LINE temp . append ( se [ 12 ] ) NEW_LINE temp . append ( se [ 18 ] ) NEW_LINE temp . append ( se [ 24 ] ) NEW_LINE for it in temp : NEW_LINE INDENT print ( it [ 0 ] , it [ 1 ] , it [ 2 ] ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT samePerimeterAndArea ( ) NEW_LINE DEDENT
Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points | Function to get the count of ractangles ; Store distinct horizontal lines ; Store distinct Vertical lines ; Insert horizontal line passing through 0 ; Insert vertical line passing through 0. ; Insert horizontal line passing through rectangle [ 3 ] [ 0 ] ; Insert vertical line passing through rectangle [ 3 ] [ 1 ] ; Insert all horizontal and vertical lines passing through the given array ; Insert all horizontal lines ; Insert all vertical lines ; Driver Code
def cntRect ( points , N , rectangle ) : NEW_LINE INDENT cntHor = set ( [ ] ) NEW_LINE cntVer = set ( [ ] ) NEW_LINE cntHor . add ( 0 ) NEW_LINE cntVer . add ( 0 ) NEW_LINE cntHor . add ( rectangle [ 3 ] [ 0 ] ) NEW_LINE cntVer . add ( rectangle [ 3 ] [ 1 ] ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT cntHor . add ( points [ i ] [ 0 ] ) NEW_LINE cntVer . add ( points [ i ] [ 1 ] ) NEW_LINE DEDENT return ( ( len ( cntHor ) - 1 ) * ( len ( cntVer ) - 1 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT rectangle = [ [ 0 , 0 ] , [ 0 , 5 ] , [ 5 , 0 ] , [ 5 , 5 ] ] NEW_LINE points = [ [ 1 , 2 ] , [ 3 , 4 ] ] NEW_LINE N = len ( points ) NEW_LINE print ( cntRect ( points , N , rectangle ) ) NEW_LINE DEDENT
Count squares possible from M and N straight lines parallel to X and Y axis respectively | Function to count all the possible squares with given lines parallel to both the X and Y axis ; Stores the count of all possible distances in X [ ] & Y [ ] respectively ; Find distance between all pairs in the array X [ ] ; Add the count to m1 ; Find distance between all pairs in the array Y [ ] ; Add the count to m2 ; Find sum of m1 [ i ] * m2 [ i ] for same distance ; Find current count in m2 ; Add to the total count ; Return the final count ; Driver Code ; Given lines ; Function call
def numberOfSquares ( X , Y , N , M ) : NEW_LINE INDENT m1 = { } NEW_LINE m2 = { } NEW_LINE ans = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT dist = abs ( X [ i ] - X [ j ] ) NEW_LINE if dist in m1 : NEW_LINE INDENT m1 [ dist ] = m1 [ dist ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT m1 [ dist ] = 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( 0 , M ) : NEW_LINE INDENT for j in range ( i + 1 , M ) : NEW_LINE INDENT dist = abs ( Y [ i ] - Y [ j ] ) NEW_LINE if dist in m2 : NEW_LINE INDENT m2 [ dist ] = m2 [ dist ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT m2 [ dist ] = 1 NEW_LINE DEDENT DEDENT DEDENT for key in m1 : NEW_LINE INDENT if key in m2 : NEW_LINE INDENT ans = ans + ( m1 [ key ] * m2 [ key ] ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = [ 1 , 3 , 7 ] NEW_LINE Y = [ 2 , 4 , 6 , 1 ] NEW_LINE N = len ( X ) NEW_LINE M = len ( Y ) NEW_LINE print ( numberOfSquares ( X , Y , N , M ) ) NEW_LINE DEDENT
Program to calculate area of a parallelogram | Python3 program for the above approach ; Function to return the area of parallelogram using sides and angle at the intersection of diagonal ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using sides and angle at the intersection of sides ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using diagonals and angle at the intersection of diagonals ; Calculate area of parallelogram ; Return the answer ; Given diagonal and angle ; Function Call ; Print the area
import math NEW_LINE def Area_Parallelogram1 ( a , b , theta ) : NEW_LINE INDENT area = ( abs ( math . tan ( math . radians ( theta ) ) ) / 2 ) * abs ( a ** 2 - b ** 2 ) NEW_LINE return area NEW_LINE DEDENT def Area_Parallelogram2 ( a , b , gamma ) : NEW_LINE INDENT area = ( abs ( math . sin ( math . radians ( gamma ) ) ) ) * abs ( a * b ) NEW_LINE return area NEW_LINE DEDENT def Area_Parallelogram3 ( d1 , d2 , theta ) : NEW_LINE INDENT area = ( abs ( math . sin ( math . radians ( theta ) ) ) / 2 ) * abs ( d1 * d2 ) NEW_LINE return area NEW_LINE DEDENT d1 = 3 NEW_LINE d2 = 5 NEW_LINE theta = 90 NEW_LINE area = Area_Parallelogram3 ( d1 , d2 , theta ) NEW_LINE print ( round ( area , 2 ) ) NEW_LINE
Count squares of size K inscribed in a square of size N | Function to calculate the number of squares of size K in a square of size N ; Stores the number of squares ; Driver Code ; Size of the bigger square ; Size of smaller square
def No_of_squares ( N , K ) : NEW_LINE INDENT no_of_squares = 0 ; NEW_LINE no_of_squares = ( N - K + 1 ) * ( N - K + 1 ) ; NEW_LINE return no_of_squares ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 5 ; NEW_LINE K = 3 ; NEW_LINE print ( No_of_squares ( N , K ) ) ; NEW_LINE DEDENT
Count cubes of size K inscribed in a cube of size N | Function to find the number of the cubes of the size K ; Stores the number of cubes ; Stores the number of cubes of size k ; Size of the bigger cube ; Size of the smaller cube
def No_of_cubes ( N , K ) : NEW_LINE INDENT No = 0 NEW_LINE No = ( N - K + 1 ) NEW_LINE No = pow ( No , 3 ) NEW_LINE return No NEW_LINE DEDENT N = 5 NEW_LINE K = 2 NEW_LINE print ( No_of_cubes ( N , K ) ) NEW_LINE
Count of smaller rectangles that can be placed inside a bigger rectangle | Function to count smaller rectangles within the larger rectangle ; If the dimension of the smaller rectangle is greater than the bigger one ; Return the number of smaller rectangles possible ; Driver code ; Dimension of bigger rectangle ; Dimension of smaller rectangle ; Function call
def No_of_rectangles ( L , B , l , b ) : NEW_LINE INDENT if ( l > L ) or ( b > B ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( L - l + 1 ) * ( B - b + 1 ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 5 NEW_LINE B = 3 NEW_LINE l = 4 NEW_LINE b = 1 NEW_LINE print ( No_of_rectangles ( L , B , l , b ) ) NEW_LINE DEDENT
Program To Check whether a Triangle is Equilateral , Isosceles or Scalene | Function to check if the triangle is equilateral or isosceles or scalene ; _Check for equilateral triangle ; Check for isosceles triangle ; Otherwise scalene triangle ; Given sides of triangle ; Function Call
def checkTriangle ( x , y , z ) : NEW_LINE INDENT if x == y == z : NEW_LINE INDENT print ( " Equilateral ▁ Triangle " ) NEW_LINE DEDENT elif x == y or y == z or z == x : NEW_LINE INDENT print ( " Isosceles ▁ Triangle " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Scalene ▁ Triangle " ) NEW_LINE DEDENT DEDENT x = 8 NEW_LINE y = 7 NEW_LINE z = 9 NEW_LINE checkTriangle ( x , y , z ) NEW_LINE
Find the remaining vertices of a square from two given vertices | Function to find the remaining vertices of a square ; Check if the x - coordinates are equal ; Check if the y - coordinates are equal ; If the the given coordinates forms a diagonal of the square ; Otherwise ; Square does not exist ; Driver Code ; Given two vertices
def findVertices ( x1 , y1 , x2 , y2 ) : NEW_LINE INDENT if ( x1 == x2 ) : NEW_LINE INDENT print ( ( x1 + y2 - y1 ) , " , " , y1 ) NEW_LINE print ( ( x2 + y2 - y1 ) , " , " , y2 ) NEW_LINE DEDENT elif ( y1 == y2 ) : NEW_LINE INDENT print ( x1 , " , " , ( y1 + x2 - x1 ) ) NEW_LINE print ( x2 , " , " , ( y2 + x2 - x1 ) ) NEW_LINE DEDENT elif ( abs ( x2 - x1 ) == abs ( y2 - y1 ) ) : NEW_LINE INDENT print ( x1 , " , " , y2 ) NEW_LINE print ( x2 , " , " , y1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x1 = 1 NEW_LINE y1 = 2 NEW_LINE x2 = 3 NEW_LINE y2 = 4 NEW_LINE findVertices ( x1 , y1 , x2 , y2 ) NEW_LINE DEDENT
Find the area of rhombus from given Angle and Side length | Python3 Program to calculate area of rhombus from given angle and side length ; Function to return the area of rhombus using one angle and side . ; Driver Code ; Function Call ; Print the final answer
import math NEW_LINE def Area_of_Rhombus ( a , theta ) : NEW_LINE INDENT area = ( a ** 2 ) * math . sin ( math . radians ( theta ) ) NEW_LINE return area NEW_LINE DEDENT a = 4 NEW_LINE theta = 60 NEW_LINE ans = Area_of_Rhombus ( a , theta ) NEW_LINE print ( round ( ans , 2 ) ) NEW_LINE
Count of Equilateral Triangles of unit length possible from a given Hexagon | Function to calculate the the number of Triangles possible ; Regular Hexagon ; Irregular Hexagon
def calculateTriangles ( sides ) : NEW_LINE INDENT count = pow ( sides [ 0 ] + sides [ 1 ] + sides [ 2 ] , 2 ) NEW_LINE count -= pow ( sides [ 0 ] , 2 ) NEW_LINE count -= pow ( sides [ 2 ] , 2 ) NEW_LINE count -= pow ( sides [ 4 ] , 2 ) NEW_LINE return int ( count ) NEW_LINE DEDENT sides = [ 1 , 1 , 1 , 1 , 1 , 1 ] NEW_LINE print ( calculateTriangles ( sides ) ) NEW_LINE sides = [ 2 , 2 , 1 , 3 , 1 , 2 ] NEW_LINE print ( calculateTriangles ( sides ) ) NEW_LINE
Length of diagonal of a parallelogram using adjacent sides and angle between them | Python3 Program to find length Of diagonal of a parallelogram Using sides and angle between them . ; Function to return the length Of diagonal of a parallelogram using sides and angle between them . ; Given Sides ; Given Angle ; Function Call ; Print the final answer
import math NEW_LINE def Length_Diagonal ( a , b , theta ) : NEW_LINE INDENT diagonal = math . sqrt ( ( ( a ** 2 ) + ( b ** 2 ) ) - 2 * a * b * math . cos ( math . radians ( theta ) ) ) NEW_LINE return diagonal NEW_LINE DEDENT a = 3 NEW_LINE b = 5 NEW_LINE theta = 45 NEW_LINE ans = Length_Diagonal ( a , b , theta ) NEW_LINE print ( round ( ans , 2 ) ) NEW_LINE
Maximum number of tiles required to cover the floor of given size using 2 x1 size tiles | Function to find the maximum number of tiles required to cover the floor of size m x n using 2 x 1 size tiles ; Prthe answer ; Driver code ; Given M and N ; Function call
def maximumTiles ( n , m ) : NEW_LINE INDENT print ( int ( ( m * n ) / 2 ) ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M = 3 ; NEW_LINE N = 4 ; NEW_LINE maximumTiles ( N , M ) ; NEW_LINE DEDENT
Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal | Python Program to implement the above approach ; Function to calculate the length of the diagonal of a parallelogram using two sides and other diagonal ; Driver Code ; Function Call ; Print the final answer
import math NEW_LINE def Length_Diagonal ( a , b , d ) : NEW_LINE INDENT diagonal = math . sqrt ( 2 * ( ( a ** 2 ) + ( b ** 2 ) ) - ( d ** 2 ) ) NEW_LINE return diagonal NEW_LINE DEDENT A = 10 NEW_LINE B = 30 NEW_LINE D = 20 NEW_LINE ans = Length_Diagonal ( A , B , D ) NEW_LINE print ( round ( ans , 2 ) ) NEW_LINE
Length of Diagonals of a Cyclic Quadrilateral using the length of Sides . | Python3 program to implement the above approach ; Function to calculate the length of diagonals of a cyclic quadrilateral ; Driver Code ; Function Call ; Print the final answer
import math NEW_LINE def Diagonals ( a , b , c , d ) : NEW_LINE INDENT p = math . sqrt ( ( ( a * c ) + ( b * d ) ) * ( ( a * d ) + ( b * c ) ) / ( ( a * b ) + ( c * d ) ) ) NEW_LINE q = math . sqrt ( ( ( a * c ) + ( b * d ) ) * ( ( a * b ) + ( c * d ) ) / ( ( a * d ) + ( b * c ) ) ) NEW_LINE return [ p , q ] NEW_LINE DEDENT A = 10 NEW_LINE B = 15 NEW_LINE C = 20 NEW_LINE D = 25 NEW_LINE ans = Diagonals ( A , B , C , D ) NEW_LINE print ( round ( ans [ 0 ] , 2 ) , round ( ans [ 1 ] , 2 ) ) NEW_LINE
Minimum Sum of Euclidean Distances to all given Points | Python3 program to implement the above approach ; Function to calculate Euclidean distance ; Function to calculate the minimum sum of the euclidean distances to all points ; Calculate the centroid ; Calculate distance of all points ; Driver Code ; Initializing the points
from math import sqrt NEW_LINE def find ( x , y , p ) : NEW_LINE INDENT mind = 0 NEW_LINE for i in range ( len ( p ) ) : NEW_LINE INDENT a = p [ i ] [ 0 ] NEW_LINE b = p [ i ] [ 1 ] NEW_LINE mind += sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) ) NEW_LINE DEDENT return mind NEW_LINE DEDENT def getMinDistSum ( p ) : NEW_LINE INDENT x = 0 NEW_LINE y = 0 NEW_LINE for i in range ( len ( p ) ) : NEW_LINE INDENT x += p [ i ] [ 0 ] NEW_LINE y += p [ i ] [ 1 ] NEW_LINE DEDENT x = x // len ( p ) NEW_LINE y = y // len ( p ) NEW_LINE mind = find ( x , y , p ) NEW_LINE return mind NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT vec = [ [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] , [ 2 , 1 ] ] NEW_LINE d = getMinDistSum ( vec ) NEW_LINE print ( int ( d ) ) NEW_LINE DEDENT
Coplanarity of Two Lines in 3D Geometry | Function to generate determinant ; Return the sum ; Driver Code ; Position vector of first line ; Direction ratios of line to which first line is parallel ; Position vectors of second line ; Direction ratios of line to which second line is parallel ; Determinant to check coplanarity ; If determinant is zero ; Otherwise
def det ( d ) : NEW_LINE INDENT Sum = d [ 0 ] [ 0 ] * ( ( d [ 1 ] [ 1 ] * d [ 2 ] [ 2 ] ) - ( d [ 2 ] [ 1 ] * d [ 1 ] [ 2 ] ) ) NEW_LINE Sum -= d [ 0 ] [ 1 ] * ( ( d [ 1 ] [ 0 ] * d [ 2 ] [ 2 ] ) - ( d [ 1 ] [ 2 ] * d [ 2 ] [ 0 ] ) ) NEW_LINE Sum += d [ 0 ] [ 2 ] * ( ( d [ 0 ] [ 1 ] * d [ 1 ] [ 2 ] ) - ( d [ 0 ] [ 2 ] * d [ 1 ] [ 1 ] ) ) NEW_LINE return Sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x1 , y1 , z1 = - 3 , 1 , 5 NEW_LINE a1 , b1 , c1 = - 3 , 1 , 5 NEW_LINE x2 , y2 , z2 = - 1 , 2 , 5 NEW_LINE a2 , b2 , c2 = - 1 , 2 , 5 NEW_LINE det_list = [ [ x2 - x1 , y2 - y1 , z2 - z1 ] , [ a1 , b1 , c1 ] , [ a2 , b2 , c2 ] ] NEW_LINE if ( det ( det_list ) == 0 ) : NEW_LINE INDENT print ( " Lines ▁ are ▁ coplanar " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Lines ▁ are ▁ non ▁ coplanar " ) NEW_LINE DEDENT DEDENT
Distance between Incenter and Circumcenter of a triangle using Inradius and Circumradius | Python3 program for the above approach ; Function returns the required distance ; Length of Inradius ; Length of Circumradius
import math NEW_LINE def distance ( r , R ) : NEW_LINE INDENT d = math . sqrt ( ( R ** 2 ) - ( 2 * r * R ) ) NEW_LINE return d NEW_LINE DEDENT r = 2 NEW_LINE R = 5 NEW_LINE print ( round ( distance ( r , R ) , 2 ) ) NEW_LINE
Check if an N | Function to check if the polygon exists or not ; Initialize a variable to store the sum of angles ; Loop through the array and calculate the sum of angles ; Check the condition for an N - side polygon ; Driver Code ; Given array arr [ ] ; Function Call
def checkValidPolygon ( arr , N ) : NEW_LINE INDENT Sum = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT Sum += arr [ i ] NEW_LINE DEDENT if Sum == 180 * ( N - 2 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT N = 3 NEW_LINE arr = [ 60 , 60 , 60 ] NEW_LINE checkValidPolygon ( arr , N ) NEW_LINE
Find the angle of Rotational Symmetry of an N | Function to find required minimum angle of rotation ; Calculating the angle of rotation and type - casting the integer N to type ; Driver code
def minAnglRot ( N ) : NEW_LINE INDENT res = 360 // N NEW_LINE return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 ; NEW_LINE print ( " Angle ▁ of ▁ Rotational ▁ Symmetry : ▁ " , minAnglRot ( N ) ) NEW_LINE DEDENT
Area of a Triangle from the given lengths of medians | Python3 program to calculate area of a triangle from the given lengths of medians ; Function to return the area of triangle using medians ; Driver Code ; Function Call ; Print the final answer
import math NEW_LINE def Area_of_Triangle ( a , b , c ) : NEW_LINE INDENT s = ( a + b + c ) // 2 NEW_LINE x = s * ( s - a ) NEW_LINE x = x * ( s - b ) NEW_LINE x = x * ( s - c ) NEW_LINE area = ( 4 / 3 ) * math . sqrt ( x ) NEW_LINE return area NEW_LINE DEDENT a = 9 NEW_LINE b = 12 NEW_LINE c = 15 NEW_LINE ans = Area_of_Triangle ( a , b , c ) NEW_LINE print ( round ( ans , 2 ) ) NEW_LINE