codeparrot/xlcost-text-to-code huggingface dataset:
Check if a right | Function to check if right - angled triangle can be formed by the given coordinates ; Calculate the sides ; Check Pythagoras Formula ; Driver Code
function checkRightAngled ( X1 , Y1 , X2 , Y2 , X3 , Y3 ) { var A = Math . pow ( X2 - X1 , 2 ) + Math . pow ( Y2 - Y1 , 2 ) ; var B = Math . pow ( X3 - X2 , 2 ) + Math . pow ( Y3 - Y2 , 2 ) ; var C = Math . pow ( X3 - X1 , 2 ) + Math . pow ( Y3 - Y1 , 2 ) ; if ( A > 0 && B > 0 && C > 0 && ( A === B + C B === A + C C === A + B ) ) document . write ( " " ) ; else document . write ( " " ) ; } var X1 = 0 , Y1 = 2 ; var X2 = 0 , Y2 = 14 ; var X3 = 9 , Y3 = 2 ; checkRightAngled ( X1 , Y1 , X2 , Y2 , X3 , Y3 ) ;
Count of intersections of M line segments with N vertical lines in XY plane | Function to create prefix sum array ; Initialize the prefix array to remove garbage values ; Marking the occurences of vertical lines ; x is the value after Index mapping ; Creating the prefix array ; Function returns the count of total letersection ; ans is the number of polets of letersection of the line segments with the vertical lines ; Index mapping ; We don 't consider a vertical  line segment because even if  it falls on a verticale line  then it just touches it and  not letersects. ; We have assumed that x1 will be left and x2 right but if not then we just swap them ; N is the number of vertical lines M is the number of line segments ; Format : x1 , y1 , x2 , y1 ; First create the prefix array ; Prlet the total number of letersections
function createPrefixArray ( n , arr , prefSize , pref ) { for ( let i = 0 ; i < prefSize ; i ++ ) { pref [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let x = arr [ i ] + 1000000 ; pref [ x ] ++ ; } for ( let i = 1 ; i < prefSize ; i ++ ) { pref [ i ] += pref [ i - 1 ] ; } } function poletsOfLetersection ( m , segments , size , pref ) { let ans = 0 ; for ( let i = 0 ; i < m ; i ++ ) { let x1 = segments [ i ] [ 0 ] ; let x2 = segments [ i ] [ 2 ] ; x1 = x1 + 1000000 ; x2 = x2 + 1000000 ; if ( x1 != x2 ) { if ( x1 > x2 ) { let temp = x1 ; x1 = x2 ; x2 = temp ; } let Occ_Till_Right = pref [ x2 - 1 ] ; let Occ_Till_Left = pref [ x1 ] ; ans = ans + ( Occ_Till_Right - Occ_Till_Left ) ; } } return ans ; } let N = 4 ; let M = 8 ; let size = 2000000 + 2 ; let pref = Array . from ( { length : size } , ( _ , i ) => 0 ) ; let lines = [ - 5 , - 3 , 2 , 3 ] ; let segments = [ [ - 2 , 5 , 5 , - 6 ] , [ - 5 , - 2 , - 3 , - 5 ] , [ - 2 , 3 , - 6 , 1 ] , [ - 1 , - 3 , 4 , 2 ] , [ 2 , 5 , 2 , 1 ] , [ 4 , 5 , 4 , - 5 ] , [ - 2 , - 4 , 5 , 3 ] , [ 1 , 2 , - 2 , 1 ] ] ; createPrefixArray ( N , lines , size , pref ) ; document . write ( poletsOfLetersection ( M , segments , size , pref ) + " " ) ;
Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively | Function to calculate number of rectangles ; Total number of ways to select two lines parallel to X axis ; Total number of ways to select two lines parallel to Y axis ; Total number of rectangles ; Driver Code
function count_rectangles ( N , M ) { let p_x = ( N * ( N - 1 ) ) / 2 ; let p_y = ( M * ( M - 1 ) ) / 2 ; return p_x * p_y ; } let N = 3 ; let M = 6 ; document . write ( count_rectangles ( N , M ) ) ;
Angle between a Pair of Lines in 3D | Javascript program for the above approach ; Function to find the angle between the two lines ; Find direction ratio of line AB ; Find direction ratio of line BC ; Find the dotProduct of lines AB & BC ; Find magnitude of line AB and BC ; Find the cosine of the angle formed by line AB and BC ; Find angle in radian ; Prvar the angle ; Given coordinates Povars A ; Povars B ; Povars C ; Function Call
var PI = 3.14 ; function calculateAngle ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) { var ABx = x1 - x2 ; var ABy = y1 - y2 ; var ABz = z1 - z2 ; var BCx = x3 - x2 ; var BCy = y3 - y2 ; var BCz = z3 - z2 ; var dotProduct = ABx * BCx + ABy * BCy + ABz * BCz ; var magnitudeAB = ABx * ABx + ABy * ABy + ABz * ABz ; var magnitudeBC = BCx * BCx + BCy * BCy + BCz * BCz ; var angle = dotProduct ; angle /= Math . sqrt ( magnitudeAB * magnitudeBC ) ; angle = ( angle * 180 ) / PI ; document . write ( Math . abs ( angle ) . toFixed ( 4 ) ) ; } var x1 = 1 , y1 = 3 , z1 = 3 ; var x2 = 3 , y2 = 4 , z2 = 5 ; var x3 = 5 , y3 = 6 , z3 = 9 ; calculateAngle ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 ) ;
Distance between end points of Hour and minute hand at given time | Function to find the angle between Hour hand and minute hand ; Validate the input ; Calculate the angles moved by hour and minute hands with reference to 12 : 00 ; Find the difference between two angles ; Return the smaller angle of two possible angles ; Function to calculate cos value of angle c ; Converting degrees to radian ; Maps the sum along the series ; Holds the actual value of sin ( n ) ; Function to distance between the endpoints of the hour and minute hand ; Time ; Length of hour hand ; Length of minute hand ; calling Function for finding angle between hour hand and minute hand ; Function for finding distance between end points of minute hand and hour hand
function calcAngle ( h , m ) { if ( h < 0 m < 0 h > 12 m > 60 ) document . write ( " " ) ; if ( h == 12 ) h = 0 ; if ( m == 60 ) m = 0 ; var hour_angle = 0.5 * ( h * 60 + m ) ; var minute_angle = 6 * m ; var angle = Math . abs ( hour_angle - minute_angle ) ; angle = Math . min ( 360 - angle , angle ) ; return angle ; } function cal_cos ( n ) { var accuracy = 0.0001 , x1 , denominator , cosx , cosval ; n = n * ( 3.142 / 180.0 ) ; x1 = 1 ; cosx = x1 ; cosval = Math . cos ( n ) ; var i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= Math . abs ( cosval - cosx ) ) ; return cosx ; } function distanceEndpoints ( a , b , c ) { var angle = cal_cos ( c ) ; return Math . sqrt ( ( a * a ) + ( b * b ) - 2 * a * b * angle ) ; } var hour = 3 ; var min = 30 ; var hourHand = 3 ; var minHand = 4 ; var angle = calcAngle ( hour , min ) ; var distance = distanceEndpoints ( minHand , hourHand , angle ) ; document . write ( distance . toFixed ( 5 ) ) ;
Pentadecagonal Number | Function to find N - th Pentadecagonal number ; Formula to calculate nth Pentadecagonal number ; Driver code
function Pentadecagonal_num ( n ) { return ( 13 * n * n - 11 * n ) / 2 ; } let n = 3 ; document . write ( Pentadecagonal_num ( n ) + " " ) ; n = 10 ; document . write ( Pentadecagonal_num ( n ) ) ;
Octadecagonal Number | Function to find N - th Octadecagonal number ; Formula to calculate nth Octadecagonal number ; Driver code
function Octadecagonal_num ( n ) { return ( 16 * n * n - 14 * n ) / 2 ; } let n = 3 ; document . write ( Octadecagonal_num ( n ) + " " ) ; n = 10 ; document . write ( Octadecagonal_num ( n ) ) ;
Icositrigonal Number | Function to find N - th Icositrigonal number ; Formula to calculate nth Icositrigonal number ; Driver code
function Icositrigonal_num ( n ) { return ( 21 * n * n - 19 * n ) / 2 ; } let n = 3 ; document . write ( Icositrigonal_num ( n ) + " " ) ; n = 10 ; document . write ( Icositrigonal_num ( n ) ) ;
Minimum number of Circular obstacles required to obstruct the path in a Grid | Function to find the minimum number of obstacles required ; Find the minimum range required to put obstacles ; Sorting the radius ; If val is less than zero then we have find the number of obstacles required ; Driver function
function solve ( n , m , obstacles , range ) { var val = Math . min ( n , m ) ; range . sort ( ( a , b ) => a - b ) var c = 1 ; for ( var i = obstacles - 1 ; i >= 0 ; i -- ) { range [ i ] = 2 * range [ i ] ; val -= range [ i ] ; if ( val <= 0 ) { return c ; } else { c ++ ; } } if ( val > 0 ) { return - 1 ; } } var n = 4 , m = 5 , obstacles = 3 ; var range = [ 1.0 , 1.25 , 1.15 ] ; document . write ( solve ( n , m , obstacles , range ) + " " ) ;
Program to calculate area of a rhombus whose one side and diagonal are given | function to calculate the area of the rhombus ; Second diagonal ; area of rhombus ; return the area ; Driver code
function area ( d1 , a ) { var d2 = Math . sqrt ( 4 * ( a * a ) - d1 * d1 ) ; var area = 0.5 * d1 * d2 ; return area ; } var d = 7.07 ; var a = 5 ; document . write ( area ( d , a ) ) ;
Check whether two points ( x1 , y1 ) and ( x2 , y2 ) lie on same side of a given line or not | Function to check if two points lie on the same side or not ; let fx1 ; Variable to store a * x1 + b * y1 - c let fx2 ; Variable to store a * x2 + b * y2 - c ; If fx1 and fx2 have same sign ; Driver code
function pointsAreOnSameSideOfLine ( a , b , c , x1 , y1 , x2 , y2 ) { fx1 = a * x1 + b * y1 - c ; fx2 = a * x2 + b * y2 - c ; if ( ( fx1 * fx2 ) > 0 ) return true ; return false ; } let a = 1 , b = 1 , c = 1 ; let x1 = 1 , y1 = 1 ; let x2 = 2 , y2 = 1 ; if ( pointsAreOnSameSideOfLine ( a , b , c , x1 , y1 , x2 , y2 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Percentage increase in volume of the cube if a side of cube is increased by a given percentage | javascript program to find percentage increase in the volume of the cube if a side of cube is increased by a given percentage ; Driver code
function newvol ( x ) { document . write ( " " + " " + ( Math . pow ( x , 3 ) / 10000 + 3 * x + ( 3 * Math . pow ( x , 2 ) ) / 100 ) + " " ) ; } let x = 10 ; newvol ( x ) ;
Number of triangles formed by joining vertices of n | Function to find the number of triangles ; print the number of triangles having two side common ; print the number of triangles having no side common ; initialize the number of sides of a polygon
function findTriangles ( n ) { var num = n ; document . write ( num + " " ) ; document . write ( num * ( num - 4 ) * ( num - 5 ) / 6 ) ; } var n ; n = 6 ; findTriangles ( n ) ;
Find the radii of the circles which are lined in a row , and distance between the centers of first and last circle is given | javascript program to find radii of the circles which are lined in a row and distance between the centers of first and last circle is given ; Driver code
function radius ( n , d ) { document . write ( " " + d / ( 2 * n - 2 ) ) ; } var d = 42 , n = 4 ; radius ( n , d ) ;
Find the side of the squares which are lined in a row , and distance between the centers of first and last square is given | javascript program to find side of the squares which are lined in a row and distance between the centers of first and last squares is given ; Driver code
function radius ( n , d ) { document . write ( " " + d / ( n - 1 ) ) ; } var d = 42 , n = 4 ; radius ( n , d ) ;
Number of triangles formed by joining vertices of n | Function to find the number of triangles ; print the number of triangles ; initialize the number of sides of a polygon
function findTriangles ( n ) { var num ; num = n * ( n - 4 ) ; document . write ( num ) ; } var n ; n = 6 ; findTriangles ( n ) ;
Find the Diameter or Longest chord of a Circle | Function to find the longest chord ; Get the radius ; Find the diameter
function diameter ( r ) { document . write ( " " + " " + 2 * r ) ; } var r = 4 ; diameter ( r ) ;
Slope of the line parallel to the line with the given slope | Function to return the slope of the line which is parallel to the line with the given slope ; Driver code
function getSlope ( m ) { return m ; } var m = 2 ; document . write ( getSlope ( m ) ) ;
Total number of triangles formed when there are H horizontal and V vertical lines | Function to return total triangles ; Only possible triangle is the given triangle ; If only vertical lines are present ; If only horizontal lines are present ; Return total triangles ; Driver code
function totalTriangles ( h , v ) { if ( h == 0 && v == 0 ) return 1 ; if ( h == 0 ) return ( ( v + 1 ) * ( v + 2 ) / 2 ) ; if ( v == 0 ) return ( h + 1 ) ; var total = ( h + 1 ) * ( ( v + 1 ) * ( v + 2 ) / 2 ) ; return total ; } var h = 2 , v = 2 ; document . write ( totalTriangles ( h , v ) ) ;
Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum | Function to find the biggest sphere ; the radii and height cannot be negative ; radius of the sphere ; volume of the sphere ; Driver code
function sph ( r , R , h ) { if ( r < 0 && R < 0 && h < 0 ) return - 1 ; var x = r ; var V = ( ( 4 * 3.14 * Math . pow ( r , 3 ) ) / 3 ) ; return V ; } var r = 5 , R = 8 , h = 11 ; document . write ( sph ( r , R , h ) . toFixed ( 5 ) ) ;
Check whether two straight lines are orthogonal or not | Function to check if two straight lines are orthogonal or not ; Both lines have infinite slope ; Only line 1 has infinite slope ; Only line 2 has infinite slope ; Find slopes of the lines ; Check if their product is - 1 ; Driver code
function checkOrtho ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) { let m1 , m2 ; if ( x2 - x1 == 0 && x4 - x3 == 0 ) return false ; else if ( x2 - x1 == 0 ) { m2 = parseInt ( ( y4 - y3 ) / ( x4 - x3 ) , 10 ) ; if ( m2 == 0 ) return true ; else return false ; } else if ( x4 - x3 == 0 ) { m1 = parseInt ( ( y2 - y1 ) / ( x2 - x1 ) , 10 ) ; if ( m1 == 0 ) return true ; else return false ; } else { m1 = parseInt ( ( y2 - y1 ) / ( x2 - x1 ) , 10 ) ; m2 = parseInt ( ( y4 - y3 ) / ( x4 - x3 ) , 10 ) ; if ( m1 * m2 == - 1 ) return true ; else return false ; } } let x1 = 0 , y1 = 4 , x2 = 0 , y2 = - 9 ; let x3 = 2 , y3 = 0 , x4 = - 1 , y4 = 0 ; if ( checkOrtho ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) == true ) document . write ( " " ) ; else document . write ( " " ) ;
Diagonal of a Regular Pentagon | Function to find the diagonal of a regular pentagon ; Side cannot be negative ; Length of the diagonal ; Driver code
function pentdiagonal ( a ) { if ( a < 0 ) return - 1 ; let d = 1.22 * a ; return d ; } let a = 6 ; document . write ( pentdiagonal ( a ) ) ;
Area of hexagon with given diagonal length | Function to calculate area ; Formula to find area ; Driver Code
function hexagonArea ( d ) { return ( 3 * Math . sqrt ( 3 ) * Math . pow ( d , 2 ) ) / 8 ; } let d = 10 ; document . write ( " " + hexagonArea ( d ) . toFixed ( 3 ) ) ;
Number of squares of side length required to cover an N * M rectangle | function to find a number of squares of a * a required to cover n * m rectangle ; Driver code ; Function call
function Squares ( n , m , a ) { return parseInt ( ( ( m + a - 1 ) / a ) ) * parseInt ( ( ( n + a - 1 ) / a ) ) ; } var n = 6 , m = 6 , a = 4 ; document . write ( Squares ( n , m , a ) ) ;
Length of the Diagonal of the Octagon | Function to find the diagonal of the octagon ; side cannot be negative ; diagonal of the octagon ; Driver code
function octadiagonal ( a ) { if ( a < 0 ) return - 1 ; return a * Math . sqrt ( 4 + ( 2 * Math . sqrt ( 2 ) ) ) ; } var a = 4 ; document . write ( octadiagonal ( a ) . toFixed ( 5 ) ) ;
Program to Calculate the Perimeter of a Decagon | Function for finding the perimeter ; Driver code
function CalPeri ( ) { var S = 5 , Perimeter ; Perimeter = 10 * S ; document . write ( " " + Perimeter ) ; } CalPeri ( ) ;
Sum of lengths of all 12 edges of any rectangular parallelepiped | function to find the sum of all the edges of parallelepiped ; to calculate the length of one edge ; sum of all the edges of one side ; net sum will be equal to the summation of edges of all the sides ; initialize the area of three faces which has a common vertex
function findEdges ( s1 , s2 , s3 ) { let a = Math . sqrt ( s1 * s2 / s3 ) ; let b = Math . sqrt ( s3 * s1 / s2 ) ; let c = Math . sqrt ( s3 * s2 / s1 ) ; let sum = a + b + c ; return 4 * sum ; } let s1 , s2 , s3 ; s1 = 65 ; s2 = 156 ; s3 = 60 ; document . write ( findEdges ( s1 , s2 , s3 ) ) ;
Maximum number of pieces in N cuts | Function for finding maximum pieces with n cuts . ; to maximize number of pieces x is the horizontal cuts ; Now ( x ) is the horizontal cuts and ( n - x ) is vertical cuts , then maximum number of pieces = ( x + 1 ) * ( n - x + 1 ) ; Taking the maximum number of cuts allowed as 3 ; Finding and printing the max number of pieces
function findMaximumPieces ( n ) { var x = parseInt ( n / 2 ) ; return ( ( x + 1 ) * ( n - x + 1 ) ) ; } var n = 3 ; document . write ( " " + n + " " + findMaximumPieces ( 3 ) ) ;
Program to check whether 4 points in a 3 | Function to find equation of plane . ; checking if the 4 th povar satisfies the above equation ; Driver Code ; function calling
function equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 , x , y , z ) { 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 ) ; if ( a * x + b * y + c * z + d == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var x1 = 3 ; var y1 = 2 ; var z1 = - 5 ; var x2 = - 1 ; var y2 = 4 ; var z2 = - 3 ; var x3 = - 3 ; var y3 = 8 ; var z3 = - 5 ; var x4 = - 3 ; var y4 = 2 ; var z4 = 1 ; equation_plane ( x1 , y1 , z1 , x2 , y2 , z2 , x3 , y3 , z3 , x4 , y4 , z4 ) ;
Angle between two Planes in 3D | Function to find Angle ; Driver Code
function distance ( a1 , b1 , c1 , a2 , b2 , c2 ) { var d = a1 * a2 + b1 * b2 + c1 * c2 ; var e1 = Math . sqrt ( a1 * a1 + b1 * b1 + c1 * c1 ) ; var e2 = Math . sqrt ( a2 * a2 + b2 * b2 + c2 * c2 ) ; d = parseFloat ( d / ( e1 * e2 ) ) ; var pi = 3.14159 ; var A = ( 180 / pi ) * Math . acos ( d ) ; document . write ( " " + A . toFixed ( 1 ) + " " ) ; } var a1 = 1 ; var b1 = 1 ; var c1 = 2 ; var d1 = 1 ; var a2 = 2 ; var b2 = - 1 ; var c2 = 1 ; var d2 = - 4 ; distance ( a1 , b1 , c1 , a2 , b2 , c2 ) ;
Mirror of a point through a 3 D plane | Function to mirror image ; Driver Code ; function call
function mirror_point ( a , b , c , d , x1 , y1 , z1 ) { var k = parseFloat ( ( - a * x1 - b * y1 - c * z1 - d ) / parseFloat ( a * a + b * b + c * c ) ) ; var x2 = parseFloat ( a * k + x1 ) ; var y2 = parseFloat ( b * k + y1 ) ; var z2 = parseFloat ( c * k + z1 ) ; var x3 = parseFloat ( 2 * x2 - x1 ) . toFixed ( 1 ) ; var y3 = parseFloat ( 2 * y2 - y1 ) . toFixed ( 1 ) ; var z3 = parseFloat ( 2 * z2 - z1 ) . toFixed ( 1 ) ; document . write ( " " + x3 ) ; document . write ( " " + y3 ) ; document . write ( " " + z3 ) ; } var a = 1 ; var b = - 2 ; var c = 0 ; var d = 0 ; var x1 = - 1 ; var y1 = 3 ; var z1 = 4 ; mirror_point ( a , b , c , d , x1 , y1 , z1 ) ;
Number of rectangles in a circle of radius R | Function to return the total possible rectangles that can be cut from the circle ; Diameter = 2 * $Radius ; Square of diameter which is the square of the maximum length diagonal ; generate all combinations of a and b in the range ( 1 , ( 2 * Radius - 1 ) ) ( Both inclusive ) ; Calculate the Diagonal length of this rectangle ; If this rectangle 's Diagonal  Length is less than the  Diameter, it is a valid  rectangle, thus increment counter ; Radius of the circle
function countRectangles ( radius ) { let rectangles = 0 ; let diameter = 2 * radius ; let diameterSquare = diameter * diameter ; for ( let a = 1 ; a < 2 * radius ; a ++ ) { for ( let b = 1 ; b < 2 * radius ; b ++ ) { let diagonalLengthSquare = ( a * a + b * b ) ; if ( diagonalLengthSquare <= diameterSquare ) { rectangles ++ ; } } } return rectangles ; } let radius = 2 ; let totalRectangles ; totalRectangles = countRectangles ( radius ) ; document . write ( totalRectangles + " " + radius ) ;
Program to check similarity of given two triangles | Function for AAA similarity ; Check for AAA ; Function for SAS similarity ; angle b / w two smallest sides is largest . ; since we take angle b / w the sides . ; Function for SSS similarity ; Check for SSS ; Driver Code ; function call for AAA similarity ; function call for SSS similarity ; function call for SAS similarity ; Check if triangles are similar or not
function simi_aaa ( a1 , a2 ) { a1 . sort ( function ( a , b ) { return a - b } ) ; a2 . sort ( function ( a , b ) { return a - b } ) ; if ( a1 [ 0 ] == a2 [ 0 ] && a1 [ 1 ] == a2 [ 1 ] && a1 [ 2 ] == a2 [ 2 ] ) return 1 ; else return 0 ; } function simi_sas ( s1 , s2 , a1 , a2 ) { a1 . sort ( function ( a , b ) { return a - b } ) ; a2 . sort ( function ( a , b ) { return a - b } ) ; s1 . sort ( function ( a , b ) { return a - b } ) ; s2 . sort ( function ( a , b ) { return a - b } ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] ) { if ( a1 [ 2 ] == a2 [ 2 ] ) return 1 ; } if ( s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] ) { if ( a1 [ 0 ] == a2 [ 0 ] ) return 1 ; } if ( s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) { if ( a1 [ 1 ] == a2 [ 1 ] ) return 1 ; } return 0 ; } function simi_sss ( s1 , s2 ) { s1 . sort ( function ( a , b ) { return a - b } ) ; s2 . sort ( function ( a , b ) { return a - b } ) ; if ( s1 [ 0 ] / s2 [ 0 ] == s1 [ 1 ] / s2 [ 1 ] && s1 [ 1 ] / s2 [ 1 ] == s1 [ 2 ] / s2 [ 2 ] && s1 [ 2 ] / s2 [ 2 ] == s1 [ 0 ] / s2 [ 0 ] ) return 1 ; return 0 ; } let s1 = [ 2 , 3 , 3 ] ; let s2 = [ 4 , 6 , 6 ] ; let a1 = [ 80 , 60 , 40 ] ; let a2 = [ 40 , 60 , 80 ] ; let aaa = simi_aaa ( a1 , a2 ) ; let sss = simi_sss ( s1 , s2 ) ; let sas = simi_sas ( s1 , s2 , a1 , a2 ) ; if ( aaa == 1 sss == 1 sas == 1 ) { document . write ( " " + " " ) ; if ( aaa == 1 ) document . write ( " " ) ; if ( sss == 1 ) document . write ( " " ) ; if ( sas == 1 ) document . write ( " " ) ; } else document . write ( " " ) ;
Centered Pentadecagonal Number | centered pentadecagonal function ; Formula to calculate nth centered pentadecagonal number ; Driver Code
function center_pentadecagonal_num ( n ) { return ( 15 * n * n - 15 * n + 2 ) / 2 ; } var n = 3 ; document . write ( n + " " ) ; document . write ( center_pentadecagonal_num ( n ) + " " ) ; n = 10 ; document . write ( n + " " ) ; document . write ( center_pentadecagonal_num ( n ) ) ;
Centered nonadecagonal number | centered nonadecagonal function ; Formula to calculate nth centered nonadecagonal number ; Driver Code
function center_nonadecagon_num ( n ) { return ( 19 * n * n - 19 * n + 2 ) / 2 ; } var n = 2 ; document . write ( n + " " + " " ) ; document . write ( center_nonadecagon_num ( n ) + " " ) ; n = 7 ; document . write ( n + " " + " " ) ; document . write ( center_nonadecagon_num ( n ) ) ;
Hendecagonal number | Function to find Hendecagonal number ; Formula to calculate nth Hendecagonal number ; Driver Code
function hendecagonal_num ( n ) { return ( 9 * n * n - 7 * n ) / 2 ; } let n = 3 ; document . write ( n + " " ) ; document . write ( hendecagonal_num ( n ) + " " ) ; n = 10 ; document . write ( n + " " ) ; document . write ( hendecagonal_num ( n ) ) ;
Centered Octagonal Number | Function to find centered octagonal number ; Formula to calculate nth centered octagonal number and return it into main function ; Driver Code
function centeredoctagonalNumber ( n ) { return 4 * n * ( n - 1 ) + 1 ; } var n = 6 ; document . write ( n + " " + " " ) ; document . write ( centeredoctagonalNumber ( n ) + " " ) ; n = 11 ; document . write ( n + " " + " " ) ; document . write ( centeredoctagonalNumber ( n ) ) ;
Number of ordered points pair satisfying line equation | Checks if ( i , j ) is valid , a point ( i , j ) is valid if point ( arr [ i ] , arr [ j ] ) satisfies the equation y = mx + c And i is not equal to j ; check if i equals to j ; Equation LHS = y , and RHS = mx + c ; Returns the number of ordered pairs ( i , j ) for which point ( arr [ i ] , arr [ j ] ) satisfies the equation of the line y = mx + c ; for every possible ( i , j ) check if ( a [ i ] , a [ j ] ) satisfies the equation y = mx + c ; ( firstIndex , secondIndex ) is same as ( i , j ) ; check if ( firstIndex , secondIndex ) is a valid point ; Driver Code ; equation of line is y = mx + c
function isValid ( arr , i , j , m , c ) { if ( i == j ) return false ; var lhs = arr [ j ] ; var rhs = m * arr [ i ] + c ; return lhs == rhs ; } function findOrderedPoints ( arr , n , m , c ) { var counter = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) { var firstIndex = i , secondIndex = j ; if ( isValid ( arr , firstIndex , secondIndex , m , c ) ) counter ++ ; } } return counter ; } var arr = [ 1 , 2 , 3 , 4 , 2 ] ; var n = arr . length ; var m = 1 , c = 1 ; document . write ( findOrderedPoints ( arr , n , m , c ) ) ;