codeparrot/xlcost-text-to-code huggingface dataset:
AKS Primality Test | array used to store coefficients . ; function to calculate the coefficients of ( x - 1 ) ^ n - ( x ^ n - 1 ) with the help of Pascal 's triangle . ; function to check whether the number is prime or not ; Calculating all the coefficients by the function coef and storing all the coefficients in c array . ; subtracting c [ n ] and adding c [ 0 ] by 1 as ( x - 1 ) ^ n - ( x ^ n - 1 ) , here we are subtracting c [ n ] by 1 and adding 1 in expression . ; checking all the coefficients whether they are divisible by n or not . if n is not prime , then loop breaks and ( i > 0 ) . ; Return true if all coefficients are divisible by n . ; Driver code
let c = [ ] ; function coef ( n ) { c [ 0 ] = 1 ; for ( let i = 0 ; i < n ; c [ 0 ] = - c [ 0 ] , i ++ ) { c [ 1 + i ] = 1 ; for ( let j = i ; j > 0 ; j -- ) c [ j ] = c [ j - 1 ] - c [ j ] ; } } function isPrime ( n ) { coef ( n ) ; c [ 0 ] ++ ; c [ n ] -- ; let i = n ; while ( ( i -- ) > 0 && c [ i ] % n == 0 ) ; return i < 0 ; } let n = 37 ; if ( isPrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Motzkin number | Return the nth Motzkin Number . ; Base Case ; Recursive step ; driver code
function motzkin ( n ) { if ( n == 0 n == 1 ) return 1 ; return ( ( 2 * n + 1 ) * motzkin ( n - 1 ) + ( 3 * n - 3 ) * motzkin ( n - 2 ) ) / ( n + 2 ) ; } var n = 8 ; document . write ( motzkin ( n ) ) ;
Sum of the series 0.6 , 0.06 , 0.006 , 0.0006 , ... to n terms | function which return the the sum of series ; Driver Code
function sumOfSeries ( n ) { return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ; } let n = 2 ; document . write ( sumOfSeries ( n ) . toFixed ( 5 ) ) ;
Narcissistic number | Function to count digits ; Returns true if n is Narcissistic number ; count the number of digits ; calculates the sum of digits raised to power ; Driver Code
function countDigit ( n ) { if ( n == 0 ) return 0 ; return ( 1 + countDigit ( n / 10 ) ) ; } function check ( n ) { let l = countDigit ( n ) ; let dup = n ; let sum = 0 ; while ( dup ) { sum += Math . pow ( dup % 10 , l ) ; dup = parseINT ( dup / 10 ) ; } return ( n == sum ) ; } let n = 1634 ; if ( check ( ! n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Sum of squares of first n natural numbers | Function to calculate sum ; Driver code
function summation ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) sum += ( i * i ) ; return sum ; } let n = 2 ; document . write ( summation ( n ) ) ;
Leyland Number | Javascript program to print first N Leyland Numbers . ; Print first n Leyland Number . ; Outer loop for x from 2 to n . ; Inner loop for y from 2 to x . ; Calculating x ^ y + y ^ x ; Sorting the all Leyland Number . ; Printing first n Leyland number . ; Driver Code
let MAX = 100 ; function leyland ( n ) { let ans = [ ] ; let index = 0 ; for ( let x = 2 ; x <= n ; x ++ ) { for ( let y = 2 ; y <= x ; y ++ ) { let temp = Math . pow ( x , y ) + Math . pow ( y , x ) ; ans [ index ] = temp ; index ++ ; } } console . log ( ans ) ans = ans . sort ( ( a , b ) => a - b ) ; console . log ( ans ) for ( let i = 0 ; i < n ; i ++ ) document . write ( ans [ i ] + " " ) ; } let n = 6 ; leyland ( n ) ;
Nicomachusâ €™ s Theorem ( Sum of k | Return the sum of k - th group of positive odd integers . ; Finding first element of kth group . ; Finding the sum . ; Driver code
function kthgroupsum ( k ) { let cur = ( k * ( k - 1 ) ) + 1 ; let sum = 0 ; while ( k -- ) { sum += cur ; cur += 2 ; } return sum ; } let k = 3 ; document . write ( kthgroupsum ( k ) ) ;
n | Returns n - th term of the series 2 , 12 , 36 , 80 , 150 ; driver code
function nthTerm ( n ) { return ( n * n ) + ( n * n * n ) ; } let n = 4 ; document . write ( nthTerm ( n ) ) ;
Sum of the series 1 , 3 , 6 , 10. . . ( Triangular Numbers ) | Function to find the sum of series ; Driver code
function seriesSum ( n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } let n = 4 ; document . write ( seriesSum ( n ) ) ;
Calculate speed , distance and time | Function to calculate speed ; Function to calculate distance traveled ; Function to calculate time taken ; Calling function cal_speed ( ) ; Calling function cal_dis ( ) ; Calling function cal_time ( )
function cal_speed ( dist , time ) { document . write ( " " + dist + " " ) ; document . write ( " " + time + " " ) ; return dist / time ; } function cal_dis ( speed , time ) { document . write ( " " + time + " " ) ; document . write ( " " + speed + " " ) ; return speed * time ; } function cal_time ( dist , speed ) { document . write ( " " + dist + " " ) ; document . write ( " " + speed + " " ) ; return speed * dist ; } document . write ( " " + cal_speed ( 45.9 , 2.0 ) + " " ) ; document . write ( " " ) ; document . write ( " " + cal_dis ( 62.9 , 2.5 ) + " " ) ; document . write ( " " ) ; document . write ( " " + cal_time ( 48.0 , 4.5 ) + " " ) ;
Print factorials of a range in right aligned format | Javascript Program to print format of factorial ; vector for store the result ; variable for store the each number factorial ; copy of first number ; found first number factorial ; push the first number in result vector ; incerement the first number ; found the all reaming number factorial loop is working until all required number factorial founded ; store the result of factorial ; incerement the first number ; return the result ; function for print the result ; setw ( ) is used for fill the blank right is used for right justification of data ; number which found the factorial of between range ; store the result of factorial ; function for found factorial ; function for print format
function find_factorial ( num1 , num2 ) { let vec = [ ] ; let t = 0 ; let fac = 1 ; let temp = num1 ; while ( 1 ) { if ( temp == 1 ) break ; fac *= temp ; temp -- ; } vec [ t ++ ] = fac ; num1 ++ ; while ( num1 <= num2 ) { fac *= num1 ; vec [ t ++ ] = fac ; num1 ++ ; } return ( vec ) ; } function print_format ( result ) { let x = result . length ; let digits = String ( result [ x - 1 ] ) . length ; for ( let i = 0 ; i < x ; i ++ ) { result [ i ] = new Array ( x - i ) . fill ( " " ) . join ( " " ) + result [ i ] ; document . write ( String ( result [ i ] ) + " " ) ; } } let m = 10 ; let n = 20 ; let result_fac ; result_fac = find_factorial ( m , n ) ; print_format ( result_fac ) ;
Find n | Function to find the nth term of series ; Loop to add numbers ; Driver code
function term ( n ) { let ans = 0 ; for ( let i = 1 ; i <= n ; i ++ ) ans += i ; return ans ; } let n = 4 ; document . write ( term ( n ) ) ;
Find the average of first N natural numbers | Return the average of first n natural numbers ; Driven Program
function avgOfFirstN ( n ) { return ( 1 + n ) / 2 ; } let n = 20 ; document . write ( avgOfFirstN ( n ) ) ;
Find the sum of the series 1 + 11 + 111 + 1111 + ... . . upto n terms | Function for finding summation ; Driver Code
function summation ( n ) { let sum ; sum = ( Math . pow ( 10 , n + 1 ) - 10 - ( 9 * n ) ) / 81 ; return sum ; } let n = 5 ; document . write ( summation ( n ) ) ;
Sum of the Series 1 + x / 1 + x ^ 2 / 2 + x ^ 3 / 3 + . . + x ^ n / n | JavaScript code to print the sum of the series ; Driver code
function sum ( x , n ) { let total = 1.0 ; let multi = x ; for ( let i = 1 ; i <= n ; i ++ ) { total = total + multi / i ; multi = multi * x ; } return total ; } let x = 2 ; let n = 5 ; document . write ( sum ( x , n ) . toFixed ( 2 ) ) ;
Find n | Function to solve the quadratic equation ; Calculating the Nth term ; Driver code
function term ( n ) { let x = parseInt ( ( ( 1 ) + Math . sqrt ( 1 + ( 8 * n ) ) ) / 2 ) ; return x ; } let n = 5 ; document . write ( term ( n ) ) ;
Deserium Number | Returns count of digits in n . ; Returns true if x is Diserium ; Compute powers of digits from right to left . ; If sum of powers is same as given number . ; Driver Code
function countDigits ( n ) { let c = 0 ; do { c ++ ; n = Math . floor ( n / 10 ) ; } while ( n != 0 ) ; return c ; } function isDeserium ( x ) { let temp = x ; let p = countDigits ( x ) ; let sum = 0 ; while ( x != 0 ) { let digit = x % 10 ; sum += Math . floor ( Math . pow ( digit , p ) ) ; p -- ; x = Math . floor ( x / 10 ) ; } return ( sum == temp ) ; } let x = 135 ; if ( isDeserium ( x ) ) document . write ( " " ) ; else document . write ( " " ) ;
Largest number by which given 3 numbers should be divided such that they leaves same remainder | __gcd function ; Function return number which divides these three number and leaves same remainder . ; We find the differences of all three pairs ; Return GCD of three differences . ; Driver code
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function sameRemainder ( a , b , c ) { var a1 = ( b - a ) , b1 = ( c - b ) , c1 = ( c - a ) ; return gcd ( a1 , gcd ( b1 , c1 ) ) ; } var a = 62 , b = 132 , c = 237 ; document . write ( sameRemainder ( a , b , c ) ) ;
Find combined mean and variance of two series | Function to find mean of series . ; Function to find the standard deviation of series . ; Function to find combined variance of two different series . ; mean1 and mean2 are the mean of two arrays . ; sd1 and sd2 are the standard deviation of two array . ; combinedMean is variable to store the combined mean of both array . ; d1_square and d2_square are the combined mean deviation . ; combinedVar is variable to store combined variance of both array . ; Driver code ; Function call to combined mean .
function mean ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; var mean = sum / n ; return mean ; } function sd ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum = sum + ( arr [ i ] - mean ( arr , n ) ) * ( arr [ i ] - mean ( arr , n ) ) ; var sdd = sum / n ; return sdd ; } function combinedVariance ( arr1 , arr2 , n , m ) { var mean1 = mean ( arr1 , n ) ; var mean2 = mean ( arr2 , m ) ; document . write ( " " + mean1 . toFixed ( 4 ) + " " ) ; document . write ( " " + mean2 + " " ) ; var sd1 = sd ( arr1 , n ) ; var sd2 = sd ( arr2 , m ) ; document . write ( " " + sd1 . toFixed ( 3 ) + " " ) ; document . write ( " " + sd2 + " " + " " ) ; var combinedMean = ( n * mean1 + m * mean2 ) / ( n + m ) ; document . write ( " " + combinedMean . toFixed ( 4 ) + " " + " " ) ; var d1_square = ( mean1 - combinedMean ) * ( mean1 - combinedMean ) ; var d2_square = ( mean2 - combinedMean ) * ( mean2 - combinedMean ) ; document . write ( " " + d1_square . toFixed ( 3 ) + " " ) ; document . write ( " " + d2_square . toFixed ( 4 ) + " " ) ; var combinedVar = ( n * ( sd1 + d1_square ) + m * ( sd2 + d2_square ) ) / ( n + m ) ; return combinedVar ; } var arr1 = [ 23 , 45 , 34 , 78 , 12 , 76 , 34 ] var arr2 = [ 65 , 67 , 34 , 23 , 45 ] var n = arr1 . length ; var m = arr2 . length ; document . write ( " " + combinedVariance ( arr1 , arr2 , n , m ) . toFixed ( 3 ) ) ;
Check if a large number is divisible by 13 or not | Returns true if number is divisible by 13 else returns false ; Append required 0 s at the beginning . ; Same as strcat ( num , "00" ) ; in c . ; Same as strcat ( num , "0" ) ; in c . ; Alternatively add / subtract digits in group of three to result . ; Store group of three numbers in group variable . ; Generate alternate series of plus and minus ; Driver code
function checkDivisibility ( num ) { let length = num . length ; if ( length == 1 && num [ 0 ] == ' ' ) return true ; if ( length % 3 == 1 ) { num += " " ; length += 2 ; } else if ( length % 3 == 2 ) { num += " " ; length += 1 ; } let sum = 0 ; p = 1 ; for ( let i = length - 1 ; i >= 0 ; i -- ) { group = 0 ; group += num [ i -- ] - ' ' ; group += ( num [ i -- ] - ' ' ) * 10 ; group += ( num [ i ] - ' ' ) * 100 ; sum = sum + group * p ; p *= ( - 1 ) ; } sum = Math . abs ( sum ) ; return ( sum % 13 == 0 ) ; } let number = " " ; if ( checkDivisibility ( number ) ) document . write ( number + " " ) ; else document . write ( number + " " ) ;
Given two numbers a and b find all x such that a % x = b | Javascript program to find x such that a % x is equal to b . ; If a is less than b then no solution ; If a is equal to b then every number greater than a will be the solution so its infinity ; Count variable store the number of values possible ; checking for both divisor and quotient whether they divide ( a - b ) completely and greater than b . ; Here y is added twice in the last iteration so 1 y should be decremented to get correct solution ; Driver Code
function modularEquation ( a , b ) { if ( a < b ) { document . write ( " " ) ; return ; } if ( a == b ) { document . write ( " " ) ; return ; } let count = 0 ; let n = a - b ; let y = Math . sqrt ( a - b ) ; for ( let i = 1 ; i <= y ; ++ i ) { if ( n % i == 0 ) { if ( n / i > b ) count ++ ; if ( i > b ) count ++ ; } } if ( y * y == n && y > b ) count -- ; document . write ( count ) ; } let a = 21 ; let b = 5 ; modularEquation ( a , b ) ;
Count different numbers that can be generated such that there digits sum is equal to ' n ' | Function to count ' num ' as sum of digits ( 1 , 2 , 3 , 4 ) ; Initialize dp [ ] array ; Base case ; Initialize the current dp [ ] array as '0' ; If i == j then there is only one way to write with element itself ' i ' ; If j == 1 , then there exist two ways , one from '1' and other from '4' ; If i - j is positive then pick the element from ' i - j ' element of dp [ ] array ; Check for modulas ; Return the final answer ; Driver Code
function countWays ( num ) { let dp = [ ] ; let MOD = 1E9 + 7 ; dp [ 1 ] = 2 ; for ( let i = 2 ; i <= num ; ++ i ) { dp [ i ] = 0 ; for ( let j = 1 ; j <= 3 ; ++ j ) { if ( i - j == 0 ) dp [ i ] += 1 ; else if ( j == 1 ) dp [ i ] += dp [ i - j ] * 2 ; else if ( i - j > 0 ) dp [ i ] += dp [ i - j ] ; if ( dp [ i ] >= MOD ) dp [ i ] %= MOD ; } } return dp [ num ] ; } let n = 3 ; document . write ( countWays ( n ) ) ;
Check whether a number can be represented by sum of two squares | function to check if there exist two numbers sum of whose squares is n . ; store square value in hashmap ; Driver Code
function sumSquare ( n ) { let s = new Map ( ) ; for ( let i = 0 ; i * i <= n ; ++ i ) { s . set ( i * i , 1 ) ; if ( s . has ( n - i * i ) ) { document . write ( Math . sqrt ( n - i * i ) + " " + i + " " ) ; return true ; } } return false ; } let n = 169 ; document . write ( sumSquare ( n ) ? " " : " " ) ;
Check whether a number can be represented by sum of two squares | Javascript program to Check whether a number can be represented by sum of two squares using Fermat Theorem . ; Count all the prime factors . ; If any prime factor of the form ( 4 k + 3 ) ( 4 k + 3 ) occurs an odd number of times . ; If n itself is a prime number and can be expressed in the form of 4 k + 3 we return false . ; Driver Code
function judgeSquareSum ( n ) { for ( i = 2 ; i * i <= n ; i ++ ) { var count = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { count ++ ; n = parseInt ( n / i ) ; } if ( i % 4 == 3 && count % 2 != 0 ) return false ; } } return n % 4 != 3 ; } var n = 17 ; if ( judgeSquareSum ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;
Total no of 1 's in numbers | function to count the frequency of 1. ; driver function
function countDigitOne ( n ) { var countr = 0 ; for ( var i = 1 ; i <= n ; i *= 10 ) { var divider = i * 10 ; countr += parseInt ( n / divider ) * i + Math . min ( Math . max ( n % divider - i + 1 , 0 ) , i ) ; } return countr ; } var n = 13 ; document . write ( countDigitOne ( n ) + " " ) ; n = 113 ; document . write ( countDigitOne ( n ) + " " ) ; n = 205 ; document . write ( countDigitOne ( n ) + " " ) ;
Largest number with prime digits | check if character is prime ; replace with previous prime character ; if 2 erase s [ i ] and replace next with 7 ; find first non prime char ; find first char greater than 2 ; like 20 ; like 7721 ; replace remaining with 7 ; Driver code
function isPrime ( c ) { return ( c == ' ' c == ' ' c == ' ' c == ' ' ) ; } function decrease ( s , i ) { if ( s [ i ] <= ' ' ) { s . splice ( i , 1 ) s [ i ] = ' ' ; } else if ( s [ i ] == ' ' ) s [ i ] = ' ' ; else if ( s [ i ] <= ' ' ) s [ i ] = ' ' ; else if ( s [ i ] <= ' ' ) s [ i ] = ' ' ; else s [ i ] = ' ' ; return s ; } function primeDigits ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! isPrime ( s [ i ] ) ) { while ( i >= 0 && s [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) i -- ; if ( i < 0 ) { i = 0 ; s = decrease ( s . split ( " " ) , i ) ; } else s = decrease ( s . split ( " " ) , i ) ; for ( let j = i + 1 ; j < s . length ; j ++ ) s [ j ] = ' ' ; break ; } } return s . join ( " " ) ; } let s = " " ; document . write ( primeDigits ( s ) + " " ) ; s = " " ; document . write ( primeDigits ( s ) + " " ) ; s = " " ; document . write ( primeDigits ( s ) + " " ) ; s = " " ; document . write ( primeDigits ( s ) + " " ) ; s = " " ; document . write ( primeDigits ( s ) + " " ) ;
Divisors of n | Function to count divisors of n ^ 2 having no factors of ' n ' ; Increment count of i - th prime divisor ; Find next prime divisor ; Increment count if divisor still remains ; Initialize variable for counting the factors of n ^ 2 and n as ans1 and ans2 respectively ; Range based for - loop ; Use formula as discussed in above ; return the difference of answers ; Driver code
function factors ( n ) { let prime = new Map ( ) ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; ++ i ) { while ( n % i == 0 ) { if ( prime . has ( i ) ) { prime . set ( i , prime . get ( i ) + 1 ) ; } else { prime . set ( i , 1 ) ; } n = Math . floor ( n / i ) ; } } if ( n > 2 ) { if ( prime . has ( n ) ) { prime . set ( n , prime . get ( n ) + 1 ) ; } else { prime . set ( n , 1 ) ; } } let ans1 = 1 , ans2 = 1 ; for ( let [ key , value ] of prime . entries ( ) ) { ans1 *= 2 * value + 1 ; ans2 *= value + 1 ; } return ans1 - ans2 ; } let n = 5 ; document . write ( factors ( n ) + " " ) ; n = 8 ; document . write ( factors ( n ) + " " ) ;
Print digit 's position to be removed to make a number divisible by 6 | Function to print the number divisible by 6 after exactly removing a digit ; Stores the sum of all elements ; Traverses the string and converts string to number array and sums up ; ODD CHECK ; If second last is odd or sum of n - 1 elements are not divisible by 3. ; Second last is even and print n - 1 elements removing last digit ; Last digit removed ; Counter to check if any element after removing , its sum % 3 == 0 ; Traverse till second last element ; To check if any element after removing , its sum % 3 == 0 ; The leftmost element ; Break at the leftmost element ; Stores the right most element ; If no element has been found as a [ i + 1 ] > a [ i ] ; If second last is even , then remove last if ( sum - last ) % 3 == 0 ; If no element which on removing gives sum % 3 == 0 ; Driver code
function greatest ( s ) { let n = s . length ; let a = new Array ( n ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] = s [ i ] - ' ' ; sum += a [ i ] ; } if ( a [ n - 1 ] % 2 ) { if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) { document . write ( " " + " " ) ; } else { document . write ( n + " " ) ; } } else { let re = sum % 3 ; let del = - 1 ; let flag = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] ) % 3 === re ) { if ( a [ i + 1 ] > a [ i ] ) { del = i ; flag = 1 ; break ; } else { del = i ; } } } if ( flag === 0 ) { if ( a [ n - 2 ] % 2 === 0 && re === a [ n - 1 ] % 3 ) del = n - 1 ; } if ( del === - 1 ) document . write ( - 1 + " " ) ; else { document . write ( del + 1 + " " ) ; } } } let s = " " ; greatest ( s ) ;
Representation of a number in powers of other | Javascript program to check if m can be represented as powers of w . ; break ; None of 3 worked . ; If m is not zero means , it can 't be  represented in terms of powers of w. ; Driver code
function asPowerSum ( w , m ) { while ( m > 0 ) { if ( ( m - 1 ) % w == 0 ) m = ( m - 1 ) / w ; else if ( ( m + 1 ) % w == 0 ) m = ( m + 1 ) / w ; else if ( m % w == 0 ) m = m / w ; else } return ( m == 0 ) ; } let w = 3 , m = 7 ; if ( asPowerSum ( w , m ) ) document . write ( " " ) ; else document . write ( " " ) ;
Number of digits to be removed to make a number divisible by 3 | function to count the no of removal of digits to make a very large number divisible by 3 ; add up all the digits of num ; if num is already is divisible by 3 then no digits are to be removed ; if there is single digit , then it is not possible to remove one digit . ; traverse through the number and find out if any number on removal makes the sum divisible by 3 ; if there are two numbers then it is not possible to remove two digits . ; Otherwise we can always make a number multiple of 2 by removing 2 digits . ; Driver Code
function divisible ( num ) { let n = num . length ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += ( num . charAt ( i ) ) ; if ( sum % 3 == 0 ) return 0 ; if ( n == 1 ) return - 1 ; for ( let i = 0 ; i < n ; i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' ' ) % 3 ) return 1 ; if ( n == 2 ) return - 1 ; return 2 ; } let num = " " ; document . write ( divisible ( num ) ) ;
Program for dot product and cross product of two vectors | Javascript implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver code ; dotProduct function call ; crossProduct function call ; Loop that prlet cross product of two vector array .
let n = 3 ; function dotProduct ( vect_A , vect_B ) { let product = 0 ; for ( let i = 0 ; i < n ; i ++ ) product = product + vect_A [ i ] * vect_B [ i ] ; return product ; } function crossProduct ( vect_A , vect_B , cross_P ) { cross_P [ 0 ] = vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ; cross_P [ 1 ] = vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ; cross_P [ 2 ] = vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ; } let vect_A = [ 3 , - 5 , 4 ] ; let vect_B = [ 2 , 6 , 5 ] ; let cross_P = [ ] ; document . write ( " " ) ; document . write ( dotProduct ( vect_A , vect_B ) + " " ) ; document . write ( " " ) ; crossProduct ( vect_A , vect_B , cross_P ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( cross_P [ i ] + " " ) ;
Number of n digit numbers that do not contain 9 | function to find number of n digit numbers possible ; Driver code
function totalNumber ( n ) { return 8 * Math . pow ( 9 , n - 1 ) ; } let n = 3 ; document . write ( totalNumber ( n ) ) ;
Count ways to express even number â €˜ nâ €™ as sum of even integers | Initialize mod variable as constant ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Return number of ways to write ' n ' as sum of even integers ; Driver code
let MOD = 1000000007 ; function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( 1 * res * x ) % p ; x = ( 1 * x * x ) % p ; } return res ; } function countEvenWays ( n ) { return power ( 2 , n / 2 - 1 , MOD ) ; } let n = 6 ; document . write ( countEvenWays ( n ) + " " ) ; n = 8 ; document . write ( countEvenWays ( n ) ) ;