codeparrot/xlcost-text-to-code huggingface dataset:
Area of a leaf inside a square | Python3 code to find the area of leaf inside a square ; Function to find the area of leaf ; Driver code
PI = 3.14159265 NEW_LINE def area_leaf ( a ) : NEW_LINE INDENT return ( a * a * ( PI / 2 - 1 ) ) NEW_LINE DEDENT a = 7 NEW_LINE print ( area_leaf ( a ) ) NEW_LINE
Length of rope tied around three equal circles touching each other | Python3 code to find the length of rope ; Function to find the length of rope ; Driver code
PI = 3.14159265 NEW_LINE def length_rope ( r ) : NEW_LINE INDENT return ( ( 2 * PI * r ) + 6 * r ) NEW_LINE DEDENT r = 7 NEW_LINE print ( length_rope ( r ) ) NEW_LINE
Number of triangles that can be formed with given N points | Python3 implementation of the above approach ; This function returns the required number of triangles ; Hash Map to store the frequency of slope corresponding to a point ( X , Y ) ; Iterate over all possible points ; Calculate slope of all elements with current element ; find the slope with reduced fraction ; Total number of ways to form a triangle having one point as current element ; Subtracting the total number of ways to form a triangle having the same slope or are collinear ; Driver Code
from collections import defaultdict NEW_LINE from math import gcd NEW_LINE def countTriangles ( P , N ) : NEW_LINE INDENT mp = defaultdict ( lambda : 0 ) NEW_LINE ans = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT mp . clear ( ) NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT X = P [ i ] [ 0 ] - P [ j ] [ 0 ] NEW_LINE Y = P [ i ] [ 1 ] - P [ j ] [ 1 ] NEW_LINE g = gcd ( X , Y ) NEW_LINE X //= g NEW_LINE Y //= g NEW_LINE mp [ ( X , Y ) ] += 1 NEW_LINE DEDENT num = N - ( i + 1 ) NEW_LINE ans += ( num * ( num - 1 ) ) // 2 NEW_LINE for j in mp : NEW_LINE INDENT ans -= ( mp [ j ] * ( mp [ j ] - 1 ) ) // 2 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT P = [ [ 0 , 0 ] , [ 2 , 0 ] , [ 1 , 1 ] , [ 2 , 2 ] ] NEW_LINE N = len ( P ) NEW_LINE print ( countTriangles ( P , N ) ) NEW_LINE DEDENT
Area of Incircle of a Right Angled Triangle | Python3 code to find the area of inscribed circle of right angled triangle ; Function to find the area of inscribed circle ; Driver code
PI = 3.14159265 NEW_LINE def area_inscribed ( P , B , H ) : NEW_LINE INDENT return ( ( P + B - H ) * ( P + B - H ) * ( PI / 4 ) ) NEW_LINE DEDENT P = 3 NEW_LINE B = 4 NEW_LINE H = 5 NEW_LINE print ( area_inscribed ( P , B , H ) ) NEW_LINE
Area of Circumcircle of a Right Angled Triangle | Python3 code to find the area of circumscribed circle of right angled triangle ; Function to find the area of circumscribed circle ; Driver code
PI = 3.14159265 NEW_LINE def area_cicumscribed ( c ) : NEW_LINE INDENT return ( c * c * ( PI / 4 ) ) NEW_LINE DEDENT c = 8.0 NEW_LINE print ( area_cicumscribed ( c ) ) NEW_LINE
Largest right circular cylinder that can be inscribed within a cone | Python 3 Program to find the biggest right circular cylinder that can be fit within a right circular cone ; Function to find the biggest right circular cylinder ; radius and height cannot be negative ; radius of right circular cylinder ; height of right circular cylinder ; volume of right circular cylinder ; Driver code
import math NEW_LINE def cyl ( r , h ) : NEW_LINE INDENT if ( r < 0 and h < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT R = ( 2 * r ) / 3 NEW_LINE H = ( 2 * h ) / 3 NEW_LINE V = 3.14 * math . pow ( R , 2 ) * H NEW_LINE return V NEW_LINE DEDENT r = 4 ; h = 8 ; NEW_LINE print ( cyl ( r , h ) ,   " " ) NEW_LINE
Largest cube that can be inscribed within a right circular cylinder | Python 3 Program to find the biggest cube inscribed within a right circular cylinder ; Function to find the volume of the cube ; height and radius cannot be negative ; volume of the cube ; Driver code
import math NEW_LINE def cube ( h , r ) : NEW_LINE INDENT if ( h < 0 and r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT a = math . pow ( h , 3 ) NEW_LINE return a NEW_LINE DEDENT h = 5 ; r = 4 ; NEW_LINE print ( cube ( h , r ) ) ; NEW_LINE
Volume of biggest sphere within a right circular cylinder | Function to find the biggest sphere ; radius and height cannot be negative ; radius of sphere ; Driver code
def sph ( r , h ) : NEW_LINE INDENT if ( r < 0 and h < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT R = r NEW_LINE return float ( R ) NEW_LINE DEDENT r , h = 4 , 8 NEW_LINE print ( sph ( r , h ) ) NEW_LINE
Volume of largest right circular cylinder within a Sphere | Python 3 Program to find the biggest right circular cylinder that can be fit within a sphere ; Function to find the biggest right circular cylinder ; radius cannot be negative ; volume of cylinder ; Driver code
import math NEW_LINE def cyl ( R ) : NEW_LINE INDENT if ( R < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT V = ( ( 2 * 3.14 * math . pow ( R , 3 ) ) / ( 3 * math . sqrt ( 3 ) ) ) ; NEW_LINE return float ( V ) NEW_LINE DEDENT R = 4 NEW_LINE print ( cyl ( R ) ) NEW_LINE
Longest rod that can be inserted within a right circular cylinder | Python 3 Program to find the longest rod that can be fit within a right circular cylinder ; Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
import math NEW_LINE def rod ( h , r ) : NEW_LINE INDENT if ( h < 0 and r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT l = ( math . sqrt ( math . pow ( h , 2 ) + 4 * math . pow ( r , 2 ) ) ) NEW_LINE return float ( l ) NEW_LINE DEDENT h , r = 4 , 1.5 NEW_LINE print ( rod ( h , r ) ) NEW_LINE
Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle | Python3 code to find the area of inscribed circle of equilateral triangle ; Function to find the area of inscribed circle ; Function to find the perimeter of inscribed circle ; Driver code
import math NEW_LINE PI = 3.14159265 NEW_LINE def area_inscribed ( a ) : NEW_LINE INDENT return ( a * a * ( PI / 12 ) ) NEW_LINE DEDENT def perm_inscribed ( a ) : NEW_LINE INDENT return ( PI * ( a / math . sqrt ( 3 ) ) ) NEW_LINE DEDENT a = 6.0 NEW_LINE print ( " Area ▁ of ▁ inscribed ▁ circle ▁ is ▁ : % ▁ f " % area_inscribed ( a ) ) NEW_LINE print ( " Perimeter of inscribed circle is : % f " % perm_inscribed ( a ) ) NEW_LINE
Largest cube that can be inscribed within a right circular cone | Python3 Program to find the biggest cube inscribed within a right circular cone ; Function to find the side of the cube ; height and radius cannot be negative ; side of the cube ; Driver code
import math NEW_LINE def cubeSide ( h , r ) : NEW_LINE INDENT if ( h < 0 and r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT a = ( ( h * r * math . sqrt ( 2 ) ) / ( h + math . sqrt ( 2 ) * r ) ) NEW_LINE return a NEW_LINE DEDENT h = 5 ; r = 6 ; NEW_LINE print ( cubeSide ( h , r ) ,   " " ) NEW_LINE
Largest right circular cone that can be inscribed within a sphere | Python 3 Program to find the biggest cone that can be inscribed within a sphere ; Function to find the radius of the cone ; radius cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
import math NEW_LINE def coner ( R ) : NEW_LINE INDENT if ( R < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT r = ( 2 * math . sqrt ( 2 ) * R ) / 3 NEW_LINE return float ( r ) NEW_LINE DEDENT def coneh ( R ) : NEW_LINE INDENT if ( R < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT h = ( 4 * R ) / 3 NEW_LINE return float ( h ) NEW_LINE DEDENT R = 10 NEW_LINE print ( " r ▁ = ▁ " , coner ( R ) , " , ▁ " , " h ▁ = ▁ " , coneh ( R ) ) NEW_LINE
Largest cone that can be inscribed within a cube | Python 3 Program to find the biggest cone inscribed within a cube ; Function to find the radius of the cone ; side cannot be negative ; radius of the cone ; Function to find the height of the cone ; side cannot be negative ; height of the cone ; Driver code
import math NEW_LINE def coneRadius ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT r = a / math . sqrt ( 2 ) NEW_LINE return r NEW_LINE DEDENT def coneHeight ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT h = a NEW_LINE return h NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 6 NEW_LINE print ( " r ▁ = ▁ " , coneRadius ( a ) , " h ▁ = ▁ " , coneHeight ( a ) ) NEW_LINE DEDENT
Largest cube that can be inscribed within the sphere | Python 3 Program to find the biggest cube inscribed within a sphere ; Function to find the side of the cube ; radius cannot be negative ; side of the cube ; Driver code
from math import sqrt NEW_LINE def largestCube ( r ) : NEW_LINE INDENT if ( r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT a = ( 2 * r ) / sqrt ( 3 ) NEW_LINE return a NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT r = 5 NEW_LINE print ( " { 0 : . 6 } " . format ( largestCube ( r ) ) ) NEW_LINE DEDENT
Largest sphere that can be inscribed inside a cube | Function to find the radius of the sphere ; side cannot be negative ; radius of the sphere ; Driver code
def sphere ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT r = a / 2 NEW_LINE return r NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 5 NEW_LINE print ( sphere ( a ) ) NEW_LINE DEDENT
Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts | function that calculates the maximum no . of cuts ; Driver code ; Calling function .
def numberOfCuts ( M , N ) : NEW_LINE INDENT result = 0 NEW_LINE result = ( M - 1 ) * ( N - 1 ) NEW_LINE return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M , N = 4 , 4 NEW_LINE Cuts = numberOfCuts ( M , N ) NEW_LINE print ( " Maximum ▁ cuts ▁ = ▁ " , Cuts ) NEW_LINE DEDENT
Find maximum volume of a cuboid from the given perimeter and area | Python3 implementation of the above approach ; function to return maximum volume ; calculate length ; calculate volume ; return result ; Driver code ; Function call
from math import sqrt NEW_LINE def maxVol ( P , A ) : NEW_LINE INDENT l = ( P - sqrt ( P * P - 24 * A ) ) / 12 NEW_LINE V = l * ( A / 2.0 - l * ( P / 4.0 - l ) ) NEW_LINE return V NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT P = 20 NEW_LINE A = 16 NEW_LINE print ( maxVol ( P , A ) ) NEW_LINE DEDENT
Program to calculate area and perimeter of a rhombus whose diagonals are given | Python 3 Program to calculate area and perimeter of a rhombus using diagonals ; calculate area and perimeter of a rhombus ; Driver code
from math import sqrt , pow NEW_LINE def rhombusAreaPeri ( d1 , d2 ) : NEW_LINE INDENT area = ( d1 * d2 ) / 2 NEW_LINE perimeter = 2 * sqrt ( pow ( d1 , 2 ) + pow ( d2 , 2 ) ) NEW_LINE print ( " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals " , d1 , " and " , d2 , " is " , area , " . " ) NEW_LINE print ( " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals " , d1 , " and " , d2 , " is " , perimeter , " . " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT d1 = 2 NEW_LINE d2 = 4 NEW_LINE rhombusAreaPeri ( d1 , d2 ) NEW_LINE DEDENT
Area of decagon inscribed within the circle | Python3 Program to find the area of the decagon inscribed within a circle ; Function to find the area of the decagon ; radius cannot be negative ; area of the decagon ; Driver code
from math import sqrt , pow NEW_LINE def area ( r ) : NEW_LINE INDENT if r < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = ( 5 * pow ( r , 2 ) * ( 3 - sqrt ( 5 ) ) * ( sqrt ( 5 ) + ( 2 * sqrt ( 5 ) ) ) ) / 4 NEW_LINE return area NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT r = 8 NEW_LINE print ( area ( r ) ) NEW_LINE DEDENT
Maximum area of rectangle possible with given perimeter | Python3 program to find maximum area rectangle ; Function to find max area ; return area ; Driver code
from math import ceil , floor NEW_LINE def maxArea ( perimeter ) : NEW_LINE INDENT length = int ( ceil ( perimeter / 4 ) ) NEW_LINE breadth = int ( floor ( perimeter / 4 ) ) NEW_LINE return length * breadth NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 38 NEW_LINE print ( " Maximum ▁ Area ▁ = " , maxArea ( n ) ) NEW_LINE DEDENT
Find the foot of perpendicular of a point in a 3 D plane | Function to find foot of perpendicular ; Driver Code ; function call
def foot ( a , b , c , d , x1 , y1 , z1 ) : NEW_LINE INDENT k = ( - a * x1 - b * y1 - c * z1 - d ) / ( a * a + b * b + c * c ) ; NEW_LINE x2 = a * k + x1 ; NEW_LINE y2 = b * k + y1 ; NEW_LINE z2 = c * k + z1 ; NEW_LINE print ( " x2 ▁ = " , round ( x2 , 1 ) ) NEW_LINE print ( " y2 ▁ = " , round ( y2 , 1 ) ) NEW_LINE print ( " z2 ▁ = " , round ( z2 , 1 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 1 NEW_LINE b = - 2 NEW_LINE c = 0 NEW_LINE d = 0 NEW_LINE x1 = - 1 NEW_LINE y1 = 3 NEW_LINE z1 = 4 NEW_LINE foot ( a , b , c , d , x1 , y1 , z1 ) NEW_LINE DEDENT
Equation of parabola from its focus and directrix | Function to find equation of parabola . ; Driver Code
def equation_parabola ( x1 , y1 , a , b , c ) : NEW_LINE INDENT t = a * a + b * b NEW_LINE a1 = t - ( a * a ) NEW_LINE b1 = t - ( b * b ) ; NEW_LINE c1 = ( - 2 * t * x1 ) - ( 2 * c * a ) NEW_LINE d1 = ( - 2 * t * y1 ) - ( 2 * c * b ) NEW_LINE e1 = - 2 * a * b NEW_LINE f1 = ( - c * c ) + ( t * x1 * x1 ) + ( t * y1 * y1 ) NEW_LINE print ( " equation ▁ of ▁ parabola ▁ is " , a1 , " x ^ 2 ▁ + " , b1 , " y ^ 2 ▁ + " , c1 , " x ▁ + " , d1 , " y ▁ + ▁ " , e1 , " xy ▁ + " , f1 , " = ▁ 0 . " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x1 , y1 , a , b , c = 0 , 0 , 3 , - 4 , 2 NEW_LINE equation_parabola ( x1 , y1 , a , b , c ) NEW_LINE DEDENT
Minimum squares to evenly cut a rectangle | Python3 code to find minimum number of squares to make a given rectangle . ; if we take gcd ( l , w ) , this will be largest possible side for square , hence minimum number of square . ; Number of squares . ; Driver Code
import math NEW_LINE def countRectangles ( l , w ) : NEW_LINE INDENT squareSide = math . gcd ( l , w ) NEW_LINE return ( l * w ) / ( squareSide * squareSide ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT l = 4 NEW_LINE w = 6 NEW_LINE ans = countRectangles ( l , w ) NEW_LINE print ( int ( ans ) ) NEW_LINE DEDENT
Equation of circle from center and radius | Function to find the equation of circle ; Printing result ; Driver code
def circle_equation ( x1 , y1 , r ) : NEW_LINE INDENT a = - 2 * x1 ; NEW_LINE b = - 2 * y1 ; NEW_LINE c = ( r * r ) - ( x1 * x1 ) - ( y1 * y1 ) ; NEW_LINE print ( " x ^ 2 ▁ + ▁ ( " , a , " x ) ▁ + ▁ " , end = " " ) ; NEW_LINE print ( " y ^ 2 ▁ + ▁ ( " , b , " y ) ▁ = ▁ " , end = " " ) ; NEW_LINE print ( c , " . " ) ; NEW_LINE DEDENT x1 = 2 ; NEW_LINE y1 = - 3 ; NEW_LINE r = 8 ; NEW_LINE circle_equation ( x1 , y1 , r ) ; NEW_LINE
Program to find the Area and Perimeter of a Semicircle | Function for calculating the area ; Formula for finding the area ; Function for calculating the perimeter ; Formula for finding the perimeter ; driver code ; Get the radius ; Find the area ; Find the perimeter
def area ( r ) : NEW_LINE INDENT return ( 0.5 ) * ( 3.14 ) * ( r * r ) NEW_LINE DEDENT def perimeter ( r ) : NEW_LINE INDENT return ( 3.14 ) * ( r ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT r = 10 NEW_LINE print ( " The ▁ Area ▁ of ▁ Semicircle : ▁ " , area ( r ) ) NEW_LINE print ( " The ▁ Perimeter ▁ of ▁ Semicircle : ▁ " , perimeter ( r ) ) NEW_LINE DEDENT
Check if the given vectors are at equilibrium or not | Function to check the equilibrium of three vectors ; summing the x coordinates ; summing the y coordinates ; summing the z coordinates ; Checking the condition for equilibrium ; Driver code ; Checking for equilibrium
def checkEquilibrium ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) : NEW_LINE INDENT resx = x1 + x2 + x3 NEW_LINE resy = y1 + y2 + y3 NEW_LINE resz = z1 + z2 + z3 NEW_LINE if ( resx == 0 and resy == 0 and resz == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT x1 = - 2 ; y1 = - 7 ; z1 = - 9 NEW_LINE x2 = 5 ; y2 = - 14 ; z2 = 14 NEW_LINE x3 = - 3 ; y3 = 21 ; z3 = - 5 NEW_LINE if ( checkEquilibrium ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ) : NEW_LINE INDENT print ( " The ▁ vectors ▁ are ▁ at ▁ equilibrium . " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " The ▁ vectors ▁ are ▁ not ▁ at ▁ equilibrium . " ) NEW_LINE DEDENT
Find Tangent at a given point on the curve | function for find Tangent ; differentiate given equation ; check that point on the curve or not ; if differentiate is negative ; differentiate is positive ; differentiate is zero ; Driver code ; declare variable ; call function findTangent
def findTangent ( A , x , y ) : NEW_LINE INDENT dif = A - x * 2 NEW_LINE if y == ( 2 * x - x * x ) : NEW_LINE INDENT if dif < 0 : NEW_LINE INDENT print ( " y ▁ = " , dif , " x " , ( x * dif ) + ( y ) ) NEW_LINE DEDENT elif dif > 0 : NEW_LINE INDENT print ( " y ▁ = " , dif , " x + " , - x * dif + y ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A , x , y = 2 , 2 , 0 NEW_LINE findTangent ( A , x , y ) NEW_LINE DEDENT
Find Four points such that they form a square whose sides are parallel to x and y axes | find the largest square ; map to store which points exist ; mark the available points ; a nested loop to choose the opposite corners of square ; remove the chosen point ; remove the chosen point ; check if the other two points exist ; if the square is largest then store it ; add the removed point ; add the removed point ; display the largest square ; Driver code ; given points ; find the largest square
def findLargestSquare ( points , n ) : NEW_LINE INDENT m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] = m . get ( ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) , 0 ) + 1 NEW_LINE DEDENT side = - 1 NEW_LINE x = - 1 NEW_LINE y = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] -= 1 NEW_LINE for j in range ( n ) : NEW_LINE INDENT m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] -= 1 NEW_LINE if ( i != j and ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) == ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ) : NEW_LINE INDENT if ( m [ ( points [ i ] [ 0 ] , points [ j ] [ 1 ] ) ] > 0 and m [ ( points [ j ] [ 0 ] , points [ i ] [ 1 ] ) ] > 0 ) : NEW_LINE INDENT if ( side < abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) or ( side == abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) and ( ( points [ i ] [ 0 ] * points [ i ] [ 0 ] + points [ i ] [ 1 ] * points [ i ] [ 1 ] ) < ( x * x + y * y ) ) ) ) : NEW_LINE INDENT x = points [ i ] [ 0 ] NEW_LINE y = points [ i ] [ 1 ] NEW_LINE side = abs ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) NEW_LINE DEDENT DEDENT DEDENT m [ ( points [ j ] [ 0 ] , points [ j ] [ 1 ] ) ] += 1 NEW_LINE DEDENT m [ ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ] += 1 NEW_LINE DEDENT if ( side != - 1 ) : NEW_LINE INDENT print ( " Side ▁ of ▁ the ▁ square ▁ is ▁ : ▁ " , side , " , points of the square are " , x , " ,   " , y , " ▁ " , ( x + side ) , " , ▁ " , y , " ▁ " , ( x ) , " , ▁ " , ( y + side ) , " ▁ " , ( x + side ) , " , ▁ " , ( y + side ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No ▁ such ▁ square " ) NEW_LINE DEDENT DEDENT n = 6 NEW_LINE points = [ [ 1 , 1 ] , [ 4 , 4 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 1 , 4 ] , [ 4 , 1 ] ] NEW_LINE findLargestSquare ( points , n ) NEW_LINE
Find length of Diagonal of Hexagon | Function to find the diagonal of the hexagon ; side cannot be negative ; diagonal of the hexagon ; Driver code
def hexadiagonal ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return 2 * a NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 4 NEW_LINE print ( hexadiagonal ( a ) ) NEW_LINE DEDENT
Program to find the side of the Octagon inscribed within the square | Python 3 Program to find the side of the octagon which can be inscribed within the square ; Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Driver code ; Get he square side ; Find the side length of the square
from math import sqrt NEW_LINE def octaside ( a ) : NEW_LINE INDENT if a < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT s = a / ( sqrt ( 2 ) + 1 ) NEW_LINE return s NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 4 NEW_LINE print ( " { 0 : . 6 } " . format ( octaside ( a ) ) ) NEW_LINE DEDENT
Check whether it is possible to join two points given on circle such that distance between them is k | Python3 program to implement above approach ; Return distance between the centers ; Distance between centers ; Case 5 ; SubCase 1 ; Subcase 2 ; Case 1 ; Case 3 ; Case 4 ; Case 2 ; Since value of k wialways be an integer ; Driver Code
from math import sqrt , ceil , floor NEW_LINE def dis ( x1 , y1 , x2 , y2 ) : NEW_LINE INDENT return sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) NEW_LINE DEDENT def check ( c1 , c2 , k ) : NEW_LINE INDENT min = 0 NEW_LINE max = 0 NEW_LINE de = dis ( c1 [ 0 ] , c1 [ 1 ] , c2 [ 0 ] , c2 [ 1 ] ) NEW_LINE if ( de == 0 ) : NEW_LINE INDENT if ( c1 [ 2 ] == c2 [ 2 ] ) : NEW_LINE INDENT min = 0 NEW_LINE max = 0 NEW_LINE DEDENT else : NEW_LINE INDENT if ( c1 [ 2 ] - c2 [ 2 ] > 0 ) : NEW_LINE INDENT min = c1 [ 2 ] - c2 [ 2 ] NEW_LINE max = min + 2 * c2 [ 2 ] NEW_LINE DEDENT else : NEW_LINE INDENT min = c2 [ 2 ] - c1 [ 2 ] NEW_LINE max = min + 2 * c1 [ 2 ] NEW_LINE DEDENT DEDENT DEDENT elif ( de >= c1 [ 2 ] + c2 [ 2 ] ) : NEW_LINE INDENT min = de - c1 [ 2 ] - c2 [ 2 ] NEW_LINE max = de + c1 [ 2 ] + c2 [ 2 ] NEW_LINE DEDENT elif ( de + c2 [ 2 ] < c1 [ 2 ] ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = c1 [ 2 ] - de - c2 [ 2 ] NEW_LINE DEDENT elif ( de + c1 [ 2 ] < c2 [ 2 ] ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = c2 [ 2 ] - de - c1 [ 2 ] NEW_LINE DEDENT elif ( ( de + c2 [ 2 ] >= c1 [ 2 ] ) or ( de + c1 [ 2 ] >= c2 [ 2 ] ) ) : NEW_LINE INDENT max = c2 [ 2 ] + c1 [ 2 ] + de NEW_LINE min = 0 NEW_LINE DEDENT temin = ceil ( min ) NEW_LINE re = max NEW_LINE if ( k >= temin and k <= re ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT circle1 = [ 0 , 0 , 5 ] NEW_LINE circle2 = [ 8 , 3 , 2 ] NEW_LINE k = 3 NEW_LINE if ( check ( circle1 , circle2 , k ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT
Check if it is possible to move from ( 0 , 0 ) to ( x , y ) in N steps | Function to check whether it is possible or not to move from ( 0 , 0 ) to ( x , y ) in exactly n steps ; Driver code
def Arrive ( a , b , n ) : NEW_LINE INDENT if ( n >= abs ( a ) + abs ( b ) and ( n - ( abs ( a ) + abs ( b ) ) ) % 2 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT a = 5 NEW_LINE b = 5 NEW_LINE n = 11 NEW_LINE if ( Arrive ( a , b , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT
Check if it is possible to move from ( a , 0 ) to ( b , 0 ) with given jumps | Function to check if it is possible ; Driver code ; function call
def Move ( a , x , b ) : NEW_LINE INDENT if ( ( ( ( b - a ) % x == 0 ) or ( ( b - a - 1 ) % x == 0 ) and a + 1 != b ) and b >= a ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 3 NEW_LINE x = 2 NEW_LINE b = 7 NEW_LINE if ( Move ( a , x , b ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT
Area of a triangle inscribed in a rectangle which is inscribed in an ellipse | Function to find the area of the triangle ; length of a and b cannot be negative ; area of the triangle ; Driver code
def area ( a , b ) : NEW_LINE INDENT if ( a < 0 or b < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT A = a * b NEW_LINE return A NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 5 NEW_LINE b = 2 NEW_LINE print ( area ( a , b ) ) NEW_LINE DEDENT