codeparrot/xlcost-text-to-code huggingface dataset:
Check whether two straight lines are parallel or not | Function to check if two lines are parallel or not ; If slopes are equal ; Driver Code ; Function Call
function parallel ( a1 , b1 , c1 , a2 , b2 , c2 ) { if ( ( - ( a1 / b1 ) ) == ( - ( a2 / b2 ) ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let a1 = - 2 , b1 = 4 , c1 = 5 ; let a2 = - 6 , b2 = 12 , c2 = 6 ; parallel ( a1 , b1 , c1 , a2 , b2 , c2 ) ;
Calculate area and height of an isosceles triangle whose sides are radii of a circle | Function to convert given angle from degree to radian ; Function to calculate height and area of the triangle OAB ; Stores the angle OAB and OBA ; Stores the angle in radians ; Stores the height ; Print height of the triangle ; Stores the base of triangle OAB ; Stores the area of the triangle ; Print the area of triangle OAB ; Driver code
function Convert ( degree ) { var pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } function areaAndHeightOfTraingle ( radius , a ) { if ( a >= 180 a == 0 ) { document . write ( " " ) ; return ; } var base_angle = ( 180 - a ) / 2 ; var radians = Convert ( base_angle ) ; var height = Math . sin ( radians ) * radius ; document . write ( " " + height + " " ) ; var Base = Math . cos ( radians ) * radius ; var area = Base * height ; document . write ( " " + area ) ; } var R = 5 , angle = 120 ; areaAndHeightOfTraingle ( R , angle ) ;
Radius of a circle having area equal to the sum of area of the circles having given radii | Function to calculate radius of the circle having area equal to sum of the area of two circles with given radii ; Area of first circle ; Area of second circle ; Area of third circle ; Radius of third circle ; Given radius ; Prints the radius of the required circle
function findRadius ( r1 , r2 ) { let a1 , a2 , a3 , r3 ; a1 = 3.14 * r1 * r1 ; a2 = 3.14 * r2 * r2 ; a3 = a1 + a2 ; r3 = Math . sqrt ( a3 / 3.14 ) ; return r3 ; } let r1 = 8 , r2 = 6 ; document . write ( findRadius ( r1 , r2 ) ) ;
Minimum number of Cuboids required to form a Cube | Function to calculate and return LCM of a , b , and c ; Find GCD of a and b ; Find LCM of a and b ; LCM ( a , b , c ) = LCM ( LCM ( a , b ) , c ) ; Finding LCM of a , b , c ; return LCM ( a , b , c ) ; Function to find the minimum number of cuboids required to make the volume of a valid cube ; Find the LCM of L , B , H ; Volume of the cube ; Volume of the cuboid ; Minimum number cuboids required to form a cube ; Given dimensions of cuboid ; Function Call
function find_lcm ( a , b , c ) { let g = __gcd ( a , b ) ; let LCM1 = ( a * b ) / g ; g = __gcd ( LCM1 , c ) ; let LCM = ( LCM1 * c ) / g ; return LCM ; } function minimumCuboids ( L , B , H ) { let lcm = find_lcm ( L , B , H ) ; let volume_cube = lcm * lcm * lcm ; let volume_cuboid = L * B * H ; document . write ( ( volume_cube / volume_cuboid ) ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let L = 1 , B = 1 , H = 2 ; minimumCuboids ( L , B , H ) ;
Check if given polygon is a convex polygon or not | Utility function to find cross product of two vectors ; Stores coefficient of X direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 1 ] A [ 0 ] ; Stores coefficient of X direction of vector A [ 2 ] A [ 0 ] ; Stores coefficient of Y direction of vector A [ 2 ] A [ 0 ] ; Return cross product ; Function to check if the polygon is convex polygon or not ; Stores count of edges in polygon ; Stores direction of cross product of previous traversed edges ; Stores direction of cross product of current traversed edges ; Traverse the array ; Stores three adjacent edges of the polygon ; Update curr ; If curr is not equal to 0 ; If direction of cross product of all adjacent edges are not same ; Update curr ; Driver code
function CrossProduct ( A ) { var X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; var Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; var X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; var Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; return ( X1 * Y2 - Y1 * X2 ) ; } function isConvex ( points ) { var N = points . length ; var prev = 0 ; var curr = 0 ; for ( i = 0 ; i < N ; i ++ ) { var temp = [ points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] ] ; curr = CrossProduct ( temp ) ; if ( curr != 0 ) { if ( curr * prev < 0 ) { return false ; } else { prev = curr ; } } } return true ; } var points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ; if ( isConvex ( points ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Program to find all possible triangles having same Area and Perimeter | Function to print sides of all the triangles having same perimeter & area ; Stores unique sides of triangles ; i + j + k values cannot exceed 256 ; Find the value of 2 * s ; Find the value of 2 * ( s - a ) ; Find the value of 2 * ( s - b ) ; Find the value of 2 * ( s - c ) ; If triplets have same area and perimeter ; Store sides of triangle ; Sort the triplets ; Inserting in se to check avoid duplicate sides ; Print sides of all desired triangles ; Function call
const samePerimeterAndArea = ( ) => { let se = [ ] ; for ( let i = 1 ; i <= 256 ; ++ i ) { for ( let j = 1 ; j <= 256 ; ++ j ) { for ( let k = 1 ; k <= 256 ; ++ k ) { let peri = i + j + k ; let mul1 = - i + j + k ; let mul2 = i - j + k ; let mul3 = i + j - k ; if ( 16 * peri == mul1 * mul2 * mul3 ) { let v = [ i , j , k ] ; v . sort ( ( a , b ) => a - b ) ; let check = - 1 ; for ( let i = 0 ; i < se . length ; ++ i ) { if ( se [ i ] [ 0 ] == v [ 0 ] && se [ i ] [ 1 ] == v [ 1 ] && se [ i ] [ 2 ] == v [ 2 ] ) check = 1 ; } if ( check === - 1 ) se . push ( v ) ; } } } } for ( let it = 0 ; it < se . length ; ++ it ) { document . write ( ` ${ se [ it ] } ` ) ; } } samePerimeterAndArea ( ) ;
Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points | Function to get the count of ractangles ; Store distinct horizontal lines ; Store distinct Vertical lines ; Insert horizontal line passing through 0 ; Insert vertical line passing through 0. ; Insert horizontal line passing through rectangle [ 3 ] [ 0 ] ; Insert vertical line passing through rectangle [ 3 ] [ 1 ] ; Insert all horizontal and vertical lines passing through the given array ; Insert all horizontal lines ; Insert all vertical lines ; Driver Code
function cntRect ( points , N , rectangle ) { var cntHor = new Set ( ) ; var cntVer = new Set ( ) ; cntHor . add ( 0 ) ; cntVer . add ( 0 ) ; cntHor . add ( rectangle [ 3 ] [ 0 ] ) ; cntVer . add ( rectangle [ 3 ] [ 1 ] ) ; for ( var i = 0 ; i < N ; i ++ ) { cntHor . add ( points [ i ] [ 0 ] ) ; cntVer . add ( points [ i ] [ 1 ] ) ; } return ( cntHor . size - 1 ) * ( cntVer . size - 1 ) ; } var rectangle = [ [ 0 , 0 ] , [ 0 , 5 ] , [ 5 , 0 ] , [ 5 , 5 ] ] ; var points = [ [ 1 , 2 ] , [ 3 , 4 ] ] ; var N = points . length ; document . write ( cntRect ( points , N , rectangle ) ) ;
Count squares possible from M and N straight lines parallel to X and Y axis respectively | Function to count all the possible squares with given lines parallel to both the X and Y axis ; Stores the count of all possible distances in X [ ] & Y [ ] respectively ; Find distance between all pairs in the array X [ ] ; Add the count to m1 ; Find distance between all pairs in the array Y [ ] ; Add the count to m2 ; Find sum of m1 [ i ] * m2 [ i ] for same distance ; Find current count in m2 ; Add to the total count ; Return the final count ; Given lines ; Function Call
function numberOfSquares ( X , Y , N , M ) { var m1 = new Map ( ) , m2 = new Map ( ) ; var i , j , ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var dist = Math . abs ( X [ i ] - X [ j ] ) ; if ( m1 . has ( dist ) ) m1 . set ( dist , m1 . get ( dist ) + 1 ) else m1 . set ( dist , 1 ) ; } } for ( i = 0 ; i < M ; i ++ ) { for ( j = i + 1 ; j < M ; j ++ ) { var dist = Math . abs ( Y [ i ] - Y [ j ] ) ; if ( m2 . has ( dist ) ) m2 . set ( dist , m2 . get ( dist ) + 1 ) else m2 . set ( dist , 1 ) ; } } m1 . forEach ( ( value , key ) => { if ( m2 . has ( key ) ) { ans += ( value * m2 . get ( key ) ) ; } } ) ; return ans ; } var X = [ 1 , 3 , 7 ] ; var Y = [ 2 , 4 , 6 , 1 ] ; var N = X . length ; var M = Y . length ; document . write ( numberOfSquares ( X , Y , N , M ) ) ;
Program to calculate area of a parallelogram | Javascript program for the above approach ; Function to return the area of parallelogram using sides and angle at the intersection of diagonal ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using sides and angle at the intersection of sides ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using diagonals and angle at the intersection of diagonals ; Calculate area of parallelogram ; Return the answer ; Given diagonal and angle ; Function call ; Print the area
function toRadians ( degree ) { let pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } function Area_Parallelogram1 ( a , b , theta ) { let area = ( Math . abs ( Math . tan ( toRadians ( theta ) ) ) / 2 ) * Math . abs ( a * a - b * b ) ; return area ; } function Area_Parallelogram2 ( a , b , gamma ) { let area = ( Math . abs ( Math . sin ( toRadians ( gamma ) ) ) ) * Math . abs ( a * b ) ; return area ; } function Area_Parallelogram3 ( d1 , d2 , theta ) { let area = ( Math . abs ( Math . sin ( toRadians ( theta ) ) ) / 2 ) * Math . abs ( d1 * d2 ) ; return area ; } let d1 = 3 ; let d2 = 5 ; let theta = 90 ; let area = Area_Parallelogram3 ( d1 , d2 , theta ) ; document . write ( area ) ;
Count squares of size K inscribed in a square of size N | Function to calculate the number of squares of size K in a square of size N ; Stores the number of squares ; Size of the bigger square ; Size of smaller square
function No_of_squares ( N , K ) { let no_of_squares = 0 ; no_of_squares = ( N - K + 1 ) * ( N - K + 1 ) ; return no_of_squares ; } let N = 5 ; let K = 3 ; document . write ( No_of_squares ( N , K ) ) ;
Count cubes of size K inscribed in a cube of size N | Function to find the number of the cubes of the size K ; Stores the number of cubes ; Stores the number of cubes of size k ; Size of the bigger cube ; Size of the smaller cube
function No_of_cubes ( N , K ) { let No = 0 ; No = ( N - K + 1 ) ; No = Math . pow ( No , 3 ) ; return No ; } let N = 5 ; let K = 2 ; document . write ( No_of_cubes ( N , K ) ) ;
Count of smaller rectangles that can be placed inside a bigger rectangle | Function to count smaller rectangles within the larger rectangle ; If the dimension of the smaller rectangle is greater than the bigger one ; Return the number of smaller rectangles possible ; Dimension of bigger rectangle ; Dimension of smaller rectangle ; Function call
function No_of_rectangles ( L , B , l , b ) { if ( ( l > L ) || ( b > B ) ) { return - 1 ; } else { return ( L - l + 1 ) * ( B - b + 1 ) ; } } let L = 5 , B = 3 ; let l = 4 , b = 1 ; document . write ( No_of_rectangles ( L , B , l , b ) ) ;
Program To Check whether a Triangle is Equilateral , Isosceles or Scalene | Function to check if the triangle is equilateral or isosceles or scalene ; Check for equilateral triangle ; Check for isosceles triangle ; Otherwise scalene triangle ; Given sides of triangle ; Function call
function checkTriangle ( x , y , z ) { if ( x == y && y == z ) document . write ( " " ) ; else if ( x == y y == z z == x ) document . write ( " " ) ; else document . write ( " " ) ; } let x = 8 , y = 7 , z = 9 ; checkTriangle ( x , y , z ) ;
Find the remaining vertices of a square from two given vertices | Function to find the remaining vertices of a square ; Check if the x - coordinates are equal ; Check if the y - coordinates are equal ; If the the given coordinates forms a diagonal of the square ; Otherwise ; Square does not exist ; Given two vertices
function findVertices ( x1 , y1 , x2 , y2 ) { if ( x1 == x2 ) { document . write ( ( x1 + y2 - y1 ) + " " + y1 + " " ) ; document . write ( ( x2 + y2 - y1 ) + " " + y2 ) ; } else if ( y1 == y2 ) { document . write ( x1 + " " + ( y1 + x2 - x1 ) + " " ) ; document . write ( x2 + " " + ( y2 + x2 - x1 ) ) ; } else if ( Math . abs ( x2 - x1 ) === Math . abs ( y2 - y1 ) ) { document . write ( x1 + " " + y2 + " " ) ; document . write ( x2 + " " + y1 ) ; } else document . write ( " " ) ; } let x1 = 1 , y1 = 2 ; let x2 = 3 , y2 = 4 ; findVertices ( x1 , y1 , x2 , y2 ) ;
Find the area of rhombus from given Angle and Side length | Function to return the area of rhombus using one angle and side . ; Driver Code ; Function Call ; Print the final answer
function Area_of_Rhombus ( a , theta ) { var area = ( a ** 2 ) * Math . sin ( theta * Math . PI / 180 ) ; return area ; } a = 4 theta = 60 ans = Area_of_Rhombus ( a , theta ) document . write ( Math . round ( ans * 100 ) / 100 ) ;
Count of Equilateral Triangles of unit length possible from a given Hexagon | Function to calculate the the number of Triangles possible ; Regular Hexagon ; Irregular Hexagon
function calculateTriangles ( sides ) { let count = Math . pow ( sides [ 0 ] + sides [ 1 ] + sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 0 ] , 2 ) ; count -= Math . pow ( sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 4 ] , 2 ) ; return ( count ) ; } let sides = [ 1 , 1 , 1 , 1 , 1 , 1 ] ; document . write ( ( calculateTriangles ( sides ) ) + " " ) ; let sides1 = [ 2 , 2 , 1 , 3 , 1 , 2 ] ; document . write ( ( calculateTriangles ( sides1 ) ) + " " ) ;
Length of diagonal of a parallelogram using adjacent sides and angle between them | Function to return the length Of diagonal of a parallelogram using sides and angle between them . ; Given sides ; Given angle ; Function call ; Print the final answer
function Length_Diagonal ( a , b , theta ) { var diagonal = Math . sqrt ( ( Math . pow ( a , 2 ) + Math . pow ( b , 2 ) ) - 2 * a * b * Math . cos ( theta * ( Math . PI / 180 ) ) ) ; return diagonal ; } var a = 3 ; var b = 5 ; var theta = 45 ; var ans = Length_Diagonal ( a , b , theta ) ; document . write ( ans . toFixed ( 2 ) ) ;
Maximum number of tiles required to cover the floor of given size using 2 x1 size tiles | Function to find the maximum number of tiles required to cover the floor of size m x n using 2 x 1 size tiles ; Print the answer ; Given M and N ; Function call
function maximumTiles ( n , m ) { document . write ( ( m * n ) / 2 ) ; } let M = 3 ; let N = 4 ; maximumTiles ( N , M ) ;
Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal | Function to calculate the length of the diagonal of a parallelogram using two sides and other diagonal ; Driver Code ; Function Call ; Print the final answer
function Length_Diagonal ( a , b , d ) { let diagonal = Math . sqrt ( 2 * ( ( a * a ) + ( b * b ) ) - ( d * d ) ) ; return diagonal ; } let A = 10 ; let B = 30 ; let D = 20 ; let ans = Length_Diagonal ( A , B , D ) ; document . write ( ans . toFixed ( 1 ) ) ;
Length of Diagonals of a Cyclic Quadrilateral using the length of Sides . | Function to calculate the length of diagonals of a cyclic quadrilateral ; Driver Code ; Function Call ; Print the final answer
function Diagonals ( a , b , c , d ) { var p = parseFloat ( Math . sqrt ( ( ( a * c ) + ( b * d ) ) * ( ( a * d ) + ( b * c ) ) / ( ( a * b ) + ( c * d ) ) ) ) ; var q = parseFloat ( Math . sqrt ( ( ( a * c ) + ( b * d ) ) * ( ( a * b ) + ( c * d ) ) / ( ( a * d ) + ( b * c ) ) ) ) ; return [ p , q ] ; } var A = 10 ; var B = 15 ; var C = 20 ; var D = 25 ; var ans = Diagonals ( A , B , C , D ) document . write ( ans [ 0 ] . toFixed ( 2 ) + " " , ans [ 1 ] . toFixed ( 2 ) ) ;
Minimum Sum of Euclidean Distances to all given Points | Function to calculate Euclidean distance ; Function to calculate the minimum sum of the euclidean distances to all polets ; Calculate the centroid ; Calculate distance of all polets ; Initializing the points
function find ( x , y , p ) { let mind = 0 ; for ( let i = 0 ; i < p . length ; i ++ ) { let a = p [ i ] [ 0 ] , b = p [ i ] [ 1 ] ; mind += Math . sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) ) ; } return mind ; } function getMinDistSum ( p ) { let x = 0 , y = 0 ; for ( let i = 0 ; i < p . length ; i ++ ) { x += p [ i ] [ 0 ] ; y += p [ i ] [ 1 ] ; } x = x / p . length ; y = y / p . length ; let mind = find ( x , y , p ) ; return mind ; } let vec = [ [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] , [ 2 , 1 ] ] ; let d = getMinDistSum ( vec ) ; document . write ( d ) ;
Coplanarity of Two Lines in 3D Geometry | Function to generate determinant ; Return the sum ; Position vector of first line ; Direction ratios of line to which first line is parallel ; Position vectors of second line ; Direction ratios of line to which second line is parallel ; Determinant to check coplanarity ; If determinant is zero ; Otherwise
function det ( d ) { let Sum = d [ 0 ] [ 0 ] * ( ( d [ 1 ] [ 1 ] * d [ 2 ] [ 2 ] ) - ( d [ 2 ] [ 1 ] * d [ 1 ] [ 2 ] ) ) ; Sum -= d [ 0 ] [ 1 ] * ( ( d [ 1 ] [ 0 ] * d [ 2 ] [ 2 ] ) - ( d [ 1 ] [ 2 ] * d [ 2 ] [ 0 ] ) ) ; Sum += d [ 0 ] [ 2 ] * ( ( d [ 0 ] [ 1 ] * d [ 1 ] [ 2 ] ) - ( d [ 0 ] [ 2 ] * d [ 1 ] [ 1 ] ) ) ; return Sum ; } let x1 = - 3 , y1 = 1 , z1 = 5 ; let a1 = - 3 , b1 = 1 , c1 = 5 ; let x2 = - 1 , y2 = 2 , z2 = 5 ; let a2 = - 1 , b2 = 2 , c2 = 5 ; let det_list = [ [ x2 - x1 , y2 - y1 , z2 - z1 ] , [ a1 , b1 , c1 ] , [ a2 , b2 , c2 ] ] ; if ( det ( det_list ) == 0 ) document . write ( " " ) ; else document . write ( " " ) ;
Distance between Incenter and Circumcenter of a triangle using Inradius and Circumradius | Function returns the required distance ; Length of Inradius ; Length of Circumradius
function distance ( r , R ) { let d = Math . sqrt ( Math . pow ( R , 2 ) - ( 2 * r * R ) ) ; return d ; } let r = 2 ; let R = 5 ; document . write ( Math . round ( distance ( r , R ) * 100.0 ) / 100.0 ) ;
Check if an N | Function to check if the polygon exists or not ; Initialize a variable to store the sum of angles ; Loop through the array and calculate the sum of angles ; Check the condition for an N - side polygon ; Driver code ; Given array arr [ ] ; Function call
function checkValidPolygon ( arr , N ) { var sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 180 * ( N - 2 ) ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 3 ; var arr = [ 60 , 60 , 60 ] ; checkValidPolygon ( arr , N ) ;
Find side of Square which makes minimal area to fit two identical rectangles inside it | javascript program of the above approach ; If ' a ' and ' b ' same then var ' a ' or ' b ' and return ( 2 * a ) or ( 2 * b ) ; Check if a != b ; If a > b ; Double the smaller value that is ' b ' and store it to ' newB ' ; Find the difference of ' newB ▁ and ▁ ' a ' ; If ' newB ' < a ; Then add the difference of ' newB ' and ' a ' to the ' b ' to make ' b ' and ' a ' as same ; Return side of the square a or b ; If ' newB ' > a then then add the difference of ' newB ' and ' a ' to the ' a ' to make ' a ' and ' newB ' as same ; Return side of the square a or newB ; If a < b ; Double the smaller value that is ' a ' and store it to ' newA ' ; Find the difference of ' newA ▁ and ▁ ' b ' ; If ' newA ' < b ; Then add the difference of ' newA ' and ' b ' to the ' a ' to make ' a ' and ' b ' as same ; Return side of the square a or b ; If ' newA ' > b then then add the difference of ' newA ' and ' b ' to the ' b ' to make ' b ' and ' newA ' as same ; Return side of the square b or newA ; Driver code ; Size of rectangle
function minimalSquareSide ( a , b ) { if ( a == b ) { return 2 * a ; } if ( a != b ) { if ( a > b ) { var newB = b + b ; var diff = Math . abs ( newB - a ) ; if ( newB < a ) { b = newB + diff ; if ( a == b ) return a ; return 0 ; } else { a = a + diff ; if ( a == newB ) return a ; return 0 ; } } else { var newA = a + a ; var diff = Math . abs ( newA - b ) ; if ( newA < b ) { a = diff + newA ; if ( a == b ) return a ; return 0 ; } else { b = b + diff ; if ( b == newA ) return b ; return 0 ; } } } return 0 ; } var H , W ; H = 3 ; W = 1 ; document . write ( minimalSquareSide ( H , W ) ) ;
Find the angle of Rotational Symmetry of an N | Function to find required minimum angle of rotation ; Store the answer in a double variable ; Calculating the angle of rotation and type - casting the integer N to double type ; Driver code
function minAnglRot ( N ) { let res ; res = 360 / N ; return res ; } let N = 4 ; document . write ( " " + minAnglRot ( N ) ) ;
Area of a Triangle from the given lengths of medians | Function to return the area of triangle using medians ; Driver Code ; Function Call ; Prvar the final answer
function Area_of_Triangle ( a , b , c ) { var s = ( a + b + c ) / 2 ; var x = s * ( s - a ) ; x = x * ( s - b ) ; x = x * ( s - c ) ; var area = ( 4 / 3 ) * Math . sqrt ( x ) ; return area ; } var a = 9 ; var b = 12 ; var c = 15 ; var ans = Area_of_Triangle ( a , b , c ) ; document . write ( ans . toFixed ( 1 ) ) ;
Total number of unit cells covered by all given Rectangles | JavaScript program for the above approach ; Update the coordinates lying within the rectangle ; Update arr [ i ] [ j ] for all ( i , j ) lying within the rectangle ; Function to return the total area covered by rectangles ; Stores the number of cells ; arr [ i ] ] [ [ j ] == 1 means that grid is filled by some rectangle ; Driver Code ; ( A [ i ] [ 0 ] , A [ i ] [ 1 ] ) denotes the coordinate of the bottom left of the rectangle ( A [ i ] [ 2 ] , A [ i ] [ 3 ] ) denotes the coordinate of upper right of the rectangle ; Update the coordinates that lie within the rectangle
let MAX = 1001 ; let arr = new Array ( MAX ) ; for ( var i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new Array ( 2 ) ; } function updateArray ( x1 , y1 , x2 , y2 ) { for ( let i = x1 ; i < x2 ; i ++ ) { for ( let j = y1 ; j < y2 ; j ++ ) { arr [ i ] [ j ] = true ; } } } function findAreaCovered ( ) { let area = 0 ; for ( let i = 0 ; i < MAX ; i ++ ) { for ( let j = 0 ; j < MAX ; j ++ ) { if ( arr [ i ] [ j ] == true ) { area ++ ; } } } return area ; } let N = 3 ; let A = [ [ 1 , 3 , 4 , 5 ] , [ 3 , 1 , 7 , 4 ] , [ 5 , 3 , 8 , 6 ] ] ; for ( let i = 0 ; i < N ; i ++ ) { updateArray ( A [ i ] [ 0 ] , A [ i ] [ 1 ] , A [ i ] [ 2 ] , A [ i ] [ 3 ] ) ; } let area = findAreaCovered ( ) ; document . write ( area ) ;
Find the equation of plane which passes through two points and parallel to a given axis | javascript implementation to find the equation of plane which passes through two points and parallel to a given axis ; Find direction vector of points ( x1 , y1 , z1 ) and ( x2 , y2 , z2 ) ; Values that are calculated and simplified from the cross product ; Prvar the equation of plane ; Povar A ; Povar B ; Given axis ; Function Call
function findEquation ( x1 , y1 , z1 , x2 , y2 , z2 , d , e , f ) { var a = x2 - x1 ; var b = y2 - y1 ; var c = z2 - z1 ; var A = parseInt ( ( b * f - c * e ) ) ; var B = parseInt ( ( a * f - c * d ) ) ; var C = parseInt ( ( a * e - b * d ) ) ; var D = - parseInt ( ( A * d - B * e + C * f ) ) ; document . write ( A + " " + B + " " + C + " " + D + " " ) ; } var x1 = 2 , y1 = 3 , z1 = 5 ; var x2 = 6 , y2 = 7 , z2 = 8 ; var a = 11 , b = 23 , c = 10 ; findEquation ( x1 , y1 , z1 , x2 , y2 , z2 , a , b , c ) ;
Find the length of the median of a Triangle if length of sides are given | Function to return the length of the median using sides of triangle ; Driver Code ; Function call ; Print final answer with 2 digits after decimal
function median ( a , b , c ) { let n = ( Math . sqrt ( 2 * b * b + 2 * c * c - a * a ) / 2 ) ; return n ; } let a , b , c ; a = 4 ; b = 3 ; c = 5 ; let ans = median ( a , b , c ) ; document . write ( ans , 2 ) ;
Number of quadrilateral formed with N distinct points on circumference of Circle | Function to find the factorial of the given number N ; Loop to find the factorial of the given number ; Function to find the number of combinations in the N ; Driver Code ; Function Call
function fact ( n ) { let res = 1 ; for ( let i = 2 ; i < n + 1 ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return ( fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ) ; } let n = 5 ; document . write ( nCr ( n , 4 ) ) ;