dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function addToArrayForm ( A , K ) { let v = [ ] ; let ans = [ ] ; let rem = 0 ; let i = 0 ; for ( i = A . length - 1 ; i >= 0 ; i -- ) { let my = A [ i ] + K % 10 + rem ; if ( my > 9 ) { rem = 1 ; v . push ( my % 10 ) ; } else { v . push ( my ) ; rem = 0 ; } K = parseInt ( K / 10 , 10 ) ; } while ( K > 0 ) { let my = K % 10 + rem ; v . push ( my % 10 ) ; if ( parseInt ( my / 10 , 10 ) > 0 ) rem = 1 ; else rem = 0 ; K = parseInt ( K / 10 , 10 ) ; } if ( rem > 0 ) v . push ( rem ) ; for ( let j = v . length - 1 ; j >= 0 ; j -- ) ans . push ( v [ j ] ) ; return ans ; } let A = [ ] ; A . push ( 2 ) ; A . push ( 7 ) ; A . push ( 4 ) ; let K = 181 ; let ans = addToArrayForm ( A , K ) ; for ( let i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
const MAX = 100005 ; function kadaneAlgorithm ( ar , n ) { let sum = 0 , maxSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += ar [ i ] ; if ( sum < 0 ) sum = 0 ; maxSum = Math . max ( maxSum , sum ) ; } return maxSum ; } function maxFunction ( arr , n ) { let b = new Array ( MAX ) , c = new Array ( MAX ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( i & 1 ) { b [ i ] = Math . abs ( arr [ i + 1 ] - arr [ i ] ) ; c [ i ] = - b [ i ] ; } else { c [ i ] = Math . abs ( arr [ i + 1 ] - arr [ i ] ) ; b [ i ] = - c [ i ] ; } } let ans = kadaneAlgorithm ( b , n - 1 ) ; ans = Math . max ( ans , kadaneAlgorithm ( c , n - 1 ) ) ; return ans ; } let arr = [ 1 , 5 , 4 , 7 ] ; let n = arr . length ; document . write ( maxFunction ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPalindrome ( n ) { var divisor = 1 ; while ( parseInt ( n / divisor ) >= 10 ) divisor *= 10 ; while ( n != 0 ) { var leading = parseInt ( n / divisor ) ; var trailing = n % 10 ; if ( leading != trailing ) return false ; n = parseInt ( ( n % divisor ) / 10 ) ; divisor = parseInt ( divisor / 100 ) ; } return true ; } function largestPalindrome ( A , n ) { var currentMax = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( A [ i ] > currentMax && isPalindrome ( A [ i ] ) ) currentMax = A [ i ] ; } return currentMax ; } var A = [ 1 , 232 , 54545 , 999991 ] ; var n = A . length ; document . write ( largestPalindrome ( A , n ) ) ;

Index/key variables: i
Accumulator variables: divisor, i
Iterator variables: i
Javascript program:
function getFinalElement ( n ) { let finalNum ; for ( finalNum = 2 ; finalNum * 2 <= n ; finalNum *= 2 ) ; return finalNum ; } let N = 12 ; document . write ( getFinalElement ( N ) ) ;

Accumulator variables: finalNum
Iterator variables: finalNum
Javascript program:
function SieveOfEratosthenes ( prime , p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( let p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } function sumOfElements ( arr , n ) { let prime = new Array ( n + 1 ) ; prime . fill ( true ) SieveOfEratosthenes ( prime , n + 1 ) ; let i , j ; let m = new Map ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; else m . set ( arr [ i ] , 1 ) ; } let sum = 0 ; for ( let it of m ) { if ( prime [ it [ 1 ] ] ) { sum += ( it [ 0 ] ) ; } } return sum ; } let arr = [ 5 , 4 , 6 , 5 , 4 , 6 ] ; let n = arr . length ; document . write ( sumOfElements ( arr , n ) ) ;

Index/key variables: i, p
Accumulator variables: i, p, sum
Iterator variables: i, it, p
Javascript program:
function isPalindrome ( num ) { let reverse_num = 0 , remainder , temp ; temp = num ; while ( temp != 0 ) { remainder = temp % 10 ; reverse_num = reverse_num * 10 + remainder ; temp = Math . floor ( temp / 10 ) ; } if ( reverse_num == num ) { return true ; } return false ; } function isOddLength ( num ) { let count = 0 ; while ( num > 0 ) { num = Math . floor ( num / 10 ) ; count ++ ; } if ( count % 2 != 0 ) { return true ; } return false ; } function sumOfAllPalindrome ( L , R ) { let sum = 0 ; if ( L <= R ) for ( let i = L ; i <= R ; i ++ ) { if ( isPalindrome ( i ) && isOddLength ( i ) ) { sum += i ; } } return sum ; } let L = 110 , R = 1130 ; document . write ( sumOfAllPalindrome ( L , R ) ) ;

Accumulator variables: count, i, sum
Iterator variables: i
Javascript program:
function fact ( n ) { let f = 1 ; for ( let i = 2 ; i <= n ; i ++ ) f = f * i ; return f ; } function waysOfConsonants ( size1 , freq ) { let ans = fact ( size1 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( i == 0 i == 4 i == 8 i == 14 i == 20 ) continue ; else ans = Math . floor ( ans / fact ( freq [ i ] ) ) ; } return ans ; } function waysOfVowels ( size2 , freq ) { return Math . floor ( fact ( size2 ) / ( fact ( freq [ 0 ] ) * fact ( freq [ 4 ] ) * fact ( freq [ 8 ] ) * fact ( freq [ 14 ] ) * fact ( freq [ 20 ] ) ) ) ; } function countWays ( str ) { let freq = new Array ( 200 ) ; for ( let i = 0 ; i < 200 ; i ++ ) freq [ i ] = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; let vowel = 0 , consonant = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] != ' ' && str [ i ] != ' ' && str [ i ] != ' ' && str [ i ] != ' ' && str [ i ] != ' ' ) consonant ++ ; else vowel ++ ; } return waysOfConsonants ( consonant + 1 , freq ) * waysOfVowels ( vowel , freq ) ; } let str = " " ; document . write ( countWays ( str ) ) ;

Index/key variables: i
Accumulator variables: consonant, i, vowel
Iterator variables: i
Javascript program:
function calculateAlternateSum ( n ) { if ( n <= 0 ) return 0 ; var fibo = Array ( n + 1 ) . fill ( 0 ) ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; var sum = Math . pow ( fibo [ 0 ] , 2 ) + Math . pow ( fibo [ 1 ] , 2 ) ; for ( i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; if ( i % 2 == 0 ) sum -= fibo [ i ] ; else sum += fibo [ i ] ; } return sum ; } var n = 8 ; document . write ( " " + n + " " + calculateAlternateSum ( n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function countDigits ( val , arr ) { while ( val > 0 ) { let digit = val % 10 ; arr [ digit ] ++ ; val = Math . floor ( val / 10 ) ; } return ; } function countFrequency ( x , n ) { let freq_count = new Array ( 10 ) ; for ( let i = 0 ; i < 10 ; i ++ ) { freq_count [ i ] = 0 ; } for ( let i = 1 ; i <= n ; i ++ ) { let val = Math . pow ( x , i ) ; countDigits ( val , freq_count ) ; } for ( let i = 0 ; i <= 9 ; i ++ ) { document . write ( freq_count [ i ] + " " ) ; } } let x = 15 , n = 3 ; countFrequency ( x , n ) ;

Index/key variables: digit, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSolutions ( a ) { let count = 0 ; for ( let i = 0 ; i <= a ; i ++ ) { if ( a == ( i + ( a ^ i ) ) ) count ++ ; } return count ; } let a = 3 ; document . write ( countSolutions ( a ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function bitCount ( n ) { let count = 0 ; while ( n != 0 ) { count ++ ; n &= ( n - 1 ) ; } return count ; } function countSolutions ( a ) { let count = bitCount ( a ) ; count = Math . pow ( 2 , count ) ; return count ; } let a = 3 ; document . write ( countSolutions ( a ) ) ;

Accumulator variables: count, n
Javascript program:
function calculateAreaSum ( l , b ) { var size = 1 ; var maxSize = Math . min ( l , b ) ; var totalArea = 0 ; for ( var i = 1 ; i <= maxSize ; i ++ ) { var totalSquares = ( l - size + 1 ) * ( b - size + 1 ) ; var area = totalSquares * size * size ; totalArea += area ; size ++ ; } return totalArea ; } var l = 4 , b = 3 ; document . write ( calculateAreaSum ( l , b ) ) ;

Accumulator variables: i, size, totalArea
Iterator variables: i
Javascript program:
function boost_hyperfactorial ( num ) { let val = 1 ; for ( let i = 1 ; i <= num ; i ++ ) { val = val * Math . pow ( i , i ) ; } return val ; } let num = 5 ; document . write ( boost_hyperfactorial ( num ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function boost_hyperfactorial ( num ) { var val = 1 ; for ( var i = 1 ; i <= num ; i ++ ) { for ( var j = 1 ; j <= i ; j ++ ) { val *= i ; } } return val ; } var num = 5 ; document . write ( boost_hyperfactorial ( num ) ) ;

Accumulator variables: i, j, val
Iterator variables: i, j
Javascript program:
var rows = 3 ; var cols = 3 ; function meanVector ( mat ) { document . write ( " " ) ; for ( var i = 0 ; i < rows ; i ++ ) { var mean = 0.00 ; var sum = 0 ; for ( var j = 0 ; j < cols ; j ++ ) sum += mat [ j ] [ i ] ; mean = sum / rows ; document . write ( mean + " " ) ; } document . write ( " " ) ; } var mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; meanVector ( mat ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function primeFactors ( n ) { var res = [ ] ; if ( n % 2 == 0 ) { while ( n % 2 == 0 ) n = parseInt ( n / 2 ) ; res . push ( 2 ) ; } for ( var i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { while ( n % i == 0 ) n = parseInt ( n / i ) ; res . push ( i ) ; } } if ( n > 2 ) res . push ( n ) ; return res ; } function isHoax ( n ) { var pf = primeFactors ( n ) ; if ( pf [ 0 ] == n ) return false ; var all_pf_sum = 0 ; for ( var i = 0 ; i < pf . length ; i ++ ) { var pf_sum ; for ( pf_sum = 0 ; pf [ i ] > 0 ; pf_sum += pf [ i ] % 10 , pf [ i ] = parseInt ( pf [ i ] / 10 ) ) ; all_pf_sum += pf_sum ; } var sum_n ; for ( sum_n = 0 ; n > 0 ; sum_n += n % 10 , n = parseInt ( n / 10 ) ) ; return sum_n == all_pf_sum ; } var n = 84 ; if ( isHoax ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: all_pf_sum, i, pf_sum, sum_n
Iterator variables: i, pf_sum, sum_n
Javascript program:
function LucasLehmer ( n ) { let current_val = 4 ; let series = [ ] ; series . push ( current_val ) ; for ( let i = 0 ; i < n ; i ++ ) { current_val = ( current_val * current_val ) - 2 ; series . push ( current_val ) ; } for ( let i = 0 ; i <= n ; i ++ ) { document . write ( " " + i + " " + series [ i ] + " " ) ; } } let n = 5 ; LucasLehmer ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function modInverse ( a , prime ) { a = a % prime ; for ( let x = 1 ; x < prime ; x ++ ) if ( ( a * x ) % prime == 1 ) return x ; return - 1 ; } function printModIverses ( n , prime ) { for ( let i = 1 ; i <= n ; i ++ ) document . write ( modInverse ( i , prime ) + " " ) ; } let n = 10 ; let prime = 17 ; printModIverses ( n , prime ) ;

Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
function minOp ( num ) { var rem ; var count = 0 ; while ( num ) { rem = num % 10 ; if ( ! ( rem == 3 rem == 8 ) ) count ++ ; num = parseInt ( num / 10 ) ; } return count ; } var num = 234198 ; document . write ( " " + minOp ( num ) ) ;

Accumulator variables: count
Javascript program:
function sumOfDigits ( a ) { var sum = 0 ; while ( a != 0 ) { sum += a % 10 ; a = parseInt ( a / 10 ) ; } return sum ; } function findMax ( x ) { var b = 1 , ans = x ; while ( x != 0 ) { var cur = ( x - 1 ) * b + ( b - 1 ) ; if ( sumOfDigits ( cur ) > sumOfDigits ( ans ) || ( sumOfDigits ( cur ) == sumOfDigits ( ans ) && cur > ans ) ) ans = cur ; x = parseInt ( x / 10 ) ; b *= 10 ; } return ans ; } var n = 521 ; document . write ( findMax ( n ) ) ;

Accumulator variables: b, sum
Javascript program:
function ssort ( a , n ) { var i , j , min , temp ; for ( i = 0 ; i < n - 1 ; i ++ ) { min = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( a [ j ] < a [ min ] ) min = j ; temp = a [ i ] ; a [ i ] = a [ min ] ; a [ min ] = temp ; } } function isPalindrome ( n ) { var divisor = 1 ; while ( parseInt ( n / divisor ) >= 10 ) divisor *= 10 ; while ( n != 0 ) { var leading = parseInt ( n / divisor ) ; var trailing = n % 10 ; if ( leading != trailing ) return false ; n = parseInt ( ( n % divisor ) / 10 ) ; divisor = parseInt ( divisor / 100 ) ; } return true ; } function largestPalindrome ( A , n ) { ssort ( A , A . length ) ; for ( var i = n - 1 ; i >= 0 ; -- i ) { if ( isPalindrome ( A [ i ] ) ) return A [ i ] ; } return - 1 ; } var A = [ 1 , 232 , 54545 , 999991 ] ; var n = A . length ; document . write ( largestPalindrome ( A , n ) ) ;

Index/key variables: i, j, min
Accumulator variables: divisor, i, j
Iterator variables: i, j
Javascript program:
function findSum ( n , a , b ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( i % a == 0 i % b == 0 ) sum += i ; return sum ; } let n = 10 ; let a = 3 ; let b = 5 ; document . write ( findSum ( n , a , b ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function LCM ( arr , n ) { var max_num = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( max_num < arr [ i ] ) max_num = arr [ i ] ; var res = 1 ; while ( x <= max_num ) { var indexes = [ ] ; for ( var j = 0 ; j < n ; j ++ ) if ( arr [ j ] % x == 0 ) indexes . push ( j ) ; if ( indexes . length >= 2 ) { for ( var j = 0 ; j < indexes . length ; j ++ ) arr [ indexes [ j ] ] = arr [ indexes [ j ] ] / x ; res = res * x ; } else x ++ ; } for ( var i = 0 ; i < n ; i ++ ) res = res * arr [ i ] ; return res ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 10 , 20 , 35 ] ; var n = arr . length ; document . write ( LCM ( arr , n ) + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, x
Iterator variables: i, j
Javascript program:
function politness ( n ) { let count = 0 ; for ( let i = 2 ; i <= Math . sqrt ( 2 * n ) ; i ++ ) { let a ; if ( ( 2 * n ) % i != 0 ) continue ; a = 2 * n ; a = Math . floor ( a / i ) ; a -= ( i - 1 ) ; if ( a % 2 != 0 ) continue ; a = Math . floor ( a / 2 ) ; if ( a > 0 ) { count ++ ; } } return count ; } let n = 90 ; document . write ( " " + n + " " + politness ( n ) + " " ) ; n = 15 ; document . write ( " " + n + " " + politness ( n ) ) ;

Accumulator variables: a, count, i
Iterator variables: i
Javascript program:
let MAX = 10000 ; let primes = new Array ( ) ; function sieveSundaram ( ) { let marked = new Array ( parseInt ( MAX / 2 ) + 100 ) . fill ( false ) ; for ( let i = 1 ; i <= ( Math . sqrt ( MAX ) - 1 ) / 2 ; i ++ ) for ( let j = ( i * ( i + 1 ) ) << 1 ; j <= MAX / 2 ; j = j + 2 * i + 1 ) marked [ j ] = true ; primes . push ( 2 ) ; for ( let i = 1 ; i <= MAX / 2 ; i ++ ) if ( marked [ i ] == false ) primes . push ( 2 * i + 1 ) ; } function findPrimes ( n ) { if ( n <= 2 n % 2 != 0 ) { document . write ( " " ) ; return ; } for ( let i = 0 ; primes [ i ] <= n / 2 ; i ++ ) { let diff = n - primes [ i ] ; if ( primes . includes ( diff ) ) { document . write ( primes [ i ] + " " + diff + " " + n + " " ) ; return ; } } } sieveSundaram ( ) ; findPrimes ( 4 ) ; findPrimes ( 38 ) ; findPrimes ( 100 ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i, j
Javascript program:
function kPrimeFactor ( n , k ) { while ( n % 2 == 0 ) { k -- ; n = n / 2 ; if ( k == 0 ) return 2 ; } for ( let i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { if ( k == 1 ) return i ; k -- ; n = n / i ; } } if ( n > 2 && k == 1 ) return n ; return - 1 ; } let n = 12 , k = 3 ; document . write ( kPrimeFactor ( n , k ) + " " ) ; n = 14 ; k = 3 ; document . write ( kPrimeFactor ( n , k ) ) ;

Accumulator variables: k
Iterator variables: i
Javascript program:
var MAX = 10001 ; function sieveOfEratosthenes ( s ) { prime = Array . from ( { length : MAX + 1 } , ( _ , i ) => false ) ; for ( i = 2 ; i <= MAX ; i += 2 ) s [ i ] = 2 ; for ( i = 3 ; i <= MAX ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( j = i ; j * i <= MAX ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } function kPrimeFactor ( n , k , s ) { while ( n > 1 ) { if ( k == 1 ) return s [ n ] ; k -- ; n /= s [ n ] ; } return - 1 ; } var s = Array . from ( { length : MAX + 1 } , ( _ , i ) => 0 ) ; sieveOfEratosthenes ( s ) ; var n = 12 , k = 3 ; document . write ( kPrimeFactor ( n , k , s ) + " " ) ; n = 14 ; k = 3 ; document . write ( kPrimeFactor ( n , k , s ) ) ;

Index/key variables: i, n
Accumulator variables: i, j, k, n
Iterator variables: i, j
Javascript program:
function sumDivisorsOfDivisors ( n ) { let mp = new Map ( ) ; for ( let j = 2 ; j <= Math . sqrt ( n ) ; j ++ ) { let count = 0 ; while ( n % j == 0 ) { n = Math . floor ( n / j ) ; count ++ ; } if ( count != 0 ) mp . set ( j , count ) ; } if ( n != 1 ) mp . set ( n , 1 ) ; let ans = 1 ; for ( let [ key , value ] of mp . entries ( ) ) { let pw = 1 ; let sum = 0 ; for ( let i = value + 1 ; i >= 1 ; i -- ) { sum += ( i * pw ) ; pw = key ; } ans *= sum ; } return ans ; } let n = 10 ; document . write ( sumDivisorsOfDivisors ( n ) ) ;

Accumulator variables: ans, count, i, j, sum
Iterator variables: i, j
Javascript program:
function prime ( n ) { if ( n & 1 ) n -= 2 ; else n -- ; let i , j ; for ( i = n ; i >= 2 ; i -= 2 ) { if ( i % 2 == 0 ) continue ; for ( j = 3 ; j <= Math . sqrt ( i ) ; j += 2 ) { if ( i % j == 0 ) break ; } if ( j > Math . sqrt ( i ) ) return i ; } return 2 ; } let n = 17 ; document . write ( prime ( n ) ) ;

Accumulator variables: i, j, n
Iterator variables: i, j
Javascript program:
function fractionToDecimal ( numr , denr ) { let res = " " ; let mp = new Map ( ) ; mp . clear ( ) ; let rem = numr % denr ; while ( ( rem != 0 ) && ( ! mp . has ( rem ) ) ) { mp . set ( rem , res . length ) ; rem = rem * 10 ; let res_part = Math . floor ( rem / denr ) ; res += res_part . toString ( ) ; rem = rem % denr ; } if ( rem == 0 ) return " " ; else if ( mp . has ( rem ) ) return res . substr ( mp . get ( rem ) ) ; return " " ; } let numr = 50 , denr = 22 ; let res = fractionToDecimal ( numr , denr ) ; if ( res == " " ) document . write ( " " ) ; else document . write ( " " + res ) ;

Accumulator variables: res
Javascript program:
function has0 ( x ) { while ( x ) { if ( x % 10 == 0 ) return 1 ; x = Math . floor ( x / 10 ) ; } return 0 ; } function getCount ( n ) { let count = 0 ; for ( let i = 1 ; i <= n ; i ++ ) count += has0 ( i ) ; return count ; } let n = 107 ; document . write ( " " + " " + n + " " + getCount ( n ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function squareRootExists ( n , p ) { n = n % p ; for ( let x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } let p = 7 ; let n = 2 ; if ( squareRootExists ( n , p ) === true ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function largestPower ( n , p ) { let x = 0 ; while ( n ) { n = parseInt ( n / p ) ; x += n ; } return Math . floor ( x ) ; } let n = 10 ; let p = 3 ; document . write ( " " + p ) ; document . write ( " " + n + " " ) ; document . write ( largestPower ( n , p ) ) ;

Accumulator variables: x
Javascript program:
function Bitwise_AND_sum_i ( arr1 , arr2 , M , N ) { let frequency = new Array ( 32 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { let bit_position = 0 ; let num = arr1 [ i ] ; while ( num ) { if ( num & 1 ) { frequency [ bit_position ] += 1 ; } bit_position += 1 ; num >>= 1 ; } } for ( let i = 0 ; i < M ; i ++ ) { let num = arr2 [ i ] ; let value_at_that_bit = 1 ; let bitwise_AND_sum = 0 ; for ( let bit_position = 0 ; bit_position < 32 ; bit_position ++ ) { if ( num & 1 ) { bitwise_AND_sum += frequency [ bit_position ] * value_at_that_bit ; } num >>= 1 ; value_at_that_bit <<= 1 ; } document . write ( bitwise_AND_sum + ' ' ) ; } return ; } let arr1 = [ 1 , 2 , 3 ] ; let arr2 = [ 1 , 2 , 3 ] ; let N = arr1 . length ; let M = arr2 . length Bitwise_AND_sum_i ( arr1 , arr2 , M , N ) ;

Index/key variables: bit_position, i
Accumulator variables: bit_position, bitwise_AND_sum, i
Iterator variables: bit_position, i
Javascript program:
function FlipBits ( n ) { for ( let bit = 0 ; bit < 32 ; bit ++ ) { if ( ( ( n >> bit ) & 1 ) > 0 ) { n = n ^ ( 1 << bit ) ; break ; } } document . write ( " " ) ; document . write ( " " + n ) ; } let N = 12 ; FlipBits ( N ) ;

Accumulator variables: bit
Iterator variables: bit
Javascript program:
function bitwiseAndOdd ( n ) { var result = 1 ; for ( var i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } var n = 10 ; document . write ( bitwiseAndOdd ( n ) ) ;

Iterator variables: i
Javascript program:
function reverseBits ( n ) { let rev = 0 ; while ( n > 0 ) { rev <<= 1 ; if ( ( n & 1 ) == 1 ) rev ^= 1 ; n >>= 1 ; } return rev ; } let n = 11 ; document . write ( reverseBits ( n ) ) ;

Accumulator variables: rev
Javascript program:
function countgroup ( a , n ) { var xs = 0 ; for ( var i = 0 ; i < n ; i ++ ) xs = xs ^ a [ i ] ; if ( xs == 0 ) return ( 1 << ( n - 1 ) ) - 1 ; } var a = [ 1 , 2 , 3 ] ; var n = a . length ; document . write ( countgroup ( a , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMax ( num ) { let num_copy = num ; let j = 4 * 8 - 1 ; let i = 0 ; while ( i < j ) { let m = ( num_copy >> i ) & 1 ; let n = ( num_copy >> j ) & 1 ; if ( m > n ) { let x = ( 1 << i 1 << j ) ; num = num ^ x ; } i ++ ; j -- ; } return num ; } let num = 4 ; document . write ( findMax ( num ) ) ;

Accumulator variables: i, j
Javascript program:
function square ( n ) { if ( n < 0 ) n = - n ; let res = n ; for ( let i = 1 ; i < n ; i ++ ) res += n ; return res ; } for ( let n = 1 ; n <= 5 ; n ++ ) document . write ( " " + n + " " + square ( n ) + " " ) ;

Accumulator variables: i, n, res
Iterator variables: i, n
Javascript program:
function answer ( n ) { var dp = Array ( 10 ) ; var prev = Array ( 10 ) ; if ( n == 1 ) return 10 ; for ( var j = 0 ; j <= 9 ; j ++ ) dp [ j ] = 1 ; for ( var i = 2 ; i <= n ; i ++ ) { for ( var j = 0 ; j <= 9 ; j ++ ) { prev [ j ] = dp [ j ] ; } for ( var j = 0 ; j <= 9 ; j ++ ) { if ( j == 0 ) dp [ j ] = prev [ j + 1 ] ; else if ( j == 9 ) dp [ j ] = prev [ j - 1 ] ; else dp [ j ] = prev [ j - 1 ] + prev [ j + 1 ] ; } } var sum = 0 ; for ( var j = 1 ; j <= 9 ; j ++ ) sum += dp [ j ] ; return sum ; } var n = 2 ; document . write ( answer ( n ) ) ;

Index/key variables: j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
var MAX = 100000 var catalan = Array ( MAX ) ; function catalanDP ( n ) { catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( var i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( var j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } } function CatalanSequence ( arr , n ) { catalanDP ( n ) ; var s = [ ] ; var a = 1 , b = 1 ; var c ; s . push ( a ) ; if ( n >= 2 ) s . push ( b ) ; for ( var i = 2 ; i < n ; i ++ ) { s . push ( catalan [ i ] ) ; } s . sort ( ( a , b ) => b - a ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( s . includes ( arr [ i ] ) ) { s . pop ( arr [ i ] ) ; } } return s . length ; } var arr = [ 1 , 1 , 2 , 5 , 41 ] ; var n = arr . length ; document . write ( CatalanSequence ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function composite ( n ) { let flag = 0 ; let c = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { if ( n % j == 0 ) { c += 1 ; } } if ( c >= 3 ) flag = 1 ; return flag ; } function odd_indices ( arr , n ) { let sum = 0 ; for ( let k = 0 ; k < n ; k += 2 ) { let check = composite ( arr [ k ] ) ; if ( check == 1 ) sum += arr [ k ] ; } document . write ( sum + " " ) ; } let arr = [ 13 , 5 , 8 , 16 , 25 ] ; let n = arr . length odd_indices ( arr , n ) ;

Index/key variables: k
Accumulator variables: c, j, k, sum
Iterator variables: j, k