dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function expressDigit ( arr , n ) { var min = 9 , index = 0 , temp = 0 ; temp = arr [ 0 ] ; for ( i = 1 ; i < 10 ; i ++ ) { if ( arr [ i ] < min ) { min = arr [ i ] ; index = i ; } } if ( temp < min ) { document . write ( 1 ) ; for ( i = 1 ; i <= temp + 1 ; i ++ ) document . write ( 0 ) ; } else { for ( i = 0 ; i < min ; i ++ ) document . write ( index ) ; document . write ( index ) ; } } var arr = [ 2 , 2 , 1 , 2 , 1 , 1 , 3 , 1 , 1 , 1 ] ; var N = 10 ; expressDigit ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countDigits ( num ) { var cnt = 0 ; while ( num > 0 ) { cnt ++ ; num = parseInt ( num / 10 ) ; } return cnt ; } function sumFromStart ( num , n , rem ) { num = ( parseInt ( num / Math . pow ( 10 , rem ) ) ) ; var sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num = parseInt ( num / 10 ) ; } return sum ; } function sumFromEnd ( num , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += ( num % 10 ) ; num = parseInt ( num / 10 ) ; } return sum ; } function getAverage ( n , k , l ) { var totalDigits = countDigits ( n ) ; if ( totalDigits < ( k + l ) ) return - 1 ; var sum1 = sumFromEnd ( n , l ) ; var sum2 = sumFromStart ( n , k , totalDigits - k ) ; return ( ( sum1 + sum2 ) / ( k + l ) ) ; } var n = 123456 , k = 2 , l = 3 ; document . write ( getAverage ( n , k , l ) ) ;

Accumulator variables: cnt, i, sum
Iterator variables: i
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: i, maxi1, maxi2
Iterator variables: i
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: i, sumDigits
Javascript program:
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 ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ;

Index/key variables: i, m, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
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 ( " " ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
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 ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
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 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: cnt, i, sum
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: j
Iterator variables: j
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ;

Accumulator variables: i, k, r
Iterator variables: i, k, r
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: ans, i, res
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
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 ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
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 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function CheckSubarray ( arr , N ) { let presum = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 1 ; i <= N ; i += 1 ) { presum [ i ] = presum [ i - 1 ] + arr [ i - 1 ] ; } for ( let i = 1 ; i <= N ; i += 1 ) { for ( let j = i ; j <= N ; j += 1 ) { if ( ( presum [ j ] - presum [ i - 1 ] ) % N == 0 ) { document . write ( ( i - 1 ) + " " + ( j - 1 ) ) ; return ; } } } document . write ( - 1 ) ; } let arr = [ 7 , 5 , 3 , 7 ] ; let N = arr . length ; CheckSubarray ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function CheckSubarray ( arr , N ) { let presum = new Array ( N + 1 ) ; for ( let i = 0 ; i < ( N + 1 ) ; i ++ ) presum [ i ] = 0 ; for ( let i = 1 ; i <= N ; i += 1 ) { presum [ i ] = presum [ i - 1 ] + arr [ i - 1 ] ; } let moduloclass = new Array ( N ) ; for ( let i = 0 ; i < N ; i += 1 ) { moduloclass [ i ] = [ ] ; } for ( let i = 1 ; i <= N ; i += 1 ) { moduloclass [ presum [ i ] % N ] . push ( i - 1 ) ; } if ( moduloclass [ 0 ] . length > 0 ) { document . write ( 0 + " " + moduloclass [ 0 ] [ 0 ] ) ; return ; } for ( let i = 1 ; i < N ; i += 1 ) { if ( moduloclass [ i ] . length >= 2 ) { document . write ( moduloclass [ i ] [ 0 ] + 1 + " " + moduloclass [ i ] [ 1 ] ) ; return ; } } } let arr = [ 7 , 3 , 5 , 2 ] ; let N = arr . length ; CheckSubarray ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countBits ( n ) { let count = 0 ; while ( n ) { count ++ ; n >>= 1 ; } return count ; } function findNearestNumber ( n ) { let cnt = countBits ( n ) ; cnt -= 1 ; if ( cnt % 2 ) { return 1 << ( cnt + 1 ) ; } else { let tempnum = 0 ; for ( let i = 0 ; i <= cnt ; i += 2 ) tempnum += 1 << i ; if ( tempnum < n ) { return ( 1 << ( cnt + 2 ) ) ; } else if ( tempnum == n ) return n ; for ( let i = 0 ; i <= cnt ; i += 2 ) { tempnum -= ( 1 << i ) ; if ( tempnum < n ) return tempnum += ( 1 << i ) ; } } } let n = 19 ; document . write ( findNearestNumber ( n ) ) ;

Accumulator variables: cnt, count, i, tempnum
Iterator variables: i
Javascript program:
function constructString ( n ) { var s = " " ; for ( var i = 0 ; i < n ; i ++ ) { s += " " ; } return s ; } function binaryToDecimal ( n ) { var num = n ; var dec_value = 0 ; var base = 1 ; var len = num . length ; for ( var i = len - 1 ; i >= 0 ; i -- ) { if ( num . charAt ( i ) == ' ' ) dec_value += base ; base = base * 2 ; } return dec_value ; } function findNumber ( n ) { var s = constructString ( n - 1 ) ; var num = binaryToDecimal ( s ) ; return num ; } var n = 4 ; document . write ( findNumber ( n ) ) ;

Accumulator variables: dec_value, i, s
Iterator variables: i
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function push ( head_ref , data ) { var new_node = new Node ( ) ; new_node . data = data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } function bitonic_point ( node ) { if ( node == null ) return - 1 ; if ( node . next == null ) return - 1 ; if ( node . data > node . next . data ) return - 1 ; while ( node . next != null ) { if ( node . data > node . next . data ) break ; node = node . next ; } let bitonicPoint = node . data ; while ( node . next != null ) { if ( node . data < node . next . data ) return - 1 ; node = node . next ; } return bitonicPoint ; } var head = null ; head = push ( head , 100 ) ; head = push ( head , 201 ) ; head = push ( head , 399 ) ; head = push ( head , 490 ) ; head = push ( head , 377 ) ; head = push ( head , 291 ) ; head = push ( head , 100 ) ; document . write ( bitonic_point ( head ) ) ;

Class/struct names: Node
Javascript program:
function MinRemove ( a , n , k ) { let cnt = new Array ( k ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) cnt [ 0 ] ++ ; else if ( cnt [ a [ i ] - 1 ] > 0 ) { cnt [ a [ i ] - 1 ] -- ; cnt [ a [ i ] ] ++ ; } } return n - ( k * cnt [ k - 1 ] ) ; } let a = [ 0 , 1 , 2 , 3 , 4 , 0 , 1 , 0 , 1 , 2 , 3 , 4 ] , k = 5 ; let n = a . length ; document . write ( MinRemove ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mosaic ( n ) { var i , ans = 1 ; for ( i = 2 ; i <= n ; i ++ ) { if ( n % i == 0 && n > 0 ) { var count = 0 ; while ( n % i == 0 ) { n /= i ; count ++ ; } ans *= count * i ; } } return ans ; } function nMosaicNumbers ( n ) { for ( var i = 1 ; i <= n ; i ++ ) document . write ( mosaic ( i ) + " " ) ; } var n = 10 ; nMosaicNumbers ( n ) ;

Accumulator variables: ans, count, i, n
Iterator variables: i
Javascript program:
function countNodes ( N , X ) { let height = Math . floor ( Math . log ( N ) / Math . log ( 2 ) ) ; if ( X > height ) { document . write ( " " ) ; return ; } if ( N == 1 ) { document . write ( " " ) ; return ; } let max_total_nodes = ( 1 << ( height + 1 ) ) - 1 ; let nodes_last_level = ( 1 << height ) - ( max_total_nodes - N ) ; let from_root ; let from_leaf ; if ( X == height ) from_root = nodes_last_level ; else from_root = 1 << X ; let left_leaf_nodes = Math . floor ( ( ( 1 << height ) - nodes_last_level ) / 2 ) ; if ( X == 0 ) { from_leaf = nodes_last_level + left_leaf_nodes ; } else { let i = X ; while ( nodes_last_level > 1 && i > 0 ) { nodes_last_level = Math . floor ( Math . ceil ( nodes_last_level / 2 ) ) ; i -- ; } from_leaf = nodes_last_level ; i = X ; while ( left_leaf_nodes > 1 && i > 0 ) { left_leaf_nodes = Math . floor ( Math . ceil ( left_leaf_nodes / 2 ) ) ; i -- ; } from_leaf += left_leaf_nodes ; } document . write ( from_root + " " + from_leaf ) ; } let N = 38 , X = 3 ; countNodes ( N , X ) ;

Accumulator variables: from_leaf, i
Javascript program:
function sum_of_4_squares ( n ) { var i , odd = 0 , even = 0 ; for ( i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i % 2 == 0 ) even += i ; else odd += i ; if ( ( n / i ) != i ) { if ( ( n / i ) % 2 == 0 ) even += ( n / i ) ; else odd += ( n / i ) ; } } } if ( n % 2 == 1 ) return 8 * ( odd + even ) ; else return 24 * ( odd ) ; } var n = 4 ; document . write ( sum_of_4_squares ( n ) ) ;

Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
function mosaic ( n ) { let i , ans = 1 ; for ( i = 2 ; i <= n ; i ++ ) { if ( n % i == 0 && n > 0 ) { let count = 0 ; while ( n % i == 0 ) { n = parseInt ( n / i , 10 ) ; count ++ ; } ans *= count * i ; } } return ans ; } let n = 36 ; document . write ( mosaic ( n ) ) ;

Accumulator variables: ans, count, i
Iterator variables: i
Javascript program:
function Total_Ways ( n ) { var fac = 1 ; for ( i = 2 ; i <= n - 1 ; i ++ ) { fac = fac * i ; } return ( fac * 2 ) ; } var n = 5 ; document . write ( Total_Ways ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function MaxNumbers ( a , n ) { let fre = new Array ( 3 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] %= 3 ; fre [ a [ i ] ] ++ ; } let ans = fre [ 0 ] ; let k = Math . min ( fre [ 1 ] , fre [ 2 ] ) ; ans += k ; fre [ 1 ] -= k ; fre [ 2 ] -= k ; ans += parseInt ( fre [ 1 ] / 3 ) + parseInt ( fre [ 2 ] / 3 ) ; return ans ; } let a = [ 1 , 4 , 10 , 7 , 11 , 2 , 8 , 5 , 9 ] ; let n = a . length ; document . write ( MaxNumbers ( a , n ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { var count = 0 ; while ( n > 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function pairs ( arr , n , k ) { var count = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var sum = countSetBits ( arr [ i ] ) + countSetBits ( arr [ j ] ) ; if ( sum == k ) count ++ ; } } return count ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; var k = 4 ; document . write ( pairs ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, n
Iterator variables: i, j
Javascript program:
var MAX = 32 ; function countSetBits ( n ) { var count = 0 ; while ( n > 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function pairs ( arr , n , k ) { var count = 0 ; var f = Array . from ( { length : MAX + 1 } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < n ; i ++ ) f [ countSetBits ( arr [ i ] ) ] ++ ; for ( i = 0 ; i <= MAX ; i ++ ) { for ( j = i ; j <= MAX ; j ++ ) { if ( i + j == k ) { if ( i == j ) count += ( ( f [ i ] * ( f [ i ] - 1 ) ) / 2 ) ; else count += ( f [ i ] * f [ j ] ) ; } } } return count ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; var k = 4 ; document . write ( pairs ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, n
Iterator variables: i, j
Javascript program:
function LowerHessenbergMatrix ( n ) { for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( j > i + 1 ) document . write ( ' ' + " " ) ; else document . write ( Math . floor ( Math . random ( ) * 10 ) + " " ) ; } document . write ( " " ) ; } } var n = 4 ; LowerHessenbergMatrix ( n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function UpperHessenbergMatrix ( n ) { for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( i > j + 1 ) document . write ( ' ' + " " ) ; else document . write ( Math . floor ( Math . random ( ) * 10 ) + " " ) ; } document . write ( " " ) ; } } var n = 4 ; UpperHessenbergMatrix ( n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function composite_factors ( n ) { var count = 0 ; var i , j ; var a = Array ( n + 1 ) . fill ( 0 ) ; for ( i = 1 ; i <= n ; ++ i ) { if ( n % i == 0 ) { a [ i ] = i ; } } for ( i = 2 ; i <= n ; i ++ ) { j = 2 ; var p = 1 ; while ( j < a [ i ] ) { if ( a [ i ] % j == 0 ) { p = 0 ; break ; } j ++ ; } if ( p == 0 && a [ i ] != 0 ) { count ++ ; } } return count ; } var n = 100 ; document . write ( composite_factors ( n ) ) ;

Index/key variables: i
Accumulator variables: count, i, j
Iterator variables: i
Javascript program:
function isMersenne ( n ) { while ( n != 0 ) { let r = n % 2 ; if ( r == 0 ) return false ; n = Math . floor ( n / 2 ) ; } return true ; } function sumOfMersenne ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 && isMersenne ( arr [ i ] ) ) { sum += arr [ i ] ; } } return sum ; } let arr = [ 17 , 6 , 7 , 63 , 3 ] ; let n = arr . length ; document . write ( sumOfMersenne ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i