codeparrot/xlcost-text-to-code huggingface dataset:
Minimize steps required to make two values equal by repeated division by any of their prime factor which is less than M | Stores the prime factor of numbers ; Function to find GCD of a and b ; Base Case ; Otherwise , calculate GCD ; Function to precompute the prime numbers till 1000000 ; Initialize all the positions with their respective values ; Iterate over the range [ 2 , sqrt ( 10 ^ 6 ) ] ; If i is prime number ; Mark it as the factor ; Utility function to count the number of steps to make X and Y equal ; Initialise steps ; Iterate x is at most 1 ; Divide with the smallest prime factor ; If X and Y can 't be  made equal ; Return steps ; Function to find the minimum number of steps required to make X and Y equal ; Generate all the prime factors ; Calculate GCD of x and y ; Divide the numbers by their gcd ; If not possible , then return - 1 ; ; Return the resultant number of steps ; Driver Code
var primes = Array ( 1000006 ) . fill ( 0 ) ; function gcd ( a , b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } function preprocess ( ) { for ( i = 1 ; i <= 1000000 ; i ++ ) primes [ i ] = i ; for ( i = 2 ; i * i <= 1000000 ; i ++ ) { if ( primes [ i ] == i ) { for ( j = 2 * i ; j <= 1000000 ; j += i ) { if ( primes [ j ] == j ) primes [ j ] = i ; } } } } function Steps ( x , m ) { var steps = 0 ; var flag = false ; while ( x > 1 ) { if ( primes [ x ] > m ) { flag = true ; break ; } x /= primes [ x ] ; steps ++ ; } if ( flag ) return - 1 ; return steps ; } function minimumSteps ( x , y , m ) { preprocess ( ) ; var g = gcd ( x , y ) ; x = x / g ; y = y / g ; var x_steps = Steps ( x , m ) ; var y_steps = Steps ( y , m ) ; if ( x_steps == - 1 y_steps == - 1 ) return - 1 ; return x_steps + y_steps ; } var X = 160 ; var Y = 180 ; var M = 10 ; document . write ( minimumSteps ( X , Y , M ) ) ;
Length of longest subsequence consisting of Non | Function to check if n is a deficient number or not ; Stores sum of divisors ; Iterate over the range [ 1 , sqrt ( N ) ] ; If n is divisible by i ; If divisors are equal , add only one of them ; Otherwise add both ; Function to print the longest subsequence which does not contain any deficient numbers ; Stores the count of array elements which are non - deficient ; Traverse the array ; If element is non - deficient ; Return the answer ; Driver Code
function isNonDeficient ( n ) { let sum = 0 ; for ( let i = 1 ; i <= Math . floor ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( Math . floor ( n / i ) == i ) { sum = sum + i ; } else { sum = sum + i ; sum = sum + Math . floor ( n / i ) ; } } } return sum >= 2 * n ; } function LongestNonDeficientSubsequence ( arr , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isNonDeficient ( arr [ i ] ) ) { res += 1 ; } } return res ; } let arr = [ 13 , 55 , 240 , 32 , 24 , 27 , 56 , 80 , 100 , 330 , 89 ] ; let N = arr . length ; document . write ( LongestNonDeficientSubsequence ( arr , N ) ) ;
Number of subarrays consisting only of Pronic Numbers | Function to check if a number is pronic number or not ; Iterate over the range [ 1 , sqrt ( N ) ] ; Return true if N is pronic ; Otherwise , return false ; Function to count the number of subarrays consisting of pronic numbers ; Stores the count of subarrays ; Stores the number of consecutive array elements which are pronic ; Traverse the array ; If i is pronic ; Return the total count ; Driver code
function isPronic ( n ) { let range = Math . sqrt ( n ) ; for ( let i = 0 ; i < range + 1 ; i ++ ) { if ( i * ( i + 1 ) == n ) return true ; } return false ; } function countSub ( arr , n ) { let ans = 0 ; let ispro = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPronic ( arr [ i ] ) ) ispro += 1 ; else ispro = 0 ; ans += ispro ; } return ans ; } let arr = [ 5 , 6 , 12 , 3 , 4 ] ; let n = arr . length ; document . write ( countSub ( arr , n ) ) ;
Replace all array elements with the nearest power of its previous element | Function to calculate log x for given base ; Function to replace all array elements with the nearest power of previous adjacent nelement ; For the first element , set the last array element to its previous element ; Traverse the array ; Find K for which x ^ k is nearest to arr [ i ] ; Find the power to x nearest to arr [ i ] ; Update x ; Driver Code ; Function Call ; Display the array
function LOG ( a , b ) { return parseInt ( Math . log ( a ) / Math . log ( b ) ) ; } function repbyNP ( arr , n ) { let x = arr [ n - 1 ] ; for ( let i = 0 ; i < n ; i ++ ) { let k = LOG ( arr [ i ] , x ) ; let temp = arr [ i ] ; if ( Math . abs ( Math . pow ( x , k ) - arr [ i ] ) < Math . abs ( Math . pow ( x , k + 1 ) - arr [ i ] ) ) arr [ i ] = Math . pow ( x , k ) ; else arr [ i ] = Math . pow ( x , k + 1 ) ; x = temp ; } } let arr = [ 2 , 4 , 6 , 3 , 11 ] ; let n = arr . length ; repbyNP ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;
Remaining array element after repeated removal of last element and subtraction of each element from next adjacent element | Function to find the last remaining array element after performing the given operations repeatedly ; Stores the resultant sum ; Traverse the array ; Increment sum by arr [ i ] * coefficient of i - th term in ( x - y ) ^ ( N - 1 ) ; Update multiplier ; Return the resultant sum ; Driver Code
function lastElement ( arr , n ) { let sum = 0 ; let multiplier = n % 2 == 0 ? - 1 : 1 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] * multiplier ; multiplier = multiplier * ( n - 1 - i ) / ( i + 1 ) * ( - 1 ) ; } return sum ; } let arr = [ 3 , 4 , 2 , 1 ] ; let N = arr . length ; document . write ( lastElement ( arr , N ) ) ;
Maximize count of pairs whose bitwise XOR is even by replacing such pairs with their Bitwise XOR | Function to maximize the count of pairs with even XOR possible in an array by given operations ; Stores count of odd array elements ; Traverse the array ; If arr [ i ] is odd ; Stores the total number of even pairs ; Input ; Function call to count the number of pairs whose XOR is even
function countPairs ( arr , N ) { let odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) odd ++ ; } let ans = ( N - odd + Math . floor ( odd / 2 ) - 1 ) + Math . floor ( odd / 2 ) ; return ans ; } let arr = [ 4 , 6 , 1 , 3 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;
Maximize count of pairs whose Bitwise AND exceeds Bitwise XOR by replacing such pairs with their Bitwise AND | Function to count the number of pairs whose Bitwise AND is greater than the Bitwise XOR ; Stores the frequency of MSB of array elements ; Traverse the array ; Increment count of numbers having MSB at log ( arr [ i ] ) ; Stores total number of pairs ; Traverse the Map ; Return total count of pairs ; Driver Code
function countPairs ( arr , N ) { var freq = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( freq . has ( parseInt ( Math . log2 ( arr [ i ] ) ) ) ) { freq . set ( parseInt ( Math . log2 ( arr [ i ] ) ) , freq . get ( parseInt ( Math . log2 ( arr [ i ] ) ) ) + 1 ) ; } else { freq . set ( parseInt ( Math . log2 ( arr [ i ] ) ) , 1 ) ; } } var pairs = 0 ; freq . forEach ( ( value , key ) => { pairs += value - 1 ; } ) ; return pairs ; } var arr = [ 12 , 9 , 15 , 7 ] ; var N = arr . length ; document . write ( countPairs ( arr , N ) ) ;
Maximize difference between odd and even indexed array elements by swapping unequal adjacent bits in their binary representations | Function to count total number of bits present in a number ; Function to count total set bits in a number ; Stores the count of set bits ; Right shift by 1 ; Return the final count ; Function to find maximum number by shifting two unequal bits ; Count set bits in number n ; Iterate the string bits ; Function to find minimum number by shifting two unequal bits ; Iterate the set bit ; Function to find the maximum difference ; Stores the maximum difference ; Stores the sum of elements placed at odd positions ; Stores the sum of elements placed at even positions ; Traverse the array ; Update CaseOne ; Stores the maximum difference ; Assign value O ; Traverse the array ; Update caseTwo ; Return maximum of caseOne and CaseTwo ; Drivers Code ; Function Call
function countBit ( n ) { return parseInt ( log2 ( n ) ) + 1 ; } function countSetBit ( n ) { let ans = 0 ; while ( n > 0 ) { ans += ( n & 1 ) ; n >>= 1 ; } return ans ; } function maximize ( n ) { let bits = countBit ( n ) ; let setBits = countSetBit ( n ) ; let ans = 0 ; for ( let i = 0 ; i < bits ; i ++ ) { if ( i < setBits ) ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } function minimize ( n ) { let setBits = countSetBit ( n ) ; let ans = 0 ; for ( let i = 0 ; i < setBits ; i ++ ) { ans |= 1 ; if ( i != setBits - 1 ) ans <<= 1 ; } return ans ; } function maxDiff ( arr ) { let caseOne = 0 ; let SumOfOdd = 0 ; let SumOfeven = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 ) SumOfOdd += minimize ( arr [ i ] ) ; else SumOfeven += maximize ( arr [ i ] ) ; } caseOne = Math . abs ( SumOfOdd - SumOfeven ) ; let caseTwo = 0 ; SumOfOdd = 0 ; SumOfeven = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 ) SumOfOdd += maximize ( arr [ i ] ) ; else SumOfeven += minimize ( arr [ i ] ) ; } caseTwo = Math . abs ( SumOfOdd - SumOfeven ) ; return Math . max ( caseOne , caseTwo ) ; } let arr = [ 54 , 32 , 11 , 23 ] ; document . write ( maxDiff ( arr ) ) ;
Sum of numbers obtained by the count of set and non | Functino to find the number after processing the diagonal elements ; Store the required number ; Checking for each position ; Store the number of set bits & non - set bits at position i ; Traverse the diagonal elements ; Update count of S if current element is set at position i ; Else update NS ; If number of set bits is > number of non - set bits , add set bits value to the ans ; Return the answer ; Function to find the sum of the numbers generated after processing both the diagonals of the matrix ; Store the primary diagonal elements ; Store the secondary diagonal elements ; Function Call to get the required numbers and return their sum ; Driver Code ; Function Call
function processDiagonal ( arr ) { let ans = 0 ; let getBit = 1 ; for ( let i = 0 ; i < 32 ; i ++ ) { let S = 0 ; let NS = 0 ; for ( let j = 0 ; j < arr . length ; j ++ ) { if ( getBit & arr [ j ] ) S += 1 ; else NS += 1 ; } if ( S > NS ) ans += Math . pow ( 2 , i ) ; getBit <<= 1 ; } return ans ; } function findSum ( mat ) { let i = 0 ; let j = 0 ; let priDiag = [ ] ; while ( i < mat . length ) { priDiag . push ( mat [ i ] [ j ] ) ; i += 1 ; j += 1 ; } i = 0 ; j = mat . length - 1 ; let secDiag = [ ] ; while ( i < mat . length ) { secDiag . push ( mat [ i ] [ j ] ) ; i += 1 ; j -= 1 ; } return processDiagonal ( priDiag ) + processDiagonal ( secDiag ) ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; document . write ( findSum ( mat ) ) ;
Minimize difference between two sequences obtained by splitting first N powers of 2 | Function to partition first N powers of 2 into two subsequences with minimum difference between their sum ; Largest element in the first part ; Place N / 2 - 1 smallest elements in the first sequence ; Place remaining N / 2 elements in the second sequence ; Print the minimum difference ; Driver Code
function minimumDifference ( N ) { var sum1 = ( 1 << N ) , sum2 = 0 ; for ( i = 1 ; i < N / 2 ; i ++ ) sum1 += ( 1 << i ) ; for ( i = N / 2 ; i < N ; i ++ ) sum2 += ( 1 << i ) ; document . write ( sum1 - sum2 ) ; } var N = 4 ; minimumDifference ( N ) ;
Check whether N can be a Perfect Cube after adding or subtracting K | Function to check if a number is a perfect Cube or not ; Driver code
function isPerfectCube ( x ) { var cr = Math . round ( Math . cbrt ( x ) ) ; return ( cr * cr * cr == x ) ; } function canBePerfectCube ( N , K ) { if ( isPerfectCube ( N + K ) || isPerfectCube ( N - K ) ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 7 , K = 1 ; canBePerfectCube ( N , K ) ; N = 5 , K = 4 ; canBePerfectCube ( N , K ) ; N = 7 , K = 2 ; canBePerfectCube ( N , K ) ;
Floor square root without using sqrt ( ) function : Recursive | Function to find the square root of the number N using BS ; If the range is still valid ; Find the mid - value of the range ; Base Case ; Condition to check if the left search space is useless ; Driver Code
function sqrtSearch ( low , high , N ) { if ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( ( mid * mid <= N ) && ( ( mid + 1 ) * ( mid + 1 ) > N ) ) { return mid ; } else if ( mid * mid < N ) { return sqrtSearch ( mid + 1 , high , N ) ; } else { return sqrtSearch ( low , mid - 1 , N ) ; } } return low ; } var N = 25 ; document . write ( sqrtSearch ( 0 , N , N ) ) ;
Common divisors of N numbers | Function to calculate gcd of two numbers ; Function to print all the common divisors ; Variable to find the gcd of N numbers ; Set to store all the common divisors ; Finding GCD of the given N numbers ; Finding divisors of the HCF of n numbers ; Print all the divisors ; Driver 's Code ; Function to print all the common divisors
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function printAllDivisors ( arr , N ) { let g = arr [ 0 ] ; let divisors = new Set ( ) ; for ( let i = 1 ; i < N ; i ++ ) { g = gcd ( arr [ i ] , g ) ; } for ( let i = 1 ; i * i <= g ; i ++ ) { if ( g % i == 0 ) { divisors . add ( i ) ; if ( Math . floor ( g / i ) != i ) divisors . add ( Math . floor ( g / i ) ) ; } } for ( let it of divisors . values ( ) ) document . write ( it + " " ) ; } let arr = [ 6 , 90 , 12 , 18 , 30 , 24 ] ; let n = arr . length ; printAllDivisors ( arr , n ) ;
Recursive Program to print multiplication table of a number | Function that print the table of a given number using recursion ; Base Case ; Print the table for current iteration ; Recursive call to next iteration ; Input number whose table is to print ; Function call to print the table
function mul_table ( N , i ) { if ( i > 10 ) return ; document . write ( N + " " + i + " " + N * i + " " ) ; return mul_table ( N , i + 1 ) ; } var N = 8 ; mul_table ( N , 1 ) ;
Find the largest composite number that divides N but is strictly lesser than N | Function to check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function that find the largest composite number which divides N and less than N ; Find the prime number ; Driver 's Code ; Get the smallest prime factor ; Check if ( N / a ) is prime or not If Yes print " - 1" ; Else print largest composite number ( N / a )
function isPrime ( n ) { if ( n <= 1 ) return false ; var i ; for ( i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function getSmallestPrimefactor ( n ) { var i ; for ( i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return i ; } } var N = 100 ; var a ; a = getSmallestPrimefactor ( N ) ; if ( isPrime ( N / a ) ) document . write ( " " ) ; else document . write ( N / a ) ;
XOR and OR of all N | Function to check if a number is palindrome or not ; Convert the num n to string ; Iterate over string to check whether it is palindromic or not ; Function to find XOR of all N - digits palindrome number ; To store the XOR and OR of all palindromic number ; Starting N - digit palindromic number ; Ending N - digit palindromic number ; Iterate over starting and / ending number ; To check if i is palindromic or not ; Print the XOR and OR of all palindromic number ; Driver Code
function ispalin ( num ) { let s = num . toString ( ) ; let st = 0 , ed = s . length - 1 ; while ( st <= ed ) { if ( s [ st ] != s [ ed ] ) return false ; st ++ ; ed -- ; } return true ; } 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 ; i ++ ) { if ( ispalin ( i ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } document . write ( " " + CalculateXOR ) ; document . write ( " " + CalculateOR ) ; } let n = 4 ; CalculateXORandOR ( n ) ;
Sum of all palindromic numbers lying in the range [ L , R ] for Q queries | pref [ ] array to precompute the sum of all palindromic number ; Function that return number num if num is palindromic else return 0 ; Convert num to string ; Function to precompute the sum of all palindrome numbers upto 100000 ; checkPalindrome ( ) return the number i if i is palindromic else return 0 ; Function to print the sum for each query ; Function to print sum of all palindromic numbers between [ L , R ] ; Function that pre computes the sum of all palindromic numbers ; Iterate over all Queries to print the sum ; Queries ; Function that print the the sum of all palindromic number in Range [ L , R ]
var pref = Array ( 100001 ) . fill ( 0 ) ; function checkPalindrome ( num ) { var str = num . toString ( ) ; var l = 0 , r = str . length - 1 ; while ( l < r ) { if ( str [ l ] != str [ r ] ) { return 0 ; } l ++ ; r -- ; } return num ; } function preCompute ( ) { for ( var i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + checkPalindrome ( i ) ; } } function printSum ( L , R ) { document . write ( pref [ R ] - pref [ L - 1 ] + " " ) ; } function printSumPalindromic ( arr , Q ) { preCompute ( ) ; for ( var i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } var Q = 2 ; var arr = [ [ 10 , 13 ] , [ 12 , 21 ] ] ; printSumPalindromic ( arr , Q ) ;
Sum of alternating sign Squares of first N natural numbers | Function to calculate the alternating sign sum ; Variable to store the sum ; Loop to iterate each number from 1 to N ; The alternating sign is put by checking if the number is even or odd ; Add the square with the sign ; Add the square with the sign ; Driver code
function summation ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) sum += ( i * i ) ; else sum -= ( i * i ) ; } return sum ; } let N = 2 ; document . write ( summation ( N ) ) ;
Sum of alternating sign Squares of first N natural numbers | Function to calculate the alternating sign sum ; Variable to store the absolute sum ; Variable to store the sign ; Variable to store the resultant sum ; Driver code
function summation ( n ) { var abs_sum = n * ( n + 1 ) / 2 ; var sign = n + 1 % 2 == 0 ? 1 : - 1 ; var result_sum = sign * abs_sum ; return result_sum ; } var N = 2 ; document . write ( summation ( N ) ) ;
Count pairs from 1 to N such that their Sum is divisible by their XOR | Function to count pairs ; variable to store count ; Generate all possible pairs such that 1 <= x < y < n ; Driver code
function countPairs ( n ) { let count = 0 ; for ( let x = 1 ; x < n ; x ++ ) { for ( let y = x + 1 ; y <= n ; y ++ ) { if ( ( y + x ) % ( y ^ x ) == 0 ) count ++ ; } } return count ; } let n = 6 ; document . write ( countPairs ( n ) ) ;
Count pairs in array such that one element is power of another | Function to check if given number number y is power of x ; log function to calculate value ; compare to the result1 or result2 both are equal ; Function to find pairs from array ; Iterate through all pairs ; Increment count if one is the power of other ; Driver code
function isPower ( x , y ) { var res1 = parseInt ( Math . log ( y ) / Math . log ( x ) ) ; var res2 = Math . log ( y ) / Math . log ( x ) ; return ( res1 == res2 ) ; } function countPower ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) if ( isPower ( arr [ i ] , arr [ j ] ) || isPower ( arr [ j ] , arr [ i ] ) ) res ++ ; return res + 1 ; } var a = [ 16 , 2 , 3 , 9 ] ; var n = a . length ; document . write ( countPower ( a , n ) ) ;
Find the original Array using XOR values of all adjacent elements | XOR of all elements from 1 to N ; Function to find the Array from the XOR Array ; Take a vector to store the permutation ; XOR of N natural numbers ; Loop to find the XOR of adjacent elements of the XOR Array ; Loop to find the other elements of the permutation ; Finding the next and next elements ; Driver Code ; Required Permutation
function xor_all_elements ( n ) { switch ( n & 3 ) { case 0 : return n ; case 1 : return 1 ; case 2 : return n + 1 ; case 3 : return 0 ; } } function findArray ( xorr , n ) { let arr = [ ] ; let xor_all = xor_all_elements ( n ) ; let xor_adjacent = 0 ; for ( let i = 0 ; i < n - 1 ; i += 2 ) { xor_adjacent = xor_adjacent ^ xorr [ i ] ; } let last_element = xor_all ^ xor_adjacent ; arr . push ( last_element ) ; for ( let i = n - 2 ; i >= 0 ; i -- ) { last_element = xorr [ i ] ^ last_element ; arr . push ( last_element ) ; } return arr ; } let arr = [ ] ; let xorr = [ 7 , 5 , 3 , 7 ] ; let n = 5 ; arr = findArray ( xorr , n ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { document . write ( arr [ i ] + " " ) ; }
Sum of non | Function to return a vector which consists the sum of four portions of the matrix ; Iterating through the matrix ; Condition for selecting all values before the second diagonal of metrics ; Top portion of the matrix ; Left portion of the matrix ; Bottom portion of the matrix ; Right portion of the matrix ; Adding all the four portions into a vector ; Driver code
function sumOfParts ( arr , N ) { var sum_part1 = 0 , sum_part2 = 0 , sum_part3 = 0 , sum_part4 = 0 ; var totalsum = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { if ( i + j < N - 1 ) { if ( i < j && i != j && i + j > 0 ) sum_part1 += arr [ i ] [ j ] ; else if ( i != j ) sum_part2 += arr [ i ] [ j ] ; } else { if ( i > j && i + j != N - 1 ) sum_part3 += arr [ i ] [ j ] ; else { if ( i + j != N - 1 && i != j ) sum_part4 += arr [ i ] [ j ] ; } } } } totalsum = sum_part1 + sum_part2 + sum_part3 + sum_part4 ; return totalsum ; } var N = 4 ; var arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; document . write ( sumOfParts ( arr , N ) ) ;
Check if X and Y can be made zero by using given operation any number of times | Function to check if X and Y can be made equal to zero by using given operation any number of times ; Check for the two conditions ; Driver code
function ifPossible ( X , Y ) { if ( X > Y ) { var temp = X ; X = Y ; Y = temp ; } if ( ( X + Y ) % 5 == 0 && 3 * X >= 2 * Y ) document . write ( " " ) ; else document . write ( " " ) ; } var X = 33 , Y = 27 ; ifPossible ( X , Y ) ;
Largest Even and Odd N | Function to print the largest n - digit even and odd numbers in hexadecimal number system ; Append ' F ' ( N - 1 ) times ; Append ' E ' for an even number ; Append ' F ' for an odd number ; Driver code
function findNumbers ( n ) { var ans = " " . repeat ( n - 1 ) ; var even = ans + ' ' ; var odd = ans + ' ' ; document . write ( " " + even + " " ) ; document . write ( " " + odd + " " ) ; } var n = 2 ; findNumbers ( n ) ;
Program to compute log a to any base b ( logb a ) | Javascript program to find log ( a ) on any base b ; Driver code
function log_a_to_base_b ( a , b ) { return parseInt ( Math . log ( a ) / Math . log ( b ) ) ; } var a = 3 ; var b = 2 ; document . write ( log_a_to_base_b ( a , b ) + " " ) ; a = 256 ; b = 4 ; document . write ( log_a_to_base_b ( a , b ) ) ;
Program to compute log a to any base b ( logb a ) | Recursive function to compute log a to the base b ; Driver code
function log_a_to_base_b ( a , b ) { var rslt = ( a > b - 1 ) ? 1 + log_a_to_base_b ( parseInt ( a / b ) , b ) : 0 ; return rslt ; } var a = 3 ; var b = 2 ; document . write ( log_a_to_base_b ( a , b ) + " " ) ; a = 256 ; b = 4 ; document . write ( log_a_to_base_b ( a , b ) ) ;
Largest and Smallest N | Function to return the largest N - digit number in Hexa - Decimal Number System ; Append ' F ' N times " a " . repeat ( 10 ) ; Function to return the smallest N - digit number in Hexa - Decimal Number System ; Append '0' ( N - 1 ) times to 1 ; Function to print the largest and smallest N - digit Hexa - Decimal number ; Driver code
function findLargest ( N ) { var largest = " " . repeat ( N ) ; return largest ; } function findSmallest ( N ) { var smallest = " " + " " . repeat ( N - 1 ) ; return smallest ; } function print ( largest ) { document . write ( " " + findLargest ( largest ) + " " ) ; document . write ( " " + findSmallest ( largest ) + " " ) ; } var N = 4 ; print ( N ) ;