codeparrot/xlcost-text-to-code huggingface dataset:
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
function printRoots ( a , b , c ) { document . write ( 1 + " " + c / ( a * 1.0 ) ) ; } var a = 2 ; var b = 3 ; var c = - 5 ; printRoots ( a , b , c ) ;
Longest alternative parity subsequence | Function to find the longest ; Marks the starting of odd number as sequence and alternatively changes ; Finding the longest odd / even sequence ; Find odd number ; Find even number ; Length of the longest even / odd sequence ; Find odd number ; Find even number ; Answer is maximum of both odd / even or even / odd subsequence ; Driver Code
function longestAlternativeSequence ( a , n ) { let maxi1 = 0 ; let f1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! f1 ) { if ( a [ i ] % 2 ) { f1 = 1 ; maxi1 ++ ; } } else { if ( a [ i ] % 2 == 0 ) { maxi1 ++ ; f1 = 0 ; } } } let maxi2 = 0 ; let f2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( f2 ) { if ( a [ i ] % 2 ) { f2 = 1 ; maxi2 ++ ; } } else { if ( a [ i ] % 2 == 0 ) { maxi2 ++ ; f2 = 0 ; } } } return Math . max ( maxi1 , maxi2 ) ; } let a = [ 13 , 16 , 8 , 9 , 32 , 10 ] ; let n = a . length ; document . write ( longestAlternativeSequence ( a , n ) ) ;
Nambiar Number Generator | Function to return the Nambiar number of the given number ; If there is no digit to choose ; Choose the first digit ; Chosen digit 's parity ; To store the sum of the consecutive digits starting from the chosen digit ; While there are digits to choose ; Update the sum ; If the parity differs ; Return the current sum concatenated with the Numbiar number for the rest of the string ; Driver code
function nambiarNumber ( str , i ) { if ( i >= str . length ) return " " ; let firstDigit = ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; let digitParity = firstDigit % 2 ; let sumDigits = 0 ; while ( i < str . length ) { sumDigits += ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; let sumParity = sumDigits % 2 ; if ( digitParity != sumParity ) { break ; } i ++ ; } return ( " " + sumDigits + nambiarNumber ( str , i + 1 ) ) ; } let str = " " ; document . write ( nambiarNumber ( str , 0 ) ) ;
Program to find the Depreciation of Value | Function to return the depreciation of value ; Driver code
function Depreciation ( v , r , t ) { var D = v * Math . pow ( ( 1 - r / 100 ) , t ) return D ; } var V1 = 200 , R = 10 , T = 2 ; document . write ( Depreciation ( V1 , R , T ) ) ;
Program to find first N Fermat Numbers | Iterative Function to calculate ( x ^ y ) in O ( log y ) ; let res = 1 ; Initialize result ; If y is odd , multiply x with the result ; n must be even now y = y >> 1 ; y = y / 2 x = x * x ; Change x to x ^ 2 ; Function to find nth fermat number ; 2 to the power i ; 2 to the power 2 ^ i ; Function to find first n Fermat numbers ; Calculate 2 ^ 2 ^ i ; Driver code ; Function call
function power ( x , y ) { while ( y > 0 ) { if ( y & 1 ) res = res * x ; } return res ; } function Fermat ( i ) { let power2_i = power ( 2 , i ) ; let power2_2_i = power ( 2 , power2_i ) ; return power2_2_i + 1 ; } function Fermat_Number ( n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( Fermat ( i ) ) ; if ( i != n - 1 ) document . write ( " " ) ; } } let n = 7 ; Fermat_Number ( n ) ;
Program to find the Speed of train as per speed of sound | Function to find the Speed of train ; Driver Code ; Calling Function
function speedOfTrain ( X , Y ) { var Speed ; Speed = 1188 * ( ( X - Y ) / Y ) ; return Speed ; } var X = 8 , Y = 7.2 ; var result = ( speedOfTrain ( X , Y ) ) ; document . write ( Math . round ( result ) + " " ) ;
Maximum value of division of two numbers in an Array | Function to maximum value of division of two numbers in an array ; Traverse through the array ; Return the required answer ; Driver code
function Division ( a , n ) { let maxi = Number . MIN_VALUE , mini = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { maxi = Math . max ( a [ i ] , maxi ) ; mini = Math . min ( a [ i ] , mini ) ; } return parseInt ( maxi / mini ) ; } let a = [ 3 , 7 , 9 , 3 , 11 ] ; let n = a . length ; document . write ( Division ( a , n ) ) ;
Ramanujan Prime | Javascript program to find Ramanujan numbers ; FUnction to return a vector of primes ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p greater than or equal to the square of it numbers which are multiple of p and are less than p ^ 2 are already been marked . ; Print all prime numbers ; Function to find number of primes less than or equal to x ; Binary search to find out number of primes less than or equal to x ; Function to find the nth ramanujan prime ; For n >= 1 , a ( n ) < 4 * n * log ( 4 n ) ; We start from upperbound and find where pi ( i ) - pi ( i / 2 ) < n the previous number being the nth ramanujan prime ; Function to find first n Ramanujan numbers ; Get the prime numbers ; Driver code
const MAX = 1000000 ; function addPrimes ( ) { let n = MAX ; let prime = new Array ( n + 1 ) . fill ( true ) ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } let ans = [ ] ; for ( let p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . push ( p ) ; return ans ; } function pi ( x , v ) { let l = 0 , r = v . length - 1 , m , inn = - 1 ; while ( l <= r ) { m = parseInt ( ( l + r ) / 2 ) ; if ( v [ m ] <= x ) { inn = m ; l = m + 1 ; } else { r = m - 1 ; } } return inn + 1 ; } function Ramanujan ( n , v ) { let upperbound = 4 * n * parseInt ( ( Math . log ( 4 * n ) / Math . log ( 2 ) ) ) ; for ( let i = upperbound ; ; i -- ) { if ( pi ( i , v ) - pi ( parseInt ( i / 2 ) , v ) < n ) return 1 + i ; } } function Ramanujan_Numbers ( n ) { let c = 1 ; let v = addPrimes ( ) ; for ( let i = 1 ; i <= n ; i ++ ) { document . write ( Ramanujan ( i , v ) ) ; if ( i != n ) document . write ( " " ) ; } } let n = 10 ; Ramanujan_Numbers ( n ) ;
Quadruplet pair with XOR zero in the given Array | Javascript 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
const MAX = 130 ; function validQuadruple ( arr , n ) { if ( n >= MAX ) return true ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) for ( let k = j + 1 ; k < n ; k ++ ) for ( let l = k + 1 ; l < n ; l ++ ) { if ( ( arr [ i ] ^ arr [ j ] ^ arr [ k ] ^ arr [ l ] ) == 0 ) { return true ; } } return false ; } let arr = [ 1 , 0 , 2 , 3 , 7 ] ; let n = arr . length ; if ( validQuadruple ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Quadruplet pair with XOR zero in the given Array | Javascript implementation of the approach ; Driver code
function check ( arr ) { let n = arr . length ; if ( n < 4 ) return false ; if ( n >= 130 ) return true ; let map = new Map ( ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { let k = arr [ i ] ^ arr [ j ] ; if ( ! map . has ( k ) ) map . set ( k , [ ] ) ; let data = map . get ( k ) ; if ( ! data . includes ( i ) && ! data . includes ( j ) ) { data . push ( i ) ; data . push ( j ) ; if ( data . length >= 4 ) return true ; map . set ( k , data ) ; } } } return false ; } let arr = [ 1 , 0 , 2 , 3 , 7 ] ; if ( check ( arr ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants | Function to returns factorial of n ; Function to find nCr ; Function to find the number of words of X vowels and Y consonants can be formed from M vowels and N consonants ; Driver code ; Function call
function fact ( n ) { var res = 1 ; for ( var i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function NumberOfWays ( X , Y , M , N ) { return fact ( X + Y ) * nCr ( M , X ) * nCr ( N , Y ) ; } var X = 2 , Y = 2 , M = 3 , N = 3 ; document . write ( NumberOfWays ( X , Y , M , N ) ) ;
Program for sum of cosh ( x ) series upto Nth term | function to return the factorial of a number ; function to return the sum of the series ; Driver code
function fact ( n ) { let i = 1 , fac = 1 ; for ( i = 1 ; i <= n ; i ++ ) fac = fac * i ; return fac ; } function log_Expansion ( x , n ) { let sum = 0 ; let i = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + Math . pow ( x , 2 * i ) / fact ( 2 * i ) ; } return sum ; } let x = 1 ; let n = 10 ; document . write ( log_Expansion ( x , n ) . toFixed ( 11 ) ) ;
Find prime numbers in the first half and second half of an array | Function to check if a number is prime or not ; Function to find whether elements are prime or not ; Traverse in the given range ; Check if a number is prime or not ; Function to print the prime numbers in the first half and second half of an array ; Driver Code ; Function call
function prime ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function prime_range ( start , end , a ) { for ( let i = start ; i < end ; i ++ ) { if ( prime ( a [ i ] ) ) document . write ( a [ i ] + " " ) ; } } function Print ( arr , n ) { document . write ( " " ) ; prime_range ( 0 , parseInt ( n / 2 ) , arr ) ; document . write ( " " ) ; document . write ( " " ) ; prime_range ( parseInt ( n / 2 ) , n , arr ) ; document . write ( " " ) ; } let arr = [ 2 , 5 , 10 , 15 , 17 , 21 , 23 ] ; let n = arr . length ; Print ( arr , n ) ;
Count of elements that can be deleted without disturbing the mean of the initial array | Function to find the elements which do not change the mean on removal ; To store the sum of the array elements ; To store the initial mean ; to store the count of required elements ; Iterate over the array ; Finding the new mean ; If the new mean equals to the initial mean ; Driver code
function countElements ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; let mean = sum / n ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let newMean = ( sum - arr [ i ] ) / ( n - 1 ) ; if ( newMean == mean ) cnt ++ ; } return cnt ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( countElements ( arr , n ) ) ;
Find the prime P using given four integers | Function to check if a number is prime or not ; Function to find possible prime number ; Find a possible prime number ; Last condition ; Driver code ; Function call
function Prime ( n ) { for ( let j = 2 ; j <= Math . sqrt ( n ) ; j ++ ) if ( n % j == 0 ) return false ; return true ; } function find_prime ( x , xsqmodp , y , ysqmodp ) { let n = x * x - xsqmodp ; let n1 = y * y - ysqmodp ; for ( let j = 2 ; j <= Math . max ( Math . sqrt ( n ) , Math . sqrt ( n1 ) ) ; j ++ ) { if ( n % j == 0 && ( x * x ) % j == xsqmodp && n1 % j == 0 && ( y * y ) % j == ysqmodp ) if ( Prime ( j ) ) return j ; let j1 = parseInt ( n / j ) ; if ( n % j1 == 0 && ( x * x ) % j1 == xsqmodp && n1 % j1 == 0 && ( y * y ) % j1 == ysqmodp ) if ( Prime ( j1 ) ) return j1 ; j1 = n1 / j ; if ( n % j1 == 0 && ( x * x ) % j1 == xsqmodp && n1 % j1 == 0 && ( y * y ) % j1 == ysqmodp ) if ( Prime ( j1 ) ) return j1 ; } if ( n == n1 ) return n ; } let x = 3 , xsqmodp = 0 , y = 5 , ysqmodp = 1 ; document . write ( find_prime ( x , xsqmodp , y , ysqmodp ) ) ;
Time taken per hour for stoppage of Car | Function to return the time taken per hour for stoppage ; Driver code
function numberOfMinutes ( S , S1 ) { let Min = 0 ; Min = ( ( S - S1 ) / Math . floor ( S ) ) * 60 ; return Min ; } let S = 30 , S1 = 10 ; document . write ( numberOfMinutes ( S , S1 ) + " " ) ;
Removing a number from array without changing its arithmetic mean | Function to remove a number from the array without changing its arithmetic mean ; Find sum of all elements ; If mean is an integer ; Check if mean is present in the array or not ; Driver code
function FindElement ( a , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum = sum + a [ i ] ; if ( sum % n == 0 ) { let m = parseInt ( sum / n ) ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] == m ) return m ; } return - 1 ; } let a = [ 1 , 2 , 3 , 4 , 5 ] ; let n = a . length ; document . write ( FindElement ( a , n ) ) ;
Sum of the Tan ( x ) expansion upto N terms | Function to find factorial of a number ; To store factorial of a number ; Return the factorial of a number ; Function to find tan ( x ) upto n terms ; To store value of the expansion ; This loops here calculate Bernoulli number which is further used to get the coefficient in the expansion of tan x ; Print the value of expansion ; Driver code ; Function call
function fac ( num ) { if ( num == 0 ) return 1 ; let fact = 1 ; for ( let i = 1 ; i <= num ; i ++ ) fact = fact * i ; return fact ; } function Tanx_expansion ( terms , x ) { let sum = 0 ; for ( let i = 1 ; i <= terms ; i += 1 ) { let B = 0 ; let Bn = 2 * i ; for ( let k = 0 ; k <= Bn ; k ++ ) { let temp = 0 ; for ( let r = 0 ; r <= k ; r ++ ) temp = temp + Math . pow ( - 1 , r ) * fac ( k ) * Math . pow ( r , Bn ) / ( fac ( r ) * fac ( k - r ) ) ; B = B + temp / ( k + 1 ) ; } sum = sum + Math . pow ( - 4 , i ) * ( 1 - Math . pow ( 4 , i ) ) * B * Math . pow ( x , 2 * i - 1 ) / fac ( 2 * i ) ; } document . write ( sum . toFixed ( 10 ) ) ; } let n = 6 , x = 1 ; Tanx_expansion ( n , x ) ;
Minimum elements to be inserted in Array to make adjacent differences equal | Function to find gcd of two numbers ; Function to calculate minimum numbers to be inserted to make equal differences between two consecutive elements ; Check if there is only one element in the array then answer will be 0 ; Calculate difference between first and second element of array ; If there is only two elements in the array then gcd of differences of consecutive elements of array will be equal to difference of first and second element of the array ; Loop to calculate the gcd of the differences between consecutive elements of the array ; Loop to calculate the elements to be inserted ; Return the answer ; Driver code
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function minimum_elements ( n , arr ) { if ( n < 3 ) return 0 ; let g , ans = 0 , diff , cnt ; diff = arr [ 1 ] - arr [ 0 ] ; g = diff ; for ( let i = 2 ; i < n ; i ++ ) { diff = arr [ i ] - arr [ i - 1 ] ; g = gcd ( g , diff ) ; } for ( let i = 1 ; i < n ; i ++ ) { diff = arr [ i ] - arr [ i - 1 ] ; cnt = parseInt ( diff / g ) ; ans += ( cnt - 1 ) ; } return ans ; } let arr = [ 1 , 5 , 8 , 10 , 12 , 16 ] ; let n = arr . length ; document . write ( minimum_elements ( n , arr ) ) ;
Check if a number is Fermat Pseudoprime | Function to check if the given number is composite ; Check if there is any divisor of n less than sqrt ( n ) ; Effectively calculate ( x ^ y ) modulo mod ; Initialize result ; If power is odd , then update the answer ; Square the number and reduce the power to its half ; Return the result ; Function to check for Fermat Pseudoprime ; If it is composite and satisfy Fermat criterion ; Else return 0 ; Driver code ; Function call
function checkcomposite ( n ) { for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return 1 ; } return 0 ; } function power ( x , y , mod ) { let res = 1 ; while ( y ) { if ( y & 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } function Check ( n , a ) { if ( a > 1 && checkcomposite ( n ) && power ( a , n - 1 , n ) == 1 ) return 1 ; return 0 ; } let N = 645 ; let a = 2 ; document . write ( Check ( N , a ) ) ;
Largest and smallest digit of a number | Function to the largest and smallest digit of a number ; Find the largest digit ; Find the smallest digit ; Driver code ; Function call
function Digits ( n ) { let largest = 0 ; let smallest = 9 ; while ( n ) { let r = n % 10 ; largest = Math . max ( r , largest ) ; smallest = Math . min ( r , smallest ) ; n = parseInt ( n / 10 ) ; } document . write ( largest + " " + smallest ) ; } let n = 2346 ; Digits ( n ) ;
Probability of distributing M items among X bags such that first bag contains N items | Function to find factorial of a number ; Function to find nCr ; Function to find probability of first bag to contain N items such that M items are distributed among X bags ; Driver code ; Function call
function factorial ( n ) { if ( n <= 1 ) return 1 ; return n * factorial ( n - 1 ) ; } function nCr ( n , r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } function Probability ( M , N , X ) { return parseFloat ( nCr ( M - N - 1 , X - 2 ) / ( nCr ( M - 1 , X - 1 ) * 1.0 ) ) ; } let M = 9 , X = 3 , N = 4 ; document . write ( Probability ( M , N , X ) . toFixed ( 6 ) ) ;
Count of N digit numbers possible which satisfy the given conditions | Function to return the factorial of n ; Function to return the count of numbers possible ; Driver code
function fact ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function Count_number ( N ) { return ( N * fact ( N ) ) ; } let N = 2 ; document . write ( Count_number ( N ) ) ;
Find the count of M character words which have at least one character repeated | Function to return the factorial of a number ; Function to return the value of nPr ; Function to return the total number of M length words which have at least a single character repeated more than once ; Driver code
function fact ( n ) { if ( n <= 1 ) return 1 ; return n * fact ( n - 1 ) ; } function nPr ( n , r ) { return fact ( n ) / fact ( n - r ) ; } function countWords ( N , M ) { return Math . pow ( N , M ) - nPr ( N , M ) ; } var N = 10 ; var M = 5 ; document . write ( countWords ( N , M ) ) ;
Minimum and maximum possible length of the third side of a triangle | Function to find the minimum and the maximum possible length of the third side of the given triangle ; Not a valid triangle ; Not a valid triangle ; Driver code
function find_length ( s1 , s2 ) { if ( s1 <= 0 s2 <= 0 ) { document . write ( - 1 ) ; return ; } var max_length = s1 + s2 - 1 ; var min_length = Math . max ( s1 , s2 ) - Math . min ( s1 , s2 ) + 1 ; if ( min_length > max_length ) { document . write ( - 1 ) ; return ; } document . write ( " " + max_length + " " ) ; document . write ( " " + min_length ) ; } var s1 = 8 , s2 = 5 ; find_length ( s1 , s2 ) ;
Number formed by the rightmost set bit in N | Function to return the integer formed by taking the rightmost set bit in n ; n & ( n - 1 ) unsets the first set bit from the right in n ; Take xor with the original number The position of the ' changed ▁ bit ' will be set and rest will be unset ; Driver code
function firstSetBit ( n ) { let x = n & ( n - 1 ) ; return ( n ^ x ) ; } let n = 12 ; document . write ( firstSetBit ( n ) ) ;
Number of N length sequences whose product is M | Function to calculate the value of ncr effectively ; Initializing the result ; Multiply and divide simultaneously to avoid overflow ; Return the answer ; Function to return the number of sequences of length N such that their product is M ; Hashmap to store the prime factors of M ; Calculate the prime factors of M ; If i divides M it means it is a factor Divide M by i till it could be divided to store the exponent ; Increase the exponent count ; If the number is a prime number greater than sqrt ( M ) ; Initializing the ans ; Multiply the answer for every prime factor ; entry . getValue ( ) represents the exponent of every prime factor ; Return the result ; Driver code
function nCr ( n , r ) { let res = 1 ; for ( let i = 1 ; i <= r ; i ++ ) { res *= ( n - r + i ) ; res = Math . floor ( res / i ) ; } return res ; } function NoofSequences ( N , M ) { let prime = new Map ( ) ; for ( let i = 2 ; i <= Math . sqrt ( M ) ; i ++ ) { while ( M % i == 0 ) { if ( prime . get ( i ) == null ) prime . set ( i , 1 ) ; else { let x = prime . get ( i ) ; prime . set ( i , ++ x ) ; } M = Math . floor ( M / i ) ; } } if ( M > 1 ) { if ( prime . get ( M ) != null ) { let x = prime . get ( M ) ; prime . set ( M , ++ x ) ; } else prime . set ( M , 1 ) ; } let ans = 1 ; for ( let [ key , value ] of prime . entries ( ) ) { ans *= ( nCr ( N + value - 1 , N - 1 ) ) ; } return ans ; } let N = 2 , M = 6 ; document . write ( NoofSequences ( N , M ) ) ;
Number of hours after which the second person moves ahead of the first person if they travel at a given speed | Function to return the number of hours for the second person to move ahead ; Time taken to equalize ; Time taken to move ahead ; Driver code
function findHours ( a , b , k ) { if ( a >= b ) return - 1 ; let time = k / ( b - a ) ; time = time + 1 ; return time ; } let a = 4 , b = 5 , k = 1 ; document . write ( findHours ( a , b , k ) ) ;
Number of ways of distributing N identical objects in R distinct groups with no groups empty | Function to return the value of ncr effectively ; Initialize the answer ; Divide simultaneously by i to avoid overflow ; Function to return the number of ways to distribute N identical objects in R distinct objects ; Driver code
function ncr ( n , r ) { let ans = 1 ; for ( let i = 1 ; i <= r ; i += 1 ) { ans *= ( n - r + i ) ; ans = parseInt ( ans / i ) ; } return ans ; } function NoOfDistributions ( N , R ) { return ncr ( N - 1 , R - 1 ) ; } let N = 4 ; let R = 3 ; document . write ( NoOfDistributions ( N , R ) ) ;
Number of ways of distributing N identical objects in R distinct groups | Function to return the value of ncr effectively ; Initialize the answer ; Divide simultaneously by i to avoid overflow ; Function to return the number of ways to distribute N identical objects in R distinct objects ; Driver code ; Function call
function ncr ( n , r ) { let ans = 1 ; for ( let i = 1 ; i <= r ; i += 1 ) { ans *= ( n - r + i ) ; ans = parseInt ( ans / i ) ; } return ans ; } function NoOfDistributions ( N , R ) { return ncr ( N + R - 1 , R - 1 ) ; } let N = 4 , R = 3 ; document . write ( NoOfDistributions ( N , R ) ) ;
Smallest perfect cube in an array | Function that returns true if n is a perfect cube ; Takes the sqrt of the number ; Checks if it is a perfect cube number ; Function to return the smallest perfect cube from the array ; Stores the minimum of all the perfect cubes from the array ; Traverse all elements in the array ; Store the minimum if current element is a perfect cube ; Driver code
function checkPerfectcube ( n ) { let d = parseInt ( Math . cbrt ( n ) ) ; if ( d * d * d == n ) return true ; return false ; } function smallestPerfectCube ( a , n ) { let mini = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( checkPerfectcube ( a [ i ] ) ) { mini = Math . min ( a [ i ] , mini ) ; } } return mini ; } let a = [ 16 , 8 , 25 , 2 , 3 , 10 ] ; let n = a . length ; document . write ( smallestPerfectCube ( a , n ) ) ;
Find two vertices of an isosceles triangle in which there is rectangle with opposite corners ( 0 , 0 ) and ( X , Y ) | Function to find two vertices of an isosceles triangle in which there is rectangle with opposite side ( 0 , 0 ) and ( x , y ) ; Required value ; ; print x1 and y1 ; print x2 and y3 ; Driver code ; Function call
function Vertices ( x , y ) { let val = Math . abs ( x ) + Math . abs ( y ) ; document . write ( val * ( x < 0 ? - 1 : 1 ) + " " ) ; document . write ( " " + val * ( y < 0 ? - 1 : 1 ) ) ; } let x = 3 , y = 3 ; Vertices ( x , y ) ;