codeparrot/xlcost-text-to-code huggingface dataset:
Number of factors of very large number N modulo M where M is any prime number | javascript implementation to find the Number of factors of very large number N modulo M ; Function for modular multiplication ; Function to find the number of factors of large Number N ; Count the number of times 2 divides the number N ; Condition to check if 2 divides it ; Check for all the possible numbers that can divide it ; Loop to check the number of times prime number i divides it ; Condition to check if prime number i divides it ; Condition to check if N at the end is a prime number . ; Driver Code
mod = 1000000007 ; function mult ( a , b ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; } function calculate_factors ( n ) { var ans , cnt ; cnt = 0 ; ans = 1 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } for ( i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { cnt = 0 ; while ( n % i == 0 ) { cnt ++ ; n = n / i ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } } if ( n > 2 ) { ans = mult ( ans , ( 2 ) ) ; } return ans % mod ; } var n = 193748576239475639 ; mod = 17 ; document . write ( calculate_factors ( n ) ) ;
Maximum value of B less than A such that A ^ B = A + B | Function to find the maximum value of B such that A ^ B = A + B ; Binary Representation of A ; Loop to find the negation of the integer A ; Output ; Driver code ; Function Call
function maxValue ( a ) { var c = a . toString ( 2 ) ; var b = " " ; for ( var i = 0 ; i < c . length ; i ++ ) { if ( ( c [ i ] - ' ' ) == 1 ) b += ' ' ; else b += ' ' ; } document . write ( parseInt ( b , 2 ) ) ; } var a = 4 ; maxValue ( a ) ;
Print all possible pair with prime XOR in the Array | Javascript implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to print all Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then print this pair ; Driver Code ; Generate all the prime number ; Function Call
const sz = 100000 ; let isPrime = new Array ( sz + 1 ) . fill ( true ) ; function generatePrime ( ) { let i , j ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } function Pair_of_PrimeXor ( A , n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) { document . write ( " " + A [ i ] + " " + A [ j ] + " " ) ; } } } } let A = [ 1 , 3 , 6 , 11 ] ; let n = A . length ; generatePrime ( ) ; Pair_of_PrimeXor ( A , n ) ;
Check if N can be expressed as product of 3 distinct numbers | function to find 3 distinct number with given product ; Declare a vector to store divisors ; store all divisors of number in array ; store all the occurence of divisors ; check if n is not equals to - 1 then n is also a prime factor ; Initialize the variables with 1 ; check for first number a ; check for second number b ; check for third number c ; check for all unwanted condition ; Driver function
function getnumbers ( n ) { let divisor = [ ] ; for ( let i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . push ( i ) ; n = Math . floor ( n / i ) ; } } if ( n != 1 ) { divisor . push ( n ) ; } let a , b , c , size ; a = b = c = 1 ; size = divisor . length ; for ( let i = 0 ; i < size ; i ++ ) { if ( a == 1 ) { a = a * divisor [ i ] ; } else if ( b == 1 b == a ) { b = b * divisor [ i ] ; } else { c = c * divisor [ i ] ; } } if ( a == 1 b == 1 c == 1 a == b b == c a == c ) { document . write ( " " + " " ) ; } else { document . write ( a + " " + b + " " + c + " " ) ; } } let n = 64 ; getnumbers ( n ) ;
Check if all Prime factors of number N are unique or not | Function that returns the all the distinct prime factors in a vector ; If n is divisible by 2 ; Divide n till all factors of 2 ; Check for the prime numbers other than 2 ; Store i in Prime [ ] i is a factor of n ; Divide n till all factors of i ; If n is greater than 2 , then n is prime number after n divided by all factors ; Returns the vector Prime ; Function that check whether N is the product of distinct prime factors or not ; Returns the vector to store all the distinct prime factors ; To find the product of all distinct prime factors ; Find the product ; If product is equals to N , print YES , else print NO ; Driver Code
function primeFactors ( n ) { let i , j ; let Prime = new Array ( ) ; if ( n % 2 == 0 ) { Prime . push ( 2 ) ; } while ( n % 2 == 0 ) { n = n / 2 ; } for ( i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { Prime . push ( i ) ; } while ( n % i == 0 ) { n = n / i ; } } if ( n > 2 ) { Prime . push ( n ) ; } return Prime ; } function checkDistinctPrime ( n ) { let Prime = primeFactors ( n ) ; let product = 1 ; for ( let i of Prime ) { product *= i ; } if ( product == n ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 30 ; checkDistinctPrime ( N ) ;
Count perfect power of K in a range [ L , R ] | Function to find the Nth root of the number ; initially guessing a random number between 0 to 9 ; Smaller eps , denotes more accuracy ; Initializing difference between two roots by INT_MAX ; xK denotes current value of x ; loop until we reach desired accuracy ; calculating current value from previous value ; Function to count the perfect powers of K in range L to R ; Driver code
function nthRoot ( A , N ) { var xPre = Math . random ( ) % 10 ; var eps = 0.001 ; var delX = 1000000000 ; var xK ; while ( delX > eps ) { xK = ( ( N - 1.0 ) * xPre + A / Math . pow ( xPre , N - 1 ) ) / N ; delX = Math . abs ( xK - xPre ) ; xPre = xK ; } return xK ; } function countPowers ( a , b , k ) { return ( Math . floor ( nthRoot ( b , k ) ) - Math . ceil ( nthRoot ( a , k ) ) + 1 ) ; } var a = 7 , b = 28 , k = 2 ; document . write ( " " + countPowers ( a , b , k ) ) ;
Minimum number of primes required such that their sum is equal to N | Function to check if n is prime ; Function to count the minimum prime required for given sum N ; Case 1 : ; Case 2 : ; Case 3 : ; Case 3 a : ; Case 3 b : ; Driver Code ; Function Call
function isPrime ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } function printMinCountPrime ( N ) { let minCount ; if ( isPrime ( N ) ) { minCount = 1 ; } else if ( N % 2 == 0 ) { minCount = 2 ; } else { if ( isPrime ( N - 2 ) ) { minCount = 2 ; } else { minCount = 3 ; } } document . write ( minCount + " " ) ; } let N = 100 ; printMinCountPrime ( N ) ;
Long Division Method to find Square root with Examples | Javascript program to find the square root of a number by using long division method ; Function to find the square root of a number by using long division method ; let i = 0 , udigit , j ; Loop counters ; Dividing the number into segments ; Last index of the array of segments ; Start long division from the last segment ( j = i ) ; Initialising the remainder to the maximum value ; Including the next segment in new dividend ; Loop to check for the perfect square closest to each segment ; This condition is to find the divisor after adding a digit in the range 0 to 9 ; Calculating the remainder ; Updating the units digit of the quotient ; Adding units digit to the quotient ; New divisor is two times quotient ; Including the remainder in new dividend ; Driver code
let INFINITY_ = 9999999 ; function sqrtByLongDivision ( n ) { let cur_divisor = 0 ; let quotient_units_digit = 0 ; let cur_quotient = 0 ; let cur_dividend = 0 ; let cur_remainder = 0 ; let a = new Array ( 10 ) ; while ( n > 0 ) { a [ i ] = n % 100 ; n = Math . floor ( n / 100 ) ; i ++ ; } i -- ; for ( j = i ; j >= 0 ; j -- ) { cur_remainder = INFINITY_ ; cur_dividend = cur_dividend * 100 + a [ j ] ; for ( udigit = 0 ; udigit <= 9 ; udigit ++ ) { if ( cur_remainder >= cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) && cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) >= 0 ) { cur_remainder = cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) ; quotient_units_digit = udigit ; } } cur_quotient = cur_quotient * 10 + quotient_units_digit ; cur_divisor = cur_quotient * 2 ; cur_dividend = cur_remainder ; } return cur_quotient ; } let x = 1225 ; document . write ( sqrtByLongDivision ( x ) + " " ) ;
Count of consecutive Fibonacci pairs in the given Array | Function to find the previous fibonacci for the number N ; Function to find the next fibonacci number for the number N ; Function to check that a Number is a perfect square or not ; Function to check that a number is fibonacci number or not ; N is Fibinacci if one of ( 5 * n * n + 4 ) or ( 5 * n * n - 4 ) is a perferct square ; Function to count the fibonacci pairs in the array ; Loop to iterate over the array to choose all pairs of the array ; Condition to check if both the number of pair is a fibonacci number ; Condition to check if both the number form consecutive fibonacci numbers ; Driver Code
function previousFibonacci ( n ) { var a = n / ( ( 1 + Math . sqrt ( 5 ) ) / 2.0 ) ; return Math . round ( a ) ; } function nextFibonacci ( n ) { var a = n * ( 1 + Math . sqrt ( 5 ) ) / 2.0 ; return Math . round ( a ) ; } function isPerfectSquare ( x ) { var s = Math . sqrt ( x ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return ( isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ) ; } function countFibonacciPairs ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) if ( isFibonacci ( arr [ i ] ) && isFibonacci ( arr [ j ] ) ) { var prevFib = previousFibonacci ( arr [ i ] ) ; var nextFib = nextFibonacci ( arr [ i ] ) ; if ( prevFib == arr [ j ] nextFib == arr [ j ] ) { res ++ ; } } return res ; } var a = [ 3 , 5 , 8 , 11 ] ; var n = a . length ; document . write ( countFibonacciPairs ( a , n ) ) ;
Count all distinct pairs with product equal to K | Function to count the number of pairs whose product is equal to K ; Pick all elements one by one ; Check if the product of this pair is equal to K ; Driver code
function countPairsWithProdK ( arr , n , k ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] * arr [ j ] == k ) count ++ ; } return count ; } var arr = [ 1 , 5 , 3 , 4 , 2 ] ; var N = arr . length ; var K = 3 ; document . write ( countPairsWithProdK ( arr , N , K ) ) ;
Count all distinct pairs with product equal to K | JavaScript program to count the number of pairs whose product is equal to K ; Function to count the number of pairs whose product is equal to K ; Initialize the count ; Initialize empty hashmap . ; Insert array elements to hashmap ; Checking if the index is a whole number and present in the hashmap ; Driver code
let MAX = 100000 ; function countPairsWithProductK ( arr , n , k ) { let count = 0 ; let i ; let hashmap = new Array ( MAX ) ; for ( i = 0 ; i < n ; i ++ ) hashmap [ arr [ i ] ] = true ; for ( i = 0 ; i < n ; i ++ ) { let x = arr [ i ] ; let index = 1.0 * k / arr [ i ] ; if ( index >= 0 && ( ( index - Math . floor ( index ) ) == 0 ) && hashmap [ k / x ] ) count ++ ; hashmap [ x ] = false ; } return count ; } let arr = [ 1 , 5 , 3 , 4 , 2 ] ; let N = arr . length ; let K = 3 ; document . write ( countPairsWithProductK ( arr , N , K ) ) ;
Find any K distinct odd integers such that their sum is equal to N | Function to find K odd integers such that their sum is N ; Condition to check if there exist such K integers ; Loop to find first K - 1 distinct odd integers ; Final Kth odd number ; Driver code
function oddIntegers ( n , k ) { if ( n % 2 != k % 2 ) { document . write ( " " ) ; return ; } var sum = 0 ; var i = 1 ; var j = 1 ; while ( j < k ) { sum = sum + i ; document . write ( i + " " ) ; i = i + 2 ; j ++ ; } var finalOdd = n - sum ; document . write ( finalOdd ) ; } var n = 10 ; var k = 2 ; oddIntegers ( n , k ) ;
Generate an array of size N according to the given rules | Function to search the most recent location of element N If not present in the array it will return - 1 ; Function to generate an array of size N by following the given rules ; Loop to fill the array as per the given rules ; Check for the occurrence of arr [ i - 1 ] ; Driver code
function search ( a , k , x ) { var j ; for ( j = k - 1 ; j > - 1 ; j -- ) { if ( a [ j ] == x ) return j ; } return - 1 ; } function genArray ( arr , N ) { for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( search ( arr , i , arr [ i ] ) == - 1 ) arr [ i + 1 ] = 0 ; else arr [ i + 1 ] = ( i - search ( arr , i , arr [ i ] ) ) ; } } var N = 5 ; var size = N + 1 ; var a = [ 0 , 0 , 0 , 0 , 0 ] ; genArray ( a , N ) ; document . write ( " " + a + " " ) ;
Count of pairs in an Array whose sum is a Perfect Cube | Function to return an ArrayList containing all the perfect cubes upto n ; while current perfect cube is less than or equal to n ; Function to print the sum of maximum two elements from the array ; Function to return the count of numbers that when added with n give a perfect cube ; temp > n is checked so that pairs ( x , y ) and ( y , x ) don 't get counted twice ; Function to count the pairs whose sum is a perfect cube ; Sum of the maximum two elements from the array ; List of perfect cubes upto max ; Contains all the array elements ; Add count of the elements that when added with arr [ i ] give a perfect cube ; Driver code
function getPerfectcubes ( n ) { let perfectcubes = [ ] ; let current = 1 ; let i = 1 ; while ( current <= n ) { perfectcubes . push ( current ) ; i += 1 ; current = parseInt ( Math . pow ( i , 3 ) ) ; } return perfectcubes ; } function maxPairSum ( arr , n ) { let max = 0 ; let secondMax = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { max = arr [ 0 ] ; secondMax = arr [ 1 ] ; } else { max = arr [ 1 ] ; secondMax = arr [ 0 ] ; } for ( let i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { secondMax = max ; max = arr [ i ] ; } else if ( arr [ i ] > secondMax ) secondMax = arr [ i ] ; } return ( max + secondMax ) ; } function countPairsWith ( n , perfectcubes , nums ) { let count = 0 ; let len = perfectcubes . length ; for ( let i = 0 ; i < len ; i ++ ) { let temp = perfectcubes [ i ] - n ; if ( temp > n ) { for ( let j = 0 ; j < nums . length ; j ++ ) { if ( nums [ j ] == temp ) count += 1 ; } } } return count ; } function countPairs ( arr , n ) { let max = maxPairSum ( arr , n ) ; let perfectcubes = getPerfectcubes ( max ) ; let nums = [ ] ; for ( let i = 0 ; i < n ; i ++ ) nums . push ( arr [ i ] ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { count += countPairsWith ( arr [ i ] , perfectcubes , nums ) ; } return count ; } let arr = [ 2 , 6 , 18 , 9 , 999 , 1 ] ; let n = arr . length ; document . write ( countPairs ( arr , n ) ) ;
Number of perfect cubes between two given numbers | Function to count cubes between two numbers ; Traverse through all numbers ; Check if current number ' i ' is perfect cube ; Driver code
function countCubes ( a , b ) { for ( let i = a ; i <= b ; i ++ ) for ( let j = 1 ; j * j * j <= i ; j ++ ) if ( j * j * j == i ) cnt ++ ; return cnt ; } let a = 7 , b = 30 ; document . write ( " " + countCubes ( a , b ) ) ;
Number of perfect cubes between two given numbers | Function to count cubes between two numbers ; Driver code
function countCubes ( a , b ) { return ( Math . floor ( b ** ( 1. / 3. ) ) - Math . ceil ( a ** ( 1. / 3. ) ) + 1 ) } let a = 7 ; let b = 28 ; document . write ( " " + countCubes ( a , b ) )
XOR and OR of all N | Function to check if a number is Armstrong or not ; Function to find XOR of all N - digits Armstrong number ; To store the XOR and OR of all Armstrong number ; Starting N - digit Armstrong number ; Ending N - digit Armstrong number ; Iterate over starting and ending number ; To check if i is Armstrong or not ; Print the XOR and OR of all Armstrong number ; Driver code
function isArmstrong ( x , n ) { let sum1 = 0 ; let temp = x ; while ( temp > 0 ) { let digit = temp % 10 ; sum1 += Math . pow ( digit , n ) ; temp = parseInt ( temp / 10 , 10 ) ; } return ( sum1 == x ) ; } function CalculateXORandOR ( n ) { let CalculateXOR = 0 ; let CalculateOR = 0 ; let start = Math . pow ( 10 , n - 1 ) ; let end = ( Math . pow ( 10 , n ) ) - 1 ; for ( let i = start ; i < end + 1 ; i ++ ) { if ( isArmstrong ( i , n ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } document . write ( " " + CalculateXOR + " " ) ; document . write ( " " + CalculateOR + " " ) ; } let n = 4 ; CalculateXORandOR ( n ) ;
Perfect Cube | Function to check if a number is a perfect Cube or not ; Iterate from 1 - N ; Find the cube of every number ; Check if cube equals N or not ; Driver code ; Function call
function perfectCube ( N ) { let cube ; for ( let i = 0 ; i <= N ; i ++ ) { cube = i * i * i ; if ( cube === N ) { document . write ( " " ) ; return ; } else if ( cube > N ) { document . write ( " " ) ; return ; } } } let N = 216 ; perfectCube ( N ) ;
Perfect Cube | Function to check if a number is a perfect Cube using inbuilt function ; If cube of cube_root is equals to N , then print Yes Else print No ; Driver 's code ; Function call to check N is cube or not
function perfectCube ( N ) { let cube_root ; cube_root = Math . round ( Math . cbrt ( N ) ) ; if ( ( cube_root * cube_root * cube_root ) == N ) { document . write ( " " ) ; return ; } else { document . write ( " " ) ; return ; } } let N = 125 ; perfectCube ( N ) ;
Check if given array can be made 0 with given operations performed any number of times | Function to whether the array can be made zero or not ; Count for even elements ; Count for odd elements ; Traverse the array to count the even and odd ; If arr [ i ] is odd ; If arr [ i ] is even ; Check if count of even is zero or count of odd is zero ; Driver 's Code
function check ( arr , N ) { let even = 0 ; let odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) { odd ++ ; } else { even ++ ; } } if ( even == N odd == N ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 1 , 1 , 3 ] ; let N = arr . length ; check ( arr , N ) ;
Calculate sum of all integers from 1 to N , excluding perfect power of 2 | Function to find the required summation ; Find the sum of first N integers using the formula ; Find the sum of numbers which are exact power of 2 by using the formula ; Print the final Sum ; Driver code ; Function to find the sum
function findSum ( N ) { var sum = ( N ) * ( N + 1 ) / 2 ; var r = ( Math . log ( N ) / Math . log ( 2 ) ) + 1 ; var expSum = ( Math . pow ( 2 , r ) ) - 1 ; document . write ( sum - expSum ) ; } var N = 2 ; findSum ( N ) ;
Largest Even and Odd N | Function to print the largest N - digit even and odd numbers of base B ; Initialise the Number ; If Base B is even , then B ^ n will give largest Even number of N + 1 digit ; To get even number of N digit subtract 2 from B ^ n ; To get odd number of N digit subtract 1 from B ^ n ; If Base B is odd , then B ^ n will give largest Odd number of N + 1 digit ; To get even number of N digit subtract 1 from B ^ n ; To get odd number of N digit subtract 2 from B ^ n ; Driver 's Code ; Function to find the numbers
function findNumbers ( n , b ) { var even = 0 , odd = 0 ; if ( b % 2 == 0 ) { even = Math . pow ( b , n ) - 2 ; odd = Math . pow ( b , n ) - 1 ; } else { even = Math . pow ( b , n ) - 1 ; odd = Math . pow ( b , n ) - 2 ; } document . write ( " " + even + " " ) ; document . write ( " " + odd ) ; } var N = 2 , B = 5 ; findNumbers ( N , B ) ;
Minimum divisor of a number to make the number perfect cube | Returns the minimum divisor ; Since 2 is only even prime , compute its power seprately . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; if n is a prime number ; Driven Program
function findMinNumber ( n ) { var count = 0 , ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 3 != 0 ) ans *= Math . pow ( 2 , ( count % 3 ) ) ; for ( var i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 3 != 0 ) ans *= Math . pow ( i , ( count % 3 ) ) ; } if ( n > 2 ) ans *= n ; return ans ; } var n = 128 ; document . write ( findMinNumber ( n ) ) ;
Check whether the number can be made perfect square after adding K | Function to check whether the number can be made perfect square after adding K ; Computing the square root of the number ; Print Yes if the number is a perfect square ; Driver code
function isPerfectSquare ( x ) { var sr = Math . round ( Math . sqrt ( x ) ) ; if ( sr * sr == x ) document . write ( " " ) ; else document . write ( " " ) ; } var n = 7 , k = 2 ; isPerfectSquare ( n + k ) ;
Number of times the largest Perfect Cube can be subtracted from N | Function to return the count of steps ; Variable to store the count of steps ; Iterate while N > 0 ; Get the largest perfect cube and subtract it from N ; Increment steps ; Return the required count ; Driver code
function countSteps ( n ) { let steps = 0 ; while ( n ) { let largest = Math . floor ( Math . cbrt ( n ) ) ; n -= ( largest * largest * largest ) ; steps ++ ; } return steps ; } let n = 150 ; document . write ( countSteps ( n ) ) ;
Product of all Subsets of a set formed by first N natural numbers | Function to find the product of all elements in all subsets in natural numbers from 1 to N ; Driver Code
function product ( N ) { let ans = 1 ; let val = Math . pow ( 2 , N - 1 ) ; for ( let i = 1 ; i <= N ; i ++ ) { ans *= Math . pow ( i , val ) ; } return ans ; } let N = 2 ; document . write ( product ( N ) ) ;
Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius | javascript program to find the radii of the three tangent circles of equal radius when the radius of the circumscribed circle is given ; Driver code
function threetangcircle ( R ) { document . write ( " " + 0.4645 * R ) ; } var R = 4 ; threetangcircle ( R ) ;
Number of common tangents between two circles if their centers and radius is given | Javascript program to find the number of common tangents between the two circles ; Driver code
function circle ( x1 , y1 , x2 , y2 , r1 , r2 ) { var distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; var radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ; if ( distSq == radSumSq ) return 1 ; else if ( distSq > radSumSq ) return - 1 ; else return 0 ; } var x1 = - 10 , y1 = 8 ; var x2 = 14 , y2 = - 24 ; var r1 = 30 , r2 = 10 ; var t = circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; if ( t == 1 ) document . write ( " " ) ; else if ( t < 0 ) document . write ( " " ) ; else document . write ( " " ) ;
Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles | javascript program to find the ratio of the distance between the centres of the circles and the povar of intersection of two transverse common tangents to the circles which do not touch each other ; Function to find the ratio ; Driver code
function GCD ( a , b ) { return ( b != 0 ? GCD ( b , a % b ) : a ) ; } function ratiotang ( r1 , r2 ) { document . write ( " " + r1 / GCD ( r1 , r2 ) + " " + r2 / GCD ( r1 , r2 ) ) ; } var r1 = 4 , r2 = 8 ; ratiotang ( r1 , r2 ) ;
Program to find the number of region in Planar Graph | Function to return the number of regions in a Planar Graph ; Driver code
function Regions ( Vertices , Edges ) { var R = Edges + 2 - Vertices ; return R ; } var V = 5 , E = 7 ; document . write ( Regions ( V , E ) ) ;
Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles | Function to find the GCD ; Function to find the ratio ; Driver code
function GCD ( a , b ) { return ( b != 0 ? GCD ( b , a % b ) : a ) ; } function ratiotang ( r1 , r2 ) { document . write ( " " + r1 / GCD ( r1 , r2 ) + " " + r2 / GCD ( r1 , r2 ) ) ; } var r1 = 4 , r2 = 6 ; ratiotang ( r1 , r2 ) ;
Length of the transverse common tangent between the two non intersecting circles | Function to find the length of the transverse common tangent ; Driver code
function lengthOfTangent ( r1 , r2 , d ) { document . write ( " " + " " + Math . sqrt ( Math . pow ( d , 2 ) - Math . pow ( ( r1 + r2 ) , 2 ) ) ) ; } var r1 = 4 , r2 = 6 , d = 12 ; lengthOfTangent ( r1 , r2 , d ) ;