codeparrot/xlcost-text-to-code huggingface dataset:
Circumradius of the rectangle | Python Program to find the radius of the circumcircle of the given rectangle ; Function to find the radius of the circumcircle ; the sides cannot be negative ; Radius of the circumcircle ; Return the radius ; Get the sides of the triangle ; Find the radius of the circumcircle
import math NEW_LINE def findRadiusOfcircumcircle ( l , b ) : NEW_LINE INDENT if ( l < 0 or b < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT radius = ( math . sqrt ( pow ( l , 2 ) + pow ( b , 2 ) ) / 2 ) ; NEW_LINE return radius ; NEW_LINE DEDENT l = 4 ; NEW_LINE b = 3 ; NEW_LINE print ( findRadiusOfcircumcircle ( l , b ) ) ; NEW_LINE
Area of the circumcircle of any triangles with sides given | Python3 Program to find the area the circumcircle of the given triangle ; Function to find the area of the circumcircle ; the sides cannot be negative ; semi - perimeter of the circle ; area of triangle ; area of the circle ; Get the sides of the triangle ; Find and print the area of the circumcircle
import math NEW_LINE def circlearea ( a , b , c ) : NEW_LINE INDENT if ( a < 0 or b < 0 or c < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT p = ( a + b + c ) / 2 ; NEW_LINE At = math . sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; NEW_LINE A = 3.14 * pow ( ( ( a * b * c ) / ( 4 * At ) ) , 2 ) ; NEW_LINE return A ; NEW_LINE DEDENT a = 4 ; NEW_LINE b = 5 ; NEW_LINE c = 3 ; NEW_LINE print ( float ( circlearea ( a , b , c ) ) ) ; NEW_LINE
Find the altitude and area of an isosceles triangle | Python 3 program to find the Altitude Area of an isosceles triangle ; function to find the altitude ; return altitude ; function to find the area ; return area ; Driver Code
import math NEW_LINE def altitude ( a , b ) : NEW_LINE INDENT return math . sqrt ( pow ( a , 2 ) - ( pow ( b , 2 ) / 4 ) ) NEW_LINE DEDENT def area ( b , h ) : NEW_LINE INDENT return ( 1 * b * h ) / 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 2 NEW_LINE b = 3 NEW_LINE h = altitude ( a , b ) NEW_LINE print ( " Altitude ▁ = ▁ " + str ( round ( h , 3 ) ) , end = " , ▁ " ) NEW_LINE print ( " Area ▁ = ▁ " + str ( round ( area ( b , h ) , 3 ) ) ) NEW_LINE DEDENT
Program to find the surface area of the square pyramid | function to find the surface area ; Driver Code ; surface area of the square pyramid
def surfaceArea ( b , s ) : NEW_LINE INDENT return 2 * b * s + pow ( b , 2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT b = 3 NEW_LINE s = 4 NEW_LINE print ( surfaceArea ( b , s ) ) NEW_LINE DEDENT
Area of largest triangle that can be inscribed within a rectangle | Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
def trianglearea ( l , b ) : NEW_LINE INDENT if ( l < 0 or b < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = ( l * b ) / 2 NEW_LINE return area NEW_LINE DEDENT l = 5 NEW_LINE b = 4 NEW_LINE print ( trianglearea ( l , b ) ) NEW_LINE
Check if any square ( with one colored cell ) can be divided into two equal parts | function to check if it 's possible to divide the square in two equal parts ; if the painted square is linked anyway to the center of the square then it 's  not possible ; else yes it 's possible ; Driver code ; initialize the size of the square ; initialize the dimension of the painted square
def halfsquare ( n , x , y ) : NEW_LINE INDENT half = n // 2 NEW_LINE if ( ( half == x or half == x - 1 ) and ( half == y or half == y - 1 ) ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 100 NEW_LINE x , y = 51 , 100 NEW_LINE halfsquare ( n , x , y ) NEW_LINE DEDENT
Check if it is possible to reach vector B by rotating vector A and adding vector C to it | function to check if vector B is possible from vector A ; if d = 0 , then you need to add nothing to vector A ; for all four quadrants ; initialize all three vector coordinates
def check ( a , b , p , q ) : NEW_LINE INDENT d = p * p + q * q ; NEW_LINE if ( d == 0 ) : NEW_LINE INDENT return a == 0 and b == 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( a * p + b * q ) % d == 0 and ( b * p - a * q ) % d == 0 ) ; NEW_LINE DEDENT DEDENT def checks ( a , b , x , y , p , q ) : NEW_LINE INDENT if ( check ( a - x , b - y , p , q ) or check ( a + x , b + y , p , q ) or check ( a - y , b + x , p , q ) or check ( a + y , b - x , p , q ) ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT a = - 4 ; NEW_LINE b = - 2 ; NEW_LINE x = 0 ; NEW_LINE y = 0 ; NEW_LINE p = - 2 ; NEW_LINE q = - 1 ; NEW_LINE if ( checks ( a , b , x , y , p , q ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT
Largest triangle that can be inscribed in an ellipse | Python 3 Program to find the biggest triangle which can be inscribed within the ellipse ; Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver Code
from math import * NEW_LINE def trianglearea ( a , b ) : NEW_LINE INDENT if a < 0 or b < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = ( 3 * sqrt ( 3 ) * pow ( a , 2 ) ) / ( 4 * b ) NEW_LINE return area NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a , b = 4 , 2 NEW_LINE print ( round ( trianglearea ( a , b ) , 4 ) ) NEW_LINE DEDENT
Area of the Largest square that can be inscribed in an ellipse | Function to find the area of the square ; a and b cannot be negative ; area of the square ; Driver code
def squarearea ( a , b ) : NEW_LINE INDENT if ( a < 0 or b < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = 4 * ( ( ( pow ( a , 2 ) + pow ( b , 2 ) ) / ( pow ( a , 2 ) * pow ( b , 2 ) ) ) ) NEW_LINE return area NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 4 NEW_LINE b = 2 NEW_LINE print ( squarearea ( a , b ) ) NEW_LINE DEDENT
Largest triangle that can be inscribed in a semicircle | Function to find the area of the triangle ; the radius cannot be negative ; area of the triangle ; Driver Code
def trianglearea ( r ) : NEW_LINE INDENT if r < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return r * r NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT r = 5 NEW_LINE print ( trianglearea ( r ) ) NEW_LINE DEDENT
Largest square that can be inscribed in a semicircle | Function to find the area of the square ; the radius cannot be negative ; area of the square ; Driver code
def squarearea ( r ) : NEW_LINE INDENT if ( r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT a = 4 * ( pow ( r , 2 ) / 5 ) NEW_LINE return a NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT r = 5 NEW_LINE print ( int ( squarearea ( r ) ) ) NEW_LINE DEDENT
Area of Largest rectangle that can be inscribed in an Ellipse | Function to find the area of the rectangle ; a and b cannot be negative ; area of the rectangle ; Driver code
def rectanglearea ( a , b ) : NEW_LINE INDENT if a < 0 or b < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return 2 * a * b NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a , b = 10 , 8 NEW_LINE print ( rectanglearea ( a , b ) ) NEW_LINE DEDENT
Area of a largest square fit in a right angle triangle | Function to find the area of the biggest square ; the height or base or hypotenuse cannot be negative ; side of the square ; squaring to get the area ; Driver Code
def squareArea ( l , b , h ) : NEW_LINE INDENT if l < 0 or b < 0 or h < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT a = ( l * b ) / ( l + b ) NEW_LINE return a * a NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l , b , h = 5 , 12 , 13 NEW_LINE print ( round ( squareArea ( l , b , h ) , 4 ) ) NEW_LINE DEDENT
Queries to check if it is possible to join boxes in a circle | Python 3 implementation of above approach ; Print the answer to each query ; setting the flag for exception ; replacing the greater element in i and j ; checking if that box is not used in previous query . ; checking if connecting to the same box ; case 1 : x < i and y lies between i and j ; case 2 : x lies between i and j and y > j ; if flag is not reset inbetween . ; Driver code
MAX = 50 NEW_LINE def solveQuery ( n , q , qi , qj ) : NEW_LINE INDENT arr = [ None ] * MAX NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT arr [ i ] = 0 NEW_LINE DEDENT for k in range ( q ) : NEW_LINE INDENT flag = 0 NEW_LINE if ( qj [ k ] < qi [ k ] ) : NEW_LINE INDENT qj [ k ] , qi [ k ] = qi [ k ] , qj [ k ] NEW_LINE DEDENT if ( arr [ qi [ k ] ] != 0 or arr [ qj [ k ] ] != 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT elif ( qi [ k ] == qj [ k ] ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 1 , qi [ k ] ) : NEW_LINE INDENT if ( arr [ i ] != 0 and arr [ i ] < qj [ k ] and qi [ k ] < arr [ i ] ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == 0 ) : NEW_LINE INDENT for i in range ( qi [ k ] + 1 , qj [ k ] ) : NEW_LINE INDENT if ( arr [ i ] != 0 and arr [ i ] > qj [ k ] ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT DEDENT if ( flag == 0 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE arr [ qi [ k ] ] = qj [ k ] NEW_LINE arr [ qj [ k ] ] = qi [ k ] NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 10 NEW_LINE q = 7 NEW_LINE qi = [ 1 , 2 , 2 , 2 , 9 , 10 , 8 ] NEW_LINE qj = [ 5 , 7 , 3 , 4 , 9 , 9 , 6 ] NEW_LINE solveQuery ( n , q , qi , qj ) NEW_LINE DEDENT
Minimum squares to cover a rectangle | Python3 program to find the minimum number of squares to cover the surface of the rectangle with given dimensions ; function to count the number of squares that can cover the surface of the rectangle ; Driver code
import math NEW_LINE def squares ( l , b , a ) : NEW_LINE INDENT return math . ceil ( l / a ) * math . ceil ( b / a ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l = 11 NEW_LINE b = 23 NEW_LINE a = 14 NEW_LINE print ( squares ( l , b , a ) ) NEW_LINE DEDENT
Smallest square formed with given rectangles | Recursive function to return gcd of a and b ; Everything divides 0 ; Base case ; a is greater ; Function to find the area of the smallest square ; the length or breadth or side cannot be negative ; LCM of length and breadth ; squaring to get the area ; Driver code
def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 or b == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( a == b ) : NEW_LINE INDENT return a NEW_LINE DEDENT if ( a > b ) : NEW_LINE INDENT return gcd ( a - b , b ) NEW_LINE DEDENT return gcd ( a , b - a ) NEW_LINE DEDENT def squarearea ( l , b ) : NEW_LINE INDENT if ( l < 0 or b < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT n = ( l * b ) / gcd ( l , b ) NEW_LINE return n * n NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT l = 6 NEW_LINE b = 4 NEW_LINE print ( int ( squarearea ( l , b ) ) ) NEW_LINE DEDENT
Find all angles of a triangle in 3D | Python Code for finding all angles of a triangle ; function for finding the angle ; driver code
import math NEW_LINE def angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) : NEW_LINE INDENT num = ( x2 - x1 ) * ( x3 - x1 ) + ( y2 - y1 ) * ( y3 - y1 ) + ( z2 - z1 ) * ( z3 - z1 ) NEW_LINE den = math . sqrt ( ( x2 - x1 ) ** 2 + ( y2 - y1 ) ** 2 + ( z2 - z1 ) ** 2 ) * math . sqrt ( ( x3 - x1 ) ** 2 + ( y3 - y1 ) ** 2 + ( z3 - z1 ) ** 2 ) NEW_LINE angle = math . degrees ( math . acos ( num / den ) ) NEW_LINE return round ( angle , 3 ) NEW_LINE DEDENT x1 = - 1 NEW_LINE y1 = 3 NEW_LINE z1 = 2 NEW_LINE x2 = 2 NEW_LINE y2 = 3 NEW_LINE z2 = 5 NEW_LINE x3 = 3 NEW_LINE y3 = 5 NEW_LINE z3 = - 2 NEW_LINE angle_A = angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) NEW_LINE angle_B = angle_triangle ( x2 , x3 , x1 , y2 , y3 , y1 , z2 , z3 , z1 ) NEW_LINE angle_C = angle_triangle ( x3 , x2 , x1 , y3 , y2 , y1 , z3 , z2 , z1 ) NEW_LINE print ( " Angles ▁ are ▁ : " ) NEW_LINE print ( " angle ▁ A ▁ = ▁ " , angle_A , " degree " ) NEW_LINE print ( " angle ▁ B ▁ = ▁ " , angle_B , " degree " ) NEW_LINE print ( " angle ▁ C ▁ = ▁ " , angle_C , " degree " ) NEW_LINE
Minimum number of square tiles required to fill the rectangular floor | Function to find the number of tiles ; if breadth is divisible by side of square ; tiles required is N / s ; one more tile required ; if length is divisible by side of square ; tiles required is M / s ; one more tile required ; Driver Code ; input length and breadth of rectangle and side of square
def solve ( M , N , s ) : NEW_LINE INDENT if ( N % s == 0 ) : NEW_LINE INDENT N = N // s NEW_LINE DEDENT else : NEW_LINE INDENT N = ( N // s ) + 1 NEW_LINE DEDENT if ( M % s == 0 ) : NEW_LINE INDENT M = M // s NEW_LINE DEDENT else : NEW_LINE INDENT M = ( M // s ) + 1 NEW_LINE DEDENT return M * N NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , M , s = 12 , 13 , 4 NEW_LINE print ( solve ( M , N , s ) ) NEW_LINE DEDENT
Minimum number of square tiles required to fill the rectangular floor | Python 3 implementation of above approach ; Function to find the number of tiles ; no of tiles ; Driver Code ; input length and breadth of rectangle and side of square
import math NEW_LINE def solve ( M , N , s ) : NEW_LINE INDENT ans = ( ( math . ceil ( M / s ) ) * ( math . ceil ( N / s ) ) ) ; NEW_LINE return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 12 NEW_LINE M = 13 NEW_LINE s = 4 NEW_LINE print ( solve ( M , N , s ) ) NEW_LINE DEDENT
Program to find equation of a plane passing through 3 points | Function to find equation of plane . ; Driver Code
def equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) : NEW_LINE INDENT a1 = x2 - x1 NEW_LINE b1 = y2 - y1 NEW_LINE c1 = z2 - z1 NEW_LINE a2 = x3 - x1 NEW_LINE b2 = y3 - y1 NEW_LINE c2 = z3 - z1 NEW_LINE a = b1 * c2 - b2 * c1 NEW_LINE b = a2 * c1 - a1 * c2 NEW_LINE c = a1 * b2 - b1 * a2 NEW_LINE d = ( - a * x1 - b * y1 - c * z1 ) NEW_LINE print " equation ▁ of ▁ plane ▁ is ▁ " , NEW_LINE print a , " x ▁ + " , NEW_LINE print b , " y ▁ + " , NEW_LINE print c , " z ▁ + " , NEW_LINE print d , " = ▁ 0 . " NEW_LINE DEDENT x1 = - 1 NEW_LINE y1 = 2 NEW_LINE z1 = 1 NEW_LINE x2 = 0 NEW_LINE y2 = - 3 NEW_LINE z2 = 2 NEW_LINE x3 = 1 NEW_LINE y3 = 1 NEW_LINE z3 = - 4 NEW_LINE equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) NEW_LINE
Perpendicular distance between a point and a Line in 2 D | Python program to find the distance between a given point and a given line in 2 D . ; Function to find distance ; Driver Code
import math NEW_LINE def shortest_distance ( x1 , y1 , a , b , c ) : NEW_LINE INDENT d = abs ( ( a * x1 + b * y1 + c ) ) / ( math . sqrt ( a * a + b * b ) ) NEW_LINE print ( " Perpendicular ▁ distance ▁ is " ) , d NEW_LINE DEDENT x1 = 5 NEW_LINE y1 = 6 NEW_LINE a = - 2 NEW_LINE b = 3 NEW_LINE c = 4 NEW_LINE shortest_distance ( x1 , y1 , a , b , c ) NEW_LINE
Program to determine the octant of the axial plane | Function to print octant ; Driver Code
def octant ( x , y , z ) : NEW_LINE INDENT if x >= 0 and y >= 0 and z >= 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 1st ▁ octant " NEW_LINE DEDENT elif x < 0 and y >= 0 and z >= 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 2nd ▁ octant " NEW_LINE DEDENT elif x < 0 and y < 0 and z >= 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 3rd ▁ octant " NEW_LINE DEDENT elif x >= 0 and y < 0 and z >= 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 4th ▁ octant " NEW_LINE DEDENT elif x >= 0 and y >= 0 and z < 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 5th ▁ octant " NEW_LINE DEDENT elif x < 0 and y >= 0 and z < 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 6th ▁ octant " NEW_LINE DEDENT elif x < 0 and y < 0 and z < 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 7th ▁ octant " NEW_LINE DEDENT elif x >= 0 and y < 0 and z < 0 : NEW_LINE INDENT print " Point ▁ lies ▁ in ▁ 8th ▁ octant " NEW_LINE DEDENT DEDENT x , y , z = 2 , 3 , 4 NEW_LINE octant ( x , y , z ) NEW_LINE x , y , z = - 4 , 2 , - 8 NEW_LINE octant ( x , y , z ) NEW_LINE x , y , z = - 6 , - 2 , 8 NEW_LINE octant ( x , y , z ) NEW_LINE
Number of triangles in a plane if no more than two points are collinear | Function to find number of triangles in a plane . ; Formula to find number of triangles nC3 = n * ( n - 1 ) * ( n - 2 ) / 6 ; Driver Code
def countNumberOfTriangles ( n ) : NEW_LINE INDENT return ( n * ( n - 1 ) * ( n - 2 ) // 6 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE print ( countNumberOfTriangles ( n ) ) NEW_LINE DEDENT
Centered Dodecagonal Number | Function to calculate centered dodecagonal number ; Formula to calculate nth centered dodecagonal number ; Driver code
def centeredDodecagonal ( n ) : NEW_LINE INDENT return 6 * n * ( n - 1 ) + 1 ; NEW_LINE DEDENT n = 2 NEW_LINE print ( centeredDodecagonal ( n ) ) ; NEW_LINE n = 9 NEW_LINE print ( centeredDodecagonal ( n ) ) ; NEW_LINE
Centered tridecagonal number | Function to find centered tridecagonal number ; Formula to calculate nth centered tridecagonal number ; Driver Code
def centeredTridecagonalNum ( n ) : NEW_LINE INDENT return ( 13 * n * ( n - 1 ) + 2 ) // 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( centeredTridecagonalNum ( n ) ) NEW_LINE n = 10 NEW_LINE print ( centeredTridecagonalNum ( n ) ) NEW_LINE DEDENT
Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Running loop from 1 to n ; get nth pentagonal number ; add to sum ; Driver Program
def pentagon_pyramidal ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT p = ( 3 * i * i - i ) / 2 NEW_LINE sum = sum + p NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 4 NEW_LINE print ( int ( pentagon_pyramidal ( n ) ) ) NEW_LINE
Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Driver Program
def pentagon_pyramidal ( n ) : NEW_LINE INDENT return n * n * ( n + 1 ) / 2 NEW_LINE DEDENT n = 4 NEW_LINE print ( int ( pentagon_pyramidal ( n ) ) ) NEW_LINE
Check if three straight lines are concurrent or not | Return true if three line are concurrent , else false . ; Driven Program
def checkConcurrent ( a1 , b1 , c1 , a2 , b2 , c2 , a3 , b3 , c3 ) : NEW_LINE INDENT return ( a3 * ( b1 * c2 - b2 * c1 ) + b3 * ( c1 * a2 - c2 * a1 ) + c3 * ( a1 * b2 - a2 * b1 ) == 0 ) NEW_LINE DEDENT a1 = 2 NEW_LINE b1 = - 3 NEW_LINE c1 = 5 NEW_LINE a2 = 3 NEW_LINE b2 = 4 NEW_LINE c2 = - 7 NEW_LINE a3 = 9 NEW_LINE b3 = - 5 NEW_LINE c3 = 8 NEW_LINE if ( checkConcurrent ( a1 , b1 , c1 , a2 , b2 , c2 , a3 , b3 , c3 ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Centered Octadecagonal Number | Centered octadecagonal number function ; Formula to calculate nth centered octadecagonal number & return it into main function . ; Driver Code
def center_octadecagon_num ( n ) : NEW_LINE INDENT return ( 9 * n * n - 9 * n + 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( n , " rd ▁ centered ▁ octadecagonal ▁ " + " number ▁ : ▁ " , center_octadecagon_num ( n ) ) NEW_LINE n = 13 NEW_LINE print ( n , " th ▁ centered ▁ octadecagonal ▁ " + " number ▁ : ▁ " , center_octadecagon_num ( n ) ) NEW_LINE DEDENT
Centered decagonal number | Centered decagonal number function ; Formula to calculate nth centered decagonal number & return it into main function . ; Driver Code
def centereddecagonalnum ( n ) : NEW_LINE INDENT return ( 5 * n * n + 5 * n + 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE print ( n , " th ▁ centered ▁ decagonal ▁ " + " number ▁ : ▁ " , centereddecagonalnum ( n ) ) NEW_LINE n = 9 NEW_LINE print ( n , " th ▁ centered ▁ decagonal ▁ " + " number ▁ : ▁ " , centereddecagonalnum ( n ) ) NEW_LINE DEDENT
Lexicographically Kth smallest way to reach given coordinate from origin | Return ( a + b ) ! / a ! b ! ; finding ( a + b ) ! ; finding ( a + b ) ! / a ! ; finding ( a + b ) ! / b ! ; Return the Kth smallest way to reach given coordinate from origin ; if at origin ; if on y - axis ; decrement y . ; Move vertical ; recursive call to take next step . ; If on x - axis ; decrement x . ; Move horizontal . ; recursive call to take next step . ; If x + y C x is greater than K ; Move Horizontal ; recursive call to take next step . ; Move vertical ; recursive call to take next step . ; Driver Code
def factorial ( a , b ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , a + b + 1 ) : NEW_LINE INDENT res = res * i NEW_LINE DEDENT for i in range ( 1 , a + 1 ) : NEW_LINE INDENT res = res // i NEW_LINE DEDENT for i in range ( 1 , b + 1 ) : NEW_LINE INDENT res = res // i NEW_LINE DEDENT return res NEW_LINE DEDENT def Ksmallest ( x , y , k ) : NEW_LINE INDENT if x == 0 and y == 0 : NEW_LINE INDENT return NEW_LINE DEDENT elif x == 0 : NEW_LINE INDENT y -= 1 NEW_LINE print ( " V " , end = " " ) NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT elif y == 0 : NEW_LINE INDENT x -= 1 NEW_LINE print ( " H " , end = " " ) NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT else : NEW_LINE INDENT if factorial ( x - 1 , y ) > k : NEW_LINE INDENT print ( " H " , end = " " ) NEW_LINE Ksmallest ( x - 1 , y , k ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " V " , end = " " ) NEW_LINE Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x , y , k = 2 , 2 , 2 NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT
Centered pentagonal number | Function to calculate Centered pentagonal number . ; Formula to calculate nth Centered pentagonal number . ; Driver Code
def centered_pentagonal_Num ( n ) : NEW_LINE INDENT return ( 5 * n * n - 5 * n + 2 ) // 2 NEW_LINE DEDENT n = 7 NEW_LINE print ( " % sth ▁ Centered ▁ pentagonal ▁ number ▁ : ▁ " % n , centered_pentagonal_Num ( n ) ) NEW_LINE
Find maximum and minimum distance between magnets | Python 3 program for max and min distance ; Function for finding distance between pivots ; Function for minimum distance ; Function for maximum distance ; Drivers code
import math NEW_LINE def pivotDis ( x0 , y0 , x1 , y1 ) : NEW_LINE INDENT return math . sqrt ( ( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) ) NEW_LINE DEDENT def minDis ( D , r1 , r2 ) : NEW_LINE INDENT return max ( ( D - r1 - r2 ) , 0 ) NEW_LINE DEDENT def maxDis ( D , r1 , r2 ) : NEW_LINE INDENT return D + r1 + r2 NEW_LINE DEDENT x0 = 0 NEW_LINE y0 = 0 NEW_LINE x1 = 8 NEW_LINE y1 = 0 NEW_LINE r1 = 4 NEW_LINE r2 = 5 NEW_LINE D = pivotDis ( x0 , y0 , x1 , y1 ) NEW_LINE print ( " Distance ▁ while ▁ repulsion ▁ = ▁ " , int ( maxDis ( D , r1 , r2 ) ) ) NEW_LINE print ( " Distance ▁ while ▁ attraction ▁ = ▁ " , minDis ( D , r1 , r2 ) ) NEW_LINE
Maximize a value for a semicircle of given radius | Function to find the maximum value of F ; using the formula derived for getting the maximum value of F ; Drivers code
def maximumValueOfF ( R ) : NEW_LINE INDENT return 4 * R * R + 0.25 NEW_LINE DEDENT R = 3 NEW_LINE print ( maximumValueOfF ( R ) ) NEW_LINE
Find the other end point of a line with given one end and mid | function to find the end point of a line ; find end point for x coordinates ; find end point for y coordinates ; Driven Program
def otherEndPoint ( x1 , y1 , m1 , m2 ) : NEW_LINE INDENT x2 = ( 2 * m1 - x1 ) NEW_LINE y2 = ( 2 * m2 - y1 ) NEW_LINE print ( " x2 ▁ = ▁ { } , ▁ y2 ▁ = ▁ { } " . format ( x2 , y2 ) ) NEW_LINE DEDENT x1 = - 4 NEW_LINE y1 = - 1 NEW_LINE m1 = 3 NEW_LINE m2 = 5 NEW_LINE otherEndPoint ( x1 , y1 , m1 , m2 ) NEW_LINE