codeparrot/xlcost-text-to-code huggingface dataset:
Find all angles of a triangle in 3D | function for finding the angle ; Driver code
< ? php function angle_triangle ( $ x1 , $ x2 , $ x3 , $ y1 , $ y2 , $ y3 , $ z1 , $ z2 , $ z3 ) { $ num = ( $ x2 - $ x1 ) * ( $ x3 - $ x1 ) + ( $ y2 - $ y1 ) * ( $ y3 - $ y1 ) + ( $ z2 - $ z1 ) * ( $ z3 - $ z1 ) ; $ den = sqrt ( pow ( ( $ x2 - $ x1 ) , 2 ) + pow ( ( $ y2 - $ y1 ) , 2 ) + pow ( ( $ z2 - $ z1 ) , 2 ) ) * sqrt ( pow ( ( $ x3 - $ x1 ) , 2 ) + pow ( ( $ y3 - $ y1 ) , 2 ) + pow ( ( $ z3 - $ z1 ) , 2 ) ) ; $ angle = acos ( $ num / $ den ) * ( 180.0 / 3.141592653589793238463 ) ; return $ angle ; } $ x1 = -1 ; $ y1 = 3 ; $ z1 = 2 ; $ x2 = 2 ; $ y2 = 3 ; $ z2 = 5 ; $ x3 = 3 ; $ y3 = 5 ; $ z3 = -2 ; $ angle_A = angle_triangle ( $ x1 , $ x2 , $ x3 , $ y1 , $ y2 , $ y3 , $ z1 , $ z2 , $ z3 ) ; $ angle_B = angle_triangle ( $ x2 , $ x3 , $ x1 , $ y2 , $ y3 , $ y1 , $ z2 , $ z3 , $ z1 ) ; $ angle_C = angle_triangle ( $ x3 , $ x2 , $ x1 , $ y3 , $ y2 , $ y1 , $ z3 , $ z2 , $ z1 ) ; echo " Angles ▁ are ▁ : STRNEWLINE " ; echo " angle A = " ▁ . ▁ round ( $ angle _ A , ▁ 3 ) ▁ . ▁ " degree " ; STRNEWLINE echo ▁ " angle B = " ▁ . ▁ round ( $ angle _ B , ▁ 3 ) ▁ . ▁ " degree " ; STRNEWLINE echo ▁ " angle C = " ▁ . ▁ round ( $ angle _ C , ▁ 3 ) ▁ . ▁ " degree " ? >
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 ; input length and breadth of rectangle and side of square
< ? php function solve ( $ M , $ N , $ s ) { if ( $ N % $ s == 0 ) { $ N = $ N / $ s ; } else { $ N = ( $ N / $ s ) + 1 ; } if ( $ M % $ s == 0 ) { $ M = $ M / $ s ; } else { $ M = ( $ M / $ s ) + 1 ; } return ( int ) $ M * $ N ; } $ N = 12 ; $ M = 13 ; $ s = 4 ; echo solve ( $ M , $ N , $ s ) ; ? >
Minimum number of square tiles required to fill the rectangular floor | Function to find the number of tiles ; no of tiles ; input length and breadth of rectangle and side of square
< ? php function solve ( $ M , $ N , $ s ) { $ ans = ( ( int ) ( ceil ( $ M / $ s ) ) * ( int ) ( ceil ( $ N / $ s ) ) ) ; return $ ans ; } $ N = 12 ; $ M = 13 ; $ s = 4 ; echo solve ( $ M , $ N , $ s ) ; ? >
Program to find equation of a plane passing through 3 points | Function to find equation of plane . ; Driver Code
< ? php function equation_plane ( $ x1 , $ y1 , $ z1 , $ x2 , $ y2 , $ z2 , $ x3 , $ y3 , $ z3 ) { $ a1 = $ x2 - $ x1 ; $ b1 = $ y2 - $ y1 ; $ c1 = $ z2 - $ z1 ; $ a2 = $ x3 - $ x1 ; $ b2 = $ y3 - $ y1 ; $ c2 = $ z3 - $ z1 ; $ a = $ b1 * $ c2 - $ b2 * $ c1 ; $ b = $ a2 * $ c1 - $ a1 * $ c2 ; $ c = $ a1 * $ b2 - $ b1 * $ a2 ; $ d = ( - $ a * $ x1 - $ b * $ y1 - $ c * $ z1 ) ; echo sprintf ( " equation ▁ of ▁ the ▁ plane ▁ is ▁ % .2fx " . " ▁ + ▁ % .2fy ▁ + ▁ % .2fz ▁ + ▁ % .2f ▁ = ▁ 0" , $ a , $ b , $ c , $ d ) ; } $ x1 = -1 ; $ y1 = 2 ; $ z1 = 1 ; $ x2 = 0 ; $ y2 = -3 ; $ z2 = 2 ; $ x3 = 1 ; $ y3 = 1 ; $ z3 = -4 ; equation_plane ( $ x1 , $ y1 , $ z1 , $ x2 , $ y2 , $ z2 , $ x3 , $ y3 , $ z3 ) ; ? >
Perpendicular distance between a point and a Line in 2 D | Function to find distance ; Driver Code
< ? php function shortest_distance ( $ x1 , $ y1 , $ a , $ b , $ c ) { $ d = abs ( ( $ a * $ x1 + $ b * $ y1 + $ c ) ) / ( sqrt ( $ a * $ a + $ b * $ b ) ) ; echo " Perpendicular ▁ distance ▁ is ▁ " , $ d ; } $ x1 = 5 ; $ y1 = 6 ; $ a = -2 ; $ b = 3 ; $ c = 4 ; shortest_distance ( $ x1 , $ y1 , $ a , $ b , $ c ) ; ? >
Program to determine the octant of the axial plane | Function to print octant ; Driver Code
< ? php function octant ( $ x , $ y , $ z ) { if ( $ x >= 0 && $ y >= 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 1st ▁ octant STRNEWLINE " ; else if ( $ x < 0 && $ y >= 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 2nd ▁ octant STRNEWLINE " ; else if ( $ x < 0 && $ y < 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 3rd ▁ octant STRNEWLINE " ; else if ( $ x >= 0 && $ y < 0 && $ z >= 0 ) echo " Point ▁ lies ▁ in ▁ 4th ▁ octant STRNEWLINE " ; else if ( $ x >= 0 && $ y >= 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 5th ▁ octant STRNEWLINE " ; else if ( $ x < 0 && $ y >= 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 6th ▁ octant STRNEWLINE " ; else if ( $ x < 0 && $ y < 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 7th ▁ octant STRNEWLINE " ; else if ( $ x >= 0 && $ y < 0 && $ z < 0 ) echo " Point ▁ lies ▁ in ▁ 8th ▁ octant STRNEWLINE " ; } $ x = 2 ; $ y = 3 ; $ z = 4 ; octant ( $ x , $ y , $ z ) ; $ x = -4 ; $ y = 2 ; $ z = -8 ; octant ( $ x , $ y , $ z ) ; $ x = -6 ; $ y = -2 ; $ z = 8 ; octant ( $ x , $ y , $ z ) ; ? >
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
< ? php function countNumberOfTriangles ( $ n ) { return $ n * ( $ n - 1 ) * ( $ n - 2 ) / 6 ; } $ n = 4 ; echo countNumberOfTriangles ( $ n ) ; ? >
Centered tridecagonal number | Function to find nth centered tridecagonal number ; Formula to calculate nth centered tridecagonal number ; Driver Code
< ? php function centeredTridecagonalNum ( $ n ) { return ( 13 * $ n * ( $ n - 1 ) + 2 ) / 2 ; } $ n = 3 ; echo centeredTridecagonalNum ( $ n ) ; echo " STRNEWLINE " ; $ n = 10 ; echo centeredTridecagonalNum ( $ n ) ; ? >
Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Running loop from 1 to n ; get nth pentagonal number ; add to sum ; Driver Code
< ? php function pentagon_pyramidal ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ p = ( 3 * $ i * $ i - $ i ) / 2 ; $ sum = $ sum + $ p ; } return $ sum ; } $ n = 4 ; echo pentagon_pyramidal ( $ n ) ; ? >
Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Driver Code
< ? php function pentagon_pyramidal ( $ n ) { return $ n * $ n * ( $ n + 1 ) / 2 ; } $ n = 4 ; echo pentagon_pyramidal ( $ n ) ; ? >
Check if three straight lines are concurrent or not | Return true if three line are concurrent , else false . ; Driver Code
< ? php function checkConcurrent ( $ a1 , $ b1 , $ c1 , $ a2 , $ b2 , $ c2 , $ a3 , $ b3 , $ c3 ) { return ( $ a3 * ( $ b1 * $ c2 - $ b2 * $ c1 ) + $ b3 * ( $ c1 * $ a2 - $ c2 * $ a1 ) + $ c3 * ( $ a1 * $ b2 - $ a2 * $ b1 ) == 0 ) ; } $ a1 = 2 ; $ b1 = -3 ; $ c1 = 5 ; $ a2 = 3 ; $ b2 = 4 ; $ c2 = -7 ; $ a3 = 9 ; $ b3 = -5 ; $ c3 = 8 ; if ( checkConcurrent ( $ a1 , $ b1 , $ c1 , $ a2 , $ b2 , $ c2 , $ a3 , $ b3 , $ c3 ) ) echo " Yes " ; else echo " No " ; ? >
Centered Octadecagonal Number | centered octadecagon function ; Formula to calculate nth centered octadecagonal number ; Driver Code
< ? php function center_octadecagon_num ( $ n ) { return ( 9 * $ n * $ n - 9 * $ n + 1 ) ; } $ n = 3 ; echo $ n , " th ▁ centered ▁ octadecagonal ▁ " . " number ▁ : ▁ " , center_octadecagon_num ( $ n ) ; echo " STRNEWLINE " ; $ n = 13 ; echo $ n , " th ▁ centered ▁ octadecagonal ▁ " . " number ▁ : ▁ " , center_octadecagon_num ( $ n ) ; ? >
Centered decagonal number | Centered decagonal number function ; Formula to calculate nth centered decagonal number & return it into main function . ; Driver Code
< ? php function centereddecagonalnum ( $ n ) { return ( 5 * $ n * $ n + 5 * $ n + 1 ) ; } $ n = 5 ; echo $ n , " th ▁ centered ▁ decagonal " , " number : ▁ " ; echo centereddecagonalnum ( $ n ) ; echo " STRNEWLINE " ; $ n = 9 ; echo $ n , " th ▁ centered ▁ decagonal " , " number : ▁ " ; echo centereddecagonalnum ( $ n ) ; ? >
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
< ? php function factorial ( $ a , $ b ) { $ res = 1 ; for ( $ i = 1 ; $ i <= ( $ a + $ b ) ; $ i ++ ) $ res = $ res * $ i ; for ( $ i = 1 ; $ i <= $ a ; $ i ++ ) $ res = $ res / $ i ; for ( $ i = 1 ; $ i <= $ b ; $ i ++ ) $ res = $ res / $ i ; return $ res ; } function Ksmallest ( $ x , $ y , $ k ) { if ( $ x == 0 && $ y == 0 ) return ; else if ( $ x == 0 ) { $ y -- ; echo ( " V " ) ; Ksmallest ( $ x , $ y , $ k ) ; } else if ( $ y == 0 ) { $ x -- ; echo ( " H " ) ; Ksmallest ( $ x , $ y , $ k ) ; } else { if ( factorial ( $ x - 1 , $ y ) > $ k ) { echo ( " H " ) ; Ksmallest ( $ x - 1 , $ y , $ k ) ; } else { echo ( " V " ) ; Ksmallest ( $ x , $ y - 1 , $ k - factorial ( $ x - 1 , $ y ) ) ; } } } $ x = 2 ; $ y = 2 ; $ k = 2 ; Ksmallest ( $ x , $ y , $ k ) ; ? >
Centered pentagonal number | Centered pentagonal number function ; Formula to calculate nth Centered pentagonal number and return it into main function . ; Driver Code
< ? php function centered_pentagonal_Num ( $ n ) { return ( 5 * $ n * $ n - 5 * $ n + 2 ) / 2 ; } $ n = 7 ; echo $ n , " th ▁ Centered ▁ pentagonal ▁ number : ▁ " ; echo centered_pentagonal_Num ( $ n ) ; ? >
Find maximum and minimum distance between magnets | Function for finding distance between pivots ; Function for minimum distance ; Function for maximum distance ; Driver code
< ? php function pivotDis ( $ x0 , $ y0 , $ x1 , $ y1 ) { return sqrt ( ( $ x1 - $ x0 ) * ( $ x1 - $ x0 ) + ( $ y1 - $ y0 ) * ( $ y1 - $ y0 ) ) ; } function minDis ( $ D , $ r1 , $ r2 ) { return max ( ( $ D - $ r1 - $ r2 ) , 0 ) ; } function maxDis ( $ D , $ r1 , $ r2 ) { return $ D + $ r1 + $ r2 ; } $ x0 = 0 ; $ y0 = 0 ; $ x1 = 8 ; $ y1 = 0 ; $ r1 = 4 ; $ r2 = 5 ; $ D = pivotDis ( $ x0 , $ y0 , $ x1 , $ y1 ) ; echo " Distance ▁ while ▁ repulsion ▁ = ▁ " , maxDis ( $ D , $ r1 , $ r2 ) ; echo " Distance while attraction = " , minDis ( $ D , $ r1 , $ r2 ) ; ? >
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
< ? php function maximumValueOfF ( $ R ) { return 4 * $ R * $ R + 0.25 ; } $ R = 3 ; echo maximumValueOfF ( $ R ) ; ? >
Find the other end point of a line with given one end and mid | PHP function to find the end point of a line ; find end point for x coordinates ; find end point for y coordinates ; Driven Program
< ? php function otherEndPoint ( $ x1 , $ y1 , $ m1 , $ m2 ) { $ x2 = ( 2 * $ m1 - $ x1 ) ; $ y2 = ( 2 * $ m2 - $ y1 ) ; echo " x2 ▁ = ▁ " . $ x2 . " , ▁ y2 ▁ = ▁ " . $ y2 ; } $ x1 = -4 ; $ y1 = -1 ; $ m1 = 3 ; $ m2 = 5 ; otherEndPoint ( $ x1 , $ y1 , $ m1 , $ m2 ) ; ? >
Coordinates of rectangle with given points lie inside | function to print coordinate of smallest rectangle ; find Xmax and Xmin ; find Ymax and Ymin ; print all four coordinates ; Driver Code
< ? php function printRect ( $ X , $ Y , $ n ) { $ Xmax = max ( $ X ) ; $ Xmin = min ( $ X ) ; $ Ymax = max ( $ Y ) ; $ Ymin = min ( $ Y ) ; echo " { " , $ Xmin , " , ▁ " , $ Ymin , " } " , " STRNEWLINE " ; echo " { " , $ Xmin , " , ▁ " , $ Ymax , " } " , " STRNEWLINE " ; echo " { " , $ Xmax , " , ▁ " , $ Ymax , " } " , " STRNEWLINE " ; echo " { " , $ Xmax , " , ▁ " , $ Ymin , " } " ; } $ X = array ( 4 , 3 , 6 , 1 , -1 , 12 ) ; $ Y = array ( 4 , 1 , 10 , 3 , 7 , -1 ) ; $ n = count ( $ X ) ; printRect ( $ X , $ Y , $ n ) ; ? >
Check if a line passes through the origin | PHP program to find if line passing through two coordinates also passes through origin or not ; Driver code
< ? php function checkOrigin ( $ x1 , $ y1 , $ x2 , $ y2 ) { return ( $ x1 * ( $ y2 - $ y1 ) == $ y1 * ( $ x2 - $ x1 ) ) ; } if ( checkOrigin ( 1 , 28 , 2 , 56 ) == true ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >
Number of horizontal or vertical line segments to connect 3 points | Function to check if the third point forms a rectangle with other two points at corners ; Returns true if point k can be used as a joining point to connect using two line segments ; Check for the valid polyline with two segments ; Check whether the X - coordinates or Y - cocordinates are same . ; Iterate over all pairs to check for two line segments ; Otherwise answer is three . ; Driver code
< ? php function isBetween ( $ a , $ b , $ c ) { return min ( $ a , $ b ) <= $ c and $ c <= max ( $ a , $ b ) ; } function canJoin ( $ x , $ y , $ i , $ j , $ k ) { return ( $ x [ $ k ] == $ x [ $ i ] or $ x [ $ k ] == $ x [ $ j ] ) and isBetween ( $ y [ $ i ] , $ y [ $ j ] , $ y [ $ k ] ) or ( $ y [ $ k ] == $ y [ $ i ] or $ y [ $ k ] == $ y [ $ j ] ) and isBetween ( $ x [ $ i ] , $ x [ $ j ] , $ x [ $ k ] ) ; } function countLineSegments ( $ x , $ y ) { if ( ( $ x [ 0 ] == $ x [ 1 ] and $ x [ 1 ] == $ x [ 2 ] ) or ( $ y [ 0 ] == $ y [ 1 ] and $ y [ 1 ] == $ y [ 2 ] ) ) return 1 ; else if ( canJoin ( $ x , $ y , 0 , 1 , 2 ) or canJoin ( $ x , $ y , 0 , 2 , 1 ) || canJoin ( $ x , $ y , 1 , 2 , 0 ) ) return 2 ; else return 3 ; } $ x = array ( ) ; $ y = array ( ) ; $ x [ 0 ] = -1 ; $ y [ 0 ] = -1 ; $ x [ 1 ] = -1 ; $ y [ 1 ] = 3 ; $ x [ 2 ] = 4 ; $ y [ 2 ] = 3 ; echo countLineSegments ( $ x , $ y ) ; ? >
Pythagorean Quadruple | function for checking ; Driver Code
< ? php function pythagorean_quadruple ( $ a , $ b , $ c , $ d ) { $ sum = $ a * $ a + $ b * $ b + $ c * $ c ; if ( $ d * $ d == $ sum ) return true ; else return false ; } $ a = 1 ; $ b = 2 ; $ c = 2 ; $ d = 3 ; if ( pythagorean_quadruple ( $ a , $ b , $ c , $ d ) ) echo " Yes " ; else echo " No " ; ? >
Program for Volume and Surface area of Frustum of Cone | Function to calculate Volume of frustum of cone ; Function to calculate Curved Surface area of frustum of cone ; Function to calculate Total Surface area of frustum of cone ; Driver Code ; Printing value of volume and surface area
< ? php function volume ( $ r , $ R , $ h ) { $ pi = 3.14159 ; return ( 1 / ( 3 ) ) * $ pi * $ h * ( $ r * $ r + $ R * $ R + $ r * $ R ) ; } function curved_surface_area ( $ r , $ R , $ l ) { $ pi = 3.14159 ; return $ pi * $ l * ( $ R + $ r ) ; } function total_surface_area ( $ r , $ R , $ l , $ h ) { $ pi = 3.14159 ; return ( $ pi * $ l * ( $ R + $ r ) + $ pi * ( $ r * $ r + $ R * $ R ) ) ; } $ small_radius = 3 ; $ big_radius = 8 ; $ slant_height = 13 ; $ height = 12 ; echo ( " Volume ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( volume ( $ small_radius , $ big_radius , $ height ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Curved ▁ Surface ▁ Area ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( curved_surface_area ( $ small_radius , $ big_radius , $ slant_height ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Total ▁ Surface ▁ Area ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; echo ( total_surface_area ( $ small_radius , $ big_radius , $ slant_height , $ height ) ) ; ? >
Program to find Perimeter / Circumference of Square and Rectangle | PHP program to find Circumference of a square ; Driver Code
< ? php function Circumference ( $ a ) { return 4 * $ a ; } $ a = 5 ; echo " Circumference ▁ of ▁ a ▁ " . " square ▁ is ▁ " , Circumference ( $ a ) ; ? >
Maximum area of quadrilateral | PHP program to find maximum are of a quadrilateral ; Calculating the semi - perimeter of the given quadrilateral ; Applying Brahmagupta 's formula to  get maximum area of quadrilateral ; Driver code
< ? php function maxArea ( $ a , $ b , $ c , $ d ) { $ semiperimeter = ( $ a + $ b + $ c + $ d ) / 2 ; return sqrt ( ( $ semiperimeter - $ a ) * ( $ semiperimeter - $ b ) * ( $ semiperimeter - $ c ) * ( $ semiperimeter - $ d ) ) ; } $ a = 1 ; $ b = 2 ; $ c = 1 ; $ d = 2 ; echo ( maxArea ( $ a , $ b , $ c , $ d ) ) ; ? >
Find minimum radius such that atleast k point lie inside the circle | Return minimum distance required so that aleast k point lie inside the circle . ; Finding distance between of each point from origin ; Sorting the distance ; Driver Code
< ? php function minRadius ( $ k , $ x , $ y , $ n ) { $ dis = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ dis [ $ i ] = $ x [ $ i ] * $ x [ $ i ] + $ y [ $ i ] * $ y [ $ i ] ; sort ( $ dis ) ; return $ dis [ $ k - 1 ] ; } $ k = 3 ; $ x = array ( 1 , -1 , 1 ) ; $ y = array ( 1 , -1 , -1 ) ; $ n = count ( $ x ) ; echo minRadius ( $ k , $ x , $ y , $ n ) ; ? >
Program for Area And Perimeter Of Rectangle | Utility function ; Driver program
< ? php function areaRectangle ( $ a , $ b ) { $ area = $ a * $ b ; return $ area ; } function perimeterRectangle ( $ a , $ b ) { $ perimeter = 2 * ( $ a + $ b ) ; return $ perimeter ; } $ a = 5 ; $ b = 6 ; echo ( " Area ▁ = ▁ " ) ; echo ( areaRectangle ( $ a , $ b ) ) ; echo ( " STRNEWLINE " ) ; echo ( " Perimeter ▁ = ▁ " ) ; echo ( perimeterRectangle ( $ a , $ b ) ) ; ? >
Program for Area Of Square | PHP program to find the aria of the square ; Driver Code
< ? php function areaSquare ( $ side ) { $ area = $ side * $ side ; return $ area ; } $ side = 4 ; echo ( areaSquare ( $ side ) ) ; ? >
Minimum Perimeter of n blocks | PHP program to find minimum perimeter using n blocks . ; if n is a perfect square ; Number of rows ; perimeter of the rectangular grid ; if there are blocks left ; Driver code
< ? php function minPerimeter ( $ n ) { $ l = floor ( sqrt ( $ n ) ) ; $ sq = $ l * $ l ; if ( $ sq == $ n ) return $ l * 4 ; else { $ row = floor ( $ n / $ l ) ; $ perimeter = 2 * ( $ l + $ row ) ; if ( $ n % $ l != 0 ) $ perimeter += 2 ; return $ perimeter ; } } $ n = 10 ; echo minPerimeter ( $ n ) ; ? >
Find if it 's possible to rotate the page by an angle or not. | function to find if it 's possible to rotate page or not ; Calculating distance b / w points ; If distance is not equal ; If the points are in same line ; Points a , b , and c
< ? php function possibleOrNot ( $ a1 , $ a2 , $ b1 , $ b2 , $ c1 , $ c2 ) { $ dis1 = pow ( $ b1 - $ a1 , 2 ) + pow ( $ b2 - $ a2 , 2 ) ; $ dis2 = pow ( $ c1 - $ b1 , 2 ) + pow ( $ c2 - $ b2 , 2 ) ; if ( $ dis1 != $ dis2 ) echo " No " ; else if ( $ b1 == ( ( $ a1 + $ c1 ) / 2.0 ) && $ b2 == ( ( $ a2 + $ c2 ) / 2.0 ) ) echo " No " ; else echo " Yes " ; } $ a1 = 1 ; $ a2 = 0 ; $ b1 = 2 ; $ b2 = 0 ; $ c1 = 3 ; $ c2 = 0 ; possibleOrNot ( $ a1 , $ a2 , $ b1 , $ b2 , $ c1 , $ c2 ) ; ? >
Check if two given circles touch or intersect each other | PHP program to check if two circles touch each other or not . ; Driver code
< ? php function circle ( $ x1 , $ y1 , $ x2 , $ y2 , $ r1 , $ r2 ) { $ distSq = ( $ x1 - $ x2 ) * ( $ x1 - $ x2 ) + ( $ y1 - $ y2 ) * ( $ y1 - $ y2 ) ; $ radSumSq = ( $ r1 + $ r2 ) * ( $ r1 + $ r2 ) ; if ( $ distSq == $ radSumSq ) return 1 ; else if ( $ distSq > $ radSumSq ) return -1 ; else return 0 ; } $ x1 = -10 ; $ y1 = 8 ; $ x2 = 14 ; $ y2 = -24 ; $ r1 = 30 ; $ r2 = 10 ; $ t = circle ( $ x1 , $ y1 , $ x2 , $ y2 , $ r1 , $ r2 ) ; if ( $ t == 1 ) echo " Circle ▁ touch ▁ to ▁ each ▁ other . " ; else if ( $ t < 0 ) echo " Circle ▁ not ▁ touch ▁ to ▁ each ▁ other . " ; else echo " Circle ▁ intersect ▁ to ▁ each ▁ other . " ; ? >
Count of obtuse angles in a circle with ' k ' equidistant points between 2 given points | PHP program to count number of obtuse angles for given two points . ; There are two arcs connecting a and b . Let us count points on both arcs . ; Both arcs have same number of points ; Points on smaller arc is answer ; Driver code
< ? php function countObtuseAngles ( $ a , $ b , $ k ) { $ c1 = ( $ b - $ a ) - 1 ; $ c2 = ( $ k - $ b ) + ( $ a - 1 ) ; if ( $ c1 == $ c2 ) return 0 ; return min ( $ c1 , $ c2 ) ; } $ k = 6 ; $ a = 1 ; $ b = 3 ; echo countObtuseAngles ( $ a , $ b , $ k ) ; ? >
Count of acute , obtuse and right triangles with given sides | Find the number of acute , right , obtuse triangle that can be formed from given array . ; Finding the square of each element of array . ; Sort the sides of array and their squares . ; x for acute triangles y for right triangles z for obtuse triangles ; Finding the farthest point p where a ^ 2 + b ^ 2 >= c ^ 2. ; Finding the farthest point q where a + b > c . ; If point p make right triangle . ; All triangle between j and p are acute triangles . So add p - j - 1 in x . ; Increment y by 1. ; All triangle between q and p are acute triangles . So add q - p in z . ; If no right triangle ; All triangle between j and p are acute triangles . So add p - j in x . ; All triangle between q and p are acute triangles . So add q - p in z . ; Driver Code
< ? php function findTriangle ( $ a , $ n ) { $ b [ $ n + 2 ] = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ b [ $ i ] = $ a [ $ i ] * $ a [ $ i ] ; sort ( $ a ) ; sort ( $ b ) ; $ x = 0 ; $ y = 0 ; $ z = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ p = $ i + 1 ; $ q = $ i + 1 ; for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) { while ( $ p < $ n - 1 && $ b [ $ i ] + $ b [ $ j ] >= $ b [ $ p + 1 ] ) $ p ++ ; $ q = max ( $ q , $ p ) ; while ( $ q < $ n - 1 && $ a [ $ i ] + $ a [ $ j ] > $ a [ $ q + 1 ] ) $ q ++ ; if ( $ b [ $ i ] + $ b [ $ j ] == $ b [ $ p ] ) { $ x += max ( $ p - $ j - 1 , 0 ) ; $ y ++ ; $ z += $ q - $ p ; } else { $ x += max ( $ p - $ j , 0 ) ; $ z += $ q - $ p ; } } } echo " Acute ▁ Triangle : ▁ " , $ x , " STRNEWLINE " ; echo " Right ▁ Triangle : ▁ " , $ y , " STRNEWLINE " ; echo " Obtuse ▁ Triangle : ▁ " , $ z , " STRNEWLINE " ; } $ arr = array ( 2 , 3 , 9 , 10 , 12 , 15 ) ; $ n = sizeof ( $ arr ) ; findTriangle ( $ arr , $ n ) ; ? >
Area of a polygon with given n ordered vertices | ( X [ i ] , Y [ i ] ) are coordinates of i 'th point. ; Initialize area ; Calculate value of shoelace formula ; j is previous vertex to i ; Return absolute value ; Driver Code
< ? php function polygonArea ( $ X , $ Y , $ n ) { $ area = 0.0 ; $ j = $ n - 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ area += ( $ X [ $ j ] + $ X [ $ i ] ) * ( $ Y [ $ j ] - $ Y [ $ i ] ) ; $ j = $ i ; } return abs ( $ area / 2.0 ) ; } $ X = array ( 0 , 2 , 4 ) ; $ Y = array ( 1 , 3 , 7 ) ; $ n = sizeof ( $ X ) ; echo polygonArea ( $ X , $ Y , $ n ) ; ? >
Program to find the last digit of X in base Y | Function to find the last digit of X in base Y ; Driver code
< ? php function last_digit ( $ X , $ Y ) { echo ( $ X % $ Y ) ; } $ X = 55 ; $ Y = 3 ; last_digit ( $ X , $ Y ) ; ? >
Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula | Function to print the roots of the quadratic equation when a + b + c = 0 ; Driver code
< ? php function printRoots ( $ a , $ b , $ c ) { echo "1" ; echo " , ▁ " ; echo $ c / ( $ a * 1.0 ) ; } $ a = 2 ; $ b = 3 ; $ c = -5 ; printRoots ( $ a , $ b , $ c ) ; ? >
Quadruplet pair with XOR zero in the given Array | PHP implementation of the approach ; Function that returns true if the array contains a valid quadruplet pair ; We can always find a valid quadruplet pair for array size greater than MAX ; For smaller size arrays , perform brute force ; Driver code
< ? php const MAX = 130 ; function validQuadruple ( $ arr , $ n ) { if ( $ n >= MAX ) return true ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) for ( $ j = $ i + 1 ; $ j < $ n ; $ j ++ ) for ( $ k = $ j + 1 ; $ k < $ n ; $ k ++ ) for ( $ l = $ k + 1 ; $ l < $ n ; $ l ++ ) { if ( ( $ arr [ $ i ] ^ $ arr [ $ j ] ^ $ arr [ $ k ] ^ $ arr [ $ l ] ) == 0 ) { return true ; } } return false ; } $ arr = array ( 1 , 0 , 2 , 3 , 7 ) ; $ n = count ( $ arr ) ; if ( validQuadruple ( $ arr , $ n ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >
Check whether a number can be represented as sum of K distinct positive integers | Function that returns true if n can be represented as the sum of exactly k distinct positive integers ; If n can be represented as 1 + 2 + 3 + ... + ( k - 1 ) + ( k + x ) ; Driver code
< ? php function solve ( $ n , $ k ) { if ( $ n >= ( $ k * ( $ k + 1 ) ) / 2 ) { return true ; } return false ; } $ n = 12 ; $ k = 4 ; if ( solve ( $ n , $ k ) ) echo " Yes " ; else echo " No " ; ? >