codeparrot/xlcost-text-to-code huggingface dataset:
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
function checkEquilibrium ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) { var resx = x1 + x2 + x3 ; var resy = y1 + y2 + y3 ; var resz = z1 + z2 + z3 ; if ( resx == 0 & resy == 0 & resz == 0 ) return true ; else return false ; } var x1 = - 2 , y1 = - 7 , z1 = - 9 , x2 = 5 , y2 = - 14 , z2 = 14 , x3 = - 3 , y3 = 21 , z3 = - 5 ; if ( checkEquilibrium ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ) document . write ( " " ) ; else document . write ( " " ) ;
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 ; declare variable ; call function findTangent
function findTangent ( A , x , y ) { var dif = A - x * 2 ; if ( y == ( 2 * x - x * x ) ) { if ( dif < 0 ) document . write ( " " + dif + " " + ( x * dif + y ) + " " ) ; else if ( dif > 0 ) document . write ( " " + dif + " " + - x * dif + y + " " ) ; else document . write ( " " + " " ) ; } } var A = 2 , x = 2 , y = 0 ; findTangent ( A , x , y ) ;
Find length of Diagonal of Hexagon | Function to find the diagonal of the hexagon ; side cannot be negative ; diagonal of the hexagon ; Driver code
function hexadiagonal ( a ) { if ( a < 0 ) return - 1 ; return 2 * a ; } var a = 4 ; document . write ( hexadiagonal ( a ) ) ;
Program to find the side of the Octagon inscribed within the square | Function to find the side of the octagon ; side cannot be negative ; side of the octagon ; Get he square side ; Find the side length of the square
function octaside ( a ) { if ( a < 0 ) return - 1 ; var s = a / ( Math . sqrt ( 2 ) + 1 ) ; return s ; } var a = 4 ; document . write ( octaside ( a ) . toFixed ( 5 ) ) ;
Check whether it is possible to join two points given on circle such that distance between them is k | 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 will always be an integer ; Driver Code
function dis ( x1 , y1 , x2 , y2 ) { return Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; } function check ( c1 , c2 , k ) { let min = 0 ; let max = 0 ; let de = dis ( c1 [ 0 ] , c1 [ 1 ] , c2 [ 0 ] , c2 [ 1 ] ) ; if ( de == 0 ) { if ( c1 [ 2 ] == c2 [ 2 ] ) { min = 0 ; max = 0 ; } else if ( c1 [ 2 ] - c2 [ 2 ] > 0 ) { min = c1 [ 2 ] - c2 [ 2 ] ; max = min + 2 * c2 [ 2 ] ; } else { min = c2 [ 2 ] - c1 [ 2 ] ; max = min + 2 * c1 [ 2 ] ; } } else if ( de >= c1 [ 2 ] + c2 [ 2 ] ) { min = de - c1 [ 2 ] - c2 [ 2 ] ; max = de + c1 [ 2 ] + c2 [ 2 ] ; } else if ( de + c2 [ 2 ] < c1 [ 2 ] ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = c1 [ 2 ] - de - c2 [ 2 ] ; } else if ( de + c1 [ 2 ] < c2 [ 2 ] ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = c2 [ 2 ] - de - c1 [ 2 ] ; } else if ( ( de + c2 [ 2 ] >= c1 [ 2 ] ) || ( de + c1 [ 2 ] >= c2 [ 2 ] ) ) { max = c2 [ 2 ] + c1 [ 2 ] + de ; min = 0 ; } let temin = ( Math . ceil ( min ) ) ; let re = max ; if ( k >= temin && k <= re ) { return true ; } return false ; } let circle1 = [ 0 , 0 , 5 ] ; let circle2 = [ 8 , 3 , 2 ] ; let k = 3 ; if ( check ( circle1 , circle2 , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
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
function Arrive ( a , b , n ) { if ( n >= Math . abs ( a ) + Math . abs ( b ) && ( n - ( Math . abs ( a ) + Math . abs ( b ) ) ) % 2 == 0 ) return true ; return false ; } var a = 5 , b = 5 , n = 11 ; if ( Arrive ( a , b , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
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
function Move ( a , x , b ) { if ( ( ( ( b - a ) % x == 0 ) || ( ( b - a - 1 ) % x == 0 ) && a + 1 != b ) && b >= a ) return true ; return false ; } let a = 3 , x = 2 , b = 7 ; if ( Move ( a , x , b ) ) document . write ( " " ) ; else document . write ( " " ) ;
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
function area ( a , b ) { if ( a < 0 b < 0 ) return - 1 ; var A = a * b ; return A ; } var a = 5 , b = 2 ; document . write ( area ( a , b ) ) ;
Circumradius of the 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
function findRadiusOfcircumcircle ( l , b ) { if ( l < 0 b < 0 ) return - 1 ; var radius = Math . sqrt ( Math . pow ( l , 2 ) + Math . pow ( b , 2 ) ) / 2 ; return radius ; } var l = 4 , b = 3 ; document . write ( findRadiusOfcircumcircle ( l , b ) . toFixed ( 6 ) ) ;
Area of the circumcircle of any triangles with sides given | 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 prvar the area of the circumcircle
function circlearea ( a , b , c ) { if ( a < 0 b < 0 c < 0 ) return - 1 ; var p = ( a + b + c ) / 2 ; var At = Math . sqrt ( p * ( p - a ) * ( p - b ) * ( p - c ) ) ; var A = 3.14 * Math . pow ( ( ( a * b * c ) / ( 4 * At ) ) , 2 ) ; return A ; } var a = 4 , b = 5 , c = 3 ; document . write ( circlearea ( a , b , c ) ) ;
Find the altitude and area of an isosceles triangle | function to find the altitude ; return altitude ; function to find the area ; return area ; Driver code
function altitude ( a , b ) { return Math . sqrt ( Math . pow ( a , 2 ) - ( Math . pow ( b , 2 ) / 4 ) ) ; } function area ( b , h ) { return ( 1 * b * h ) / 2 ; } let a = 2 , b = 3 ; let h = altitude ( a , b ) ; document . write ( " " + h . toFixed ( 2 ) + " " ) ; document . write ( " " + area ( b , h ) . toFixed ( 2 ) ) ;
Program to find the surface area of the square pyramid | function to find the surface area ; Driver program ; surface area of the square pyramid
function surfaceArea ( b , s ) { return 2 * b * s + parseInt ( Math . pow ( b , 2 ) ) ; } var b = 3 , s = 4 ; document . write ( surfaceArea ( b , s ) ) ;
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
function trianglearea ( l , b ) { if ( l < 0 b < 0 ) return - 1 ; let area = ( l * b ) / 2 ; return area ; } let l = 5 , b = 4 ; document . write ( trianglearea ( l , b ) ) ;
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 ; initialize the size of the square ; initialize the dimension of the painted square
function halfsquare ( n , x , y ) { let half = n / 2 ; if ( ( half == x half == x - 1 ) && ( half == y half == y - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ; } let n = 100 ; let x = 51 , y = 100 ; halfsquare ( n , x , y ) ;
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 qua for all four quadrants ; Initialize all three vector coordinates
function _check ( a , b , p , q ) { var d = p * p + q * q ; if ( d == 0 ) return a == 0 && b == 0 ; else return ( a * p + b * q ) % d == 0 && ( b * p - a * q ) % d == 0 ; } function check ( a , b , x , y , p , q ) { if ( _check ( a - x , b - y , p , q ) || _check ( a + x , b + y , p , q ) || _check ( a - y , b + x , p , q ) || _check ( a + y , b - x , p , q ) ) return true ; else return false ; } var a = - 4 , b = - 2 ; var x = 0 , y = 0 ; var p = - 2 , q = - 1 ; if ( check ( a , b , x , y , p , q ) ) document . write ( " " ) ; else document . write ( " " ) ;
Largest triangle that can be inscribed in an ellipse | Function to find the area of the triangle ; a and b cannot be negative ; area of the triangle ; Driver code
function trianglearea ( a , b ) { if ( a < 0 b < 0 ) return - 1 ; var area = ( 3 * Math . sqrt ( 3 ) * Math . pow ( a , 2 ) ) / ( 4 * b ) ; return area ; } var a = 4 , b = 2 ; document . write ( trianglearea ( a , b ) . toFixed ( 4 ) ) ;
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
function squarearea ( a , b ) { if ( a < 0 b < 0 ) return - 1 ; var area = 4 * ( ( Math . pow ( a , 2 ) + Math . pow ( b , 2 ) ) / ( Math . pow ( a , 2 ) * Math . pow ( b , 2 ) ) ) ; return area ; } var a = 4 , b = 2 ; document . write ( squarearea ( a , b ) ) ;
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
function trianglearea ( r ) { if ( r < 0 ) return - 1 ; return r * r ; } var r = 5 ; document . write ( trianglearea ( r ) ) ;
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
function squarearea ( r ) { if ( r < 0 ) return - 1 ; var a = 4 * ( Math . pow ( r , 2 ) / 5 ) ; return a ; } var r = 5 ; document . write ( squarearea ( r ) ) ;
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
function rectanglearea ( a , b ) { if ( a < 0 b < 0 ) return - 1 ; return 2 * a * b ; } var a = 10 , b = 8 ; document . write ( rectanglearea ( a , b ) ) ;
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
function squareArea ( l , b , h ) { if ( l < 0 b < 0 h < 0 ) return - 1 ; var a = ( l * b ) / ( l + b ) ; return a * a ; } var l = 5 , b = 12 , h = 13 ; document . write ( squareArea ( l , b , h ) . toFixed ( 4 ) ) ;
Queries to check if it is possible to join boxes in a circle | Javascript 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
var MAX = 50 function solveQuery ( n , q , qi , qj ) { var arr = Array ( MAX ) ; for ( var i = 0 ; i <= n ; i ++ ) arr [ i ] = 0 ; for ( var k = 0 ; k < q ; k ++ ) { var flag = 0 ; if ( qj [ k ] < qi [ k ] ) { var temp = qi [ k ] ; qi [ k ] = qj [ k ] ; qj [ k ] = temp ; } if ( arr [ qi [ k ] ] != 0 arr [ qj [ k ] ] != 0 ) flag = 1 ; else if ( qi [ k ] == qj [ k ] ) flag = 1 ; else { for ( var i = 1 ; i < qi [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] < qj [ k ] && qi [ k ] < arr [ i ] ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( var i = qi [ k ] + 1 ; i < qj [ k ] ; i ++ ) { if ( arr [ i ] != 0 && arr [ i ] > qj [ k ] ) { flag = 1 ; break ; } } } } if ( flag == 0 ) { document . write ( " " ) ; arr [ qi [ k ] ] = qj [ k ] ; arr [ qj [ k ] ] = qi [ k ] ; } else document . write ( " " ) ; } } var n = 10 ; var q = 7 ; var qi = [ 1 , 2 , 2 , 2 , 9 , 10 , 8 ] ; var qj = [ 5 , 7 , 3 , 4 , 9 , 9 , 6 ] ; solveQuery ( n , q , qi , qj ) ;
Minimum squares to cover a rectangle | javascript 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
function squares ( l , b , a ) { return parseInt ( Math . ceil ( l / a ) * Math . ceil ( b / a ) ) ; } var l = 11 , b = 23 , a = 14 ; document . write ( squares ( l , b , a ) ) ;
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
function gcd ( a , b ) { if ( a == 0 b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } function squarearea ( l , b ) { if ( l < 0 b < 0 ) return - 1 ; var n = ( l * b ) / gcd ( l , b ) ; return n * n ; } var l = 6 , b = 4 ; document . write ( squarearea ( l , b ) ) ;
Find all angles of a triangle in 3D | function for finding the angle ; Driver code
function angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) { let num = ( x2 - x1 ) * ( x3 - x1 ) + ( y2 - y1 ) * ( y3 - y1 ) + ( z2 - z1 ) * ( z3 - z1 ) ; let den = Math . sqrt ( Math . pow ( ( x2 - x1 ) , 2 ) + Math . pow ( ( y2 - y1 ) , 2 ) + Math . pow ( ( z2 - z1 ) , 2 ) ) * Math . sqrt ( Math . pow ( ( x3 - x1 ) , 2 ) + Math . pow ( ( y3 - y1 ) , 2 ) + Math . pow ( ( z3 - z1 ) , 2 ) ) ; let angle = Math . acos ( num / den ) * ( 180.0 / 3.141592653589793238463 ) ; return angle ; } let x1 = - 1 ; let y1 = 3 ; let z1 = 2 ; let x2 = 2 ; let y2 = 3 ; let z2 = 5 ; let x3 = 3 ; let y3 = 5 ; let z3 = - 2 ; let angle_A = angle_triangle ( x1 , x2 , x3 , y1 , y2 , y3 , z1 , z2 , z3 ) ; let angle_B = angle_triangle ( x2 , x3 , x1 , y2 , y3 , y1 , z2 , z3 , z1 ) ; let angle_C = angle_triangle ( x3 , x2 , x1 , y3 , y2 , y1 , z3 , z2 , z1 ) ; document . write ( " " ) ; document . write ( " " + angle_A + " " ) ; document . write ( " " + angle_B . toFixed ( 3 ) + " " ) ; document . write ( " " + angle_C . toFixed ( 3 ) + " " ) ;
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
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 parseInt ( M * N ) ; } var N = 12 , M = 13 , s = 4 ; document . write ( 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
function solve ( M , N , s ) { let ans = Math . floor ( ( ( Math . ceil ( M / s ) ) * ( Math . ceil ( N / s ) ) ) ) ; return ans ; } let N = 12 , M = 13 , s = 4 ; document . write ( solve ( M , N , s ) ) ;
Program to find equation of a plane passing through 3 points | Function to find equation of plane . ; Driver code
function equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) { var a1 = x2 - x1 ; var b1 = y2 - y1 ; var c1 = z2 - z1 ; var a2 = x3 - x1 ; var b2 = y3 - y1 ; var c2 = z3 - z1 ; var a = b1 * c2 - b2 * c1 ; var b = a2 * c1 - a1 * c2 ; var c = a1 * b2 - b1 * a2 ; var d = ( - a * x1 - b * y1 - c * z1 ) ; document . write ( " " + a + " " + b + " " + c + " " + d + " " ) ; } var x1 = - 1 ; var y1 = 2 ; var z1 = 1 ; var x2 = 0 ; var y2 = - 3 ; var z2 = 2 ; var x3 = 1 ; var y3 = 1 ; var 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
function shortest_distance ( x1 , y1 , a , b , c ) { var d = Math . abs ( ( ( a * x1 + b * y1 + c ) ) / ( Math . sqrt ( a * a + b * b ) ) ) ; document . write ( " " + " " + d . toFixed ( 11 ) ) ; return ; } var x1 = 5 ; var y1 = 6 ; var a = - 2 ; var b = 3 ; var c = 4 ; shortest_distance ( x1 , y1 , a , b , c ) ;
Program to determine the octant of the axial plane | Function to print octant ; driver code
function octant ( x , y , z ) { if ( x >= 0 && y >= 0 && z >= 0 ) document . write ( " " + " " ) ; else if ( x < 0 && y >= 0 && z >= 0 ) document . write ( " " + " " ) ; else if ( x < 0 && y < 0 && z >= 0 ) document . write ( " " + " " ) ; else if ( x >= 0 && y < 0 && z >= 0 ) document . write ( " " + " " ) ; else if ( x >= 0 && y >= 0 && z < 0 ) document . write ( " " + " " ) ; else if ( x < 0 && y >= 0 && z < 0 ) document . write ( " " + " " ) ; else if ( x < 0 && y < 0 && z < 0 ) document . write ( " " + " " ) ; else if ( x >= 0 && y < 0 && z < 0 ) document . write ( " " + " " ) ; } let 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 triangle nC3 = n * ( n - 1 ) * ( n - 2 ) / 6 ; Driver code
function countNumberOfTriangles ( n ) { return n * ( n - 1 ) * ( n - 2 ) / 6 ; } var n = 4 ; document . write ( countNumberOfTriangles ( n ) ) ;
Centered Dodecagonal Number | Function to calculate Centered Dodecagonal number ; Formula to calculate nth centered Dodecagonal number ; Driver Code
function centeredDodecagonal ( n ) { return 6 * n * ( n - 1 ) + 1 ; } let n = 2 ; document . write ( centeredDodecagonal ( n ) ) ; document . write ( " " ) ; n = 9 ; document . write ( centeredDodecagonal ( n ) ) ;
Centered tridecagonal number | Function to find nth centered tridecagonal number ; Formula to calculate nth centered tridecagonal number ; Driver code
function centeredTridecagonalNum ( n ) { return ( 13 * n * ( n - 1 ) + 2 ) / 2 ; } var n = 3 ; document . write ( centeredTridecagonalNum ( n ) + " " ) ; n = 10 ; document . write ( 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
function pentagon_pyramidal ( n ) { var sum = 0 ; for ( i = 1 ; i <= n ; i ++ ) { var p = ( 3 * i * i - i ) / 2 ; sum = sum + p ; } return sum ; } var n = 4 ; document . write ( pentagon_pyramidal ( n ) ) ;
Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Driver Code
function pentagon_pyramidal ( n ) { return n * n * ( n + 1 ) / 2 ; } var n = 4 ; document . write ( pentagon_pyramidal ( n ) ) ;
Check if three straight lines are concurrent or not | Return true if three line are concurrent , else false . ; Driven Program
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 ; ( checkConcurrent ( a1 , b1 , c1 , a2 , b2 , c2 , a3 , b3 , c3 ) ? ( document . write ( " " ) ) : ( document . write ( " " ) ) ) ;
Centered Octadecagonal Number | centered octadecagon function ; Formula to calculate nth centered octadecagonal number ; Driver Code
function center_octadecagon_num ( n ) { return 9 * n * n - 9 * n + 1 ; } var n = 3 ; document . write ( n + " " + " " ) ; document . write ( center_octadecagon_num ( n ) + " " ) ; n = 13 ; document . write ( n + " " + " " ) ; document . write ( 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
function centereddecagonalnum ( n ) { return ( 5 * n * n + 5 * n + 1 ) ; } var n = 5 ; document . write ( n + " " + " " ) ; document . write ( centereddecagonalnum ( n ) + " " ) ; n = 9 ; document . write ( n + " " + " " ) ; document . write ( 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 . ; Driven Program
function factorial ( a , b ) { var res = 1 ; for ( var i = 1 ; i <= ( a + b ) ; i ++ ) res = res * i ; for ( var i = 1 ; i <= a ; i ++ ) res = res / i ; for ( var 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 -- ; document . write ( " " ) ; Ksmallest ( x , y , k ) ; } else if ( y == 0 ) { x -- ; document . write ( " " ) ; Ksmallest ( x , y , k ) ; } else { if ( factorial ( x - 1 , y ) > k ) { document . write ( " " ) ; Ksmallest ( x - 1 , y , k ) ; } else { document . write ( " " ) ; Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) ; } } } var 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
function centered_pentagonal_Num ( n ) { return ( 5 * n * n - 5 * n + 2 ) / 2 ; } var n = 7 ; document . write ( n + " " + " " ) ; document . write ( 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
function pivotDis ( x0 , y0 , x1 , y1 ) { return Math . sqrt ( ( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) ) ; } function minDis ( D , r1 , r2 ) { return Math . max ( ( D - r1 - r2 ) , 0 ) ; } function maxDis ( D , r1 , r2 ) { return D + r1 + r2 ; } let x0 = 0 , y0 = 0 , x1 = 8 , y1 = 0 , r1 = 4 , r2 = 5 ; let D = pivotDis ( x0 , y0 , x1 , y1 ) ; document . write ( " " + maxDis ( D , r1 , r2 ) + " " ) ; document . write ( " " + 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 ; Driver code
function maximumValueOfF ( R ) { return 4 * R * R + 0.25 ; } var R = 3 ; document . write ( maximumValueOfF ( R ) ) ;
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 ; Driver code
function otherEndPoint ( x1 , y1 , m1 , m2 ) { let x2 = 2 * m1 - x1 ; let y2 = 2 * m2 - y1 ; document . write ( " " + x2 + " " + " " + y2 ) ; } let 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 program
function printRect ( X , Y , n ) { var Xmax = X . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var Xmin = X . reduce ( ( a , b ) => Math . min ( a , b ) ) ; var Ymax = Y . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var Ymin = Y . reduce ( ( a , b ) => Math . min ( a , b ) ) ; document . write ( " " + Xmin + " " + Ymin + " " + " " ) ; document . write ( " " + Xmin + " " + Ymax + " " + " " ) ; document . write ( " " + Xmax + " " + Ymax + " " + " " ) ; document . write ( " " + Xmax + " " + Ymin + " " + " " ) ; } var X = [ 4 , 3 , 6 , 1 , - 1 , 12 ] ; var Y = [ 4 , 1 , 10 , 3 , 7 , - 1 ] ; var n = X . length ; printRect ( X , Y , n ) ;