dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function per ( n ) { let a = 3 ; let b = 0 ; let c = 2 ; let i ; let m ; if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return c ; while ( n > 2 ) { m = a + b ; a = b ; b = c ; c = m ; n -- ; } return m ; } n = 9 ; document . write ( per ( n ) ) ;

Accumulator variables: n
Javascript program:
function fact ( n ) { let num = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { num = num * i ; } return num ; } function Special_Factorial_Number ( k ) { for ( let i = 1 ; i <= k ; i ++ ) { if ( fact ( i ) % k == 0 ) { return i ; } } return 0 ; } let k = 16 ; document . write ( Special_Factorial_Number ( k ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getMaximumSumWithLCMN ( N ) { let sum = 0 ; let LIM = Math . sqrt ( N ) ; for ( let i = 1 ; i <= LIM ; i ++ ) { if ( N % i == 0 ) { if ( i == ( N / i ) ) sum += i ; else sum += ( i + N / i ) ; } } return sum ; } let N = 12 ; document . write ( getMaximumSumWithLCMN ( N ) + " " ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function hcf ( a , b ) { if ( b == 0 ) return a ; return hcf ( b , a % b ) ; } function findlcm ( a , b ) { if ( b == 1 ) return a ; a = ( a * b ) / hcf ( a , b ) ; b -= 1 ; return findlcm ( a , b ) ; } document . write ( n ) ; else document . write ( findlcm ( n , n - 1 ) ) ;

Accumulator variables: b
Javascript program:
function gcd ( a , b ) { if ( a % b != 0 ) return gcd ( b , a % b ) ; else return b ; } function lcm ( n ) { let ans = 1 ; for ( let i = 1 ; i <= n ; i ++ ) ans = ( ans * i ) / ( gcd ( ans , i ) ) ; return ans ; } let n = 20 ; document . write ( lcm ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function y ( x ) { return 1 / ( 1 + x * x ) ; } function trapezoidal ( a , b , n ) { let h = ( b - a ) / n ; let s = y ( a ) + y ( b ) ; for ( let i = 1 ; i < n ; i ++ ) s += 2 * y ( a + i * h ) ; return ( h / 2 ) * s ; } let x0 = 0 ; let xn = 1 ; let n = 6 ; document . write ( " " + Math . round ( trapezoidal ( x0 , xn , n ) * 10000.0 ) / 10000.0 ) ;

Accumulator variables: i, s
Iterator variables: i
Javascript program:
function maxProd ( n ) { if ( n == 2 n == 3 ) return ( n - 1 ) ; let res = 1 ; while ( n > 4 ) { n -= 3 ; res *= 3 ; } return ( n * res ) ; } document . write ( " " + maxProd ( 45 ) ) ;

Accumulator variables: n, res
Javascript program:
function numberOfDigits ( n ) { if ( n == 1 ) return 1 ; let d = ( n * Math . log10 ( 1.6180339887498948 ) ) - ( ( Math . log10 ( 5 ) ) / 2 ) ; return Math . ceil ( d ) ; } let i ; for ( let i = 1 ; i <= 10 ; i ++ ) document . write ( ` ${ i } ${ numberOfDigits ( i ) } ` ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function factors ( n , k ) { let v = [ ] ; while ( n % 2 == 0 ) { v . push ( 2 ) ; n = parseInt ( n / 2 ) ; } if ( v . length >= k ) return true ; for ( let i = 3 ; i * i <= n ; i += 2 ) { while ( n % i == 0 ) { n = parseInt ( n / i ) ; v . push ( i ) ; } if ( v . length >= k ) return true ; } if ( n > 2 ) v . push ( n ) ; if ( v . length >= k ) return true ; return false ; } function operation ( n , k ) { let answered = false ; if ( n < k ) { answered = true ; document . write ( " " ) ; } let ok = factors ( n , k ) ; if ( ! ok && ! answered ) { answered = true ; document . write ( " " ) ; } if ( ok && ! answered ) document . write ( " " ) ; } let n = 4 ; let k = 2 ; operation ( n , k ) ;

Accumulator variables: i
Iterator variables: i
Boolean variables: answered
Javascript program:
function sieve ( n , prime ) { for ( let i = 1 ; i <= n ; i ++ ) prime [ i ] = 1 ; prime [ 1 ] = 0 ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == 1 ) { for ( let j = i * i ; j <= n ; j += i ) prime [ j ] = 0 ; } } } function expFactor ( n , p ) { let x = p ; let exponent = 0 ; while ( ( n / x ) > 0 ) { exponent += Math . floor ( n / x ) ; x *= p ; } return exponent ; } function countFactors ( n ) { let ans = 1 ; let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { prime [ i ] = 0 ; } sieve ( n , prime ) ; for ( let p = 1 ; p <= n ; p ++ ) { if ( prime [ p ] == 1 ) ans *= ( expFactor ( n , p ) + 1 ) ; } return ans ; } let n = 16 ; document . write ( " " + n + " " + countFactors ( n ) ) ;

Index/key variables: i, j, p
Accumulator variables: ans, exponent, i, j, p, x
Iterator variables: i, j, p
Javascript program:
function __gcd ( a , b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } function LcmOfArray ( arr , idx ) { if ( idx == arr . length - 1 ) { return arr [ idx ] ; } let a = arr [ idx ] ; let b = LcmOfArray ( arr , idx + 1 ) ; return ( a * b / __gcd ( a , b ) ) ; let arr = [ 1 , 2 , 8 , 3 ] ; document . write ( LcmOfArray ( arr , 0 ) + " " ) ; arr = [ 2 , 7 , 3 , 9 , 4 ] ; document . write ( LcmOfArray ( arr , 0 ) ) ;

Index/key variables: idx
Javascript program:
function countDivisors ( n ) { let count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) + 1 ; i ++ ) { if ( n % i == 0 ) count += ( Math . floor ( n / i ) == i ) ? 1 : 2 ; } if ( count % 2 == 0 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } document . write ( " " ) ; countDivisors ( 10 ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function largestPower ( n , p ) { let x = 0 ; while ( n > 0 ) { n = parseInt ( n / p , 10 ) ; x += n ; } return x ; } function power ( x , y , p ) { let res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % p ; } x = ( x * x ) % p ; } return res ; } function modFact ( n , p ) { if ( n >= p ) { return 0 ; } let res = 1 ; let isPrime = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) isPrime [ i ] = true ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( isPrime [ i ] ) { for ( let j = 2 * i ; j <= n ; j += i ) { isPrime [ j ] = false ; } } } for ( let i = 2 ; i <= n ; i ++ ) { if ( isPrime [ i ] ) { let k = largestPower ( n , i ) ; res = ( res * power ( i , k , p ) ) % p ; } } return res ; } let n = 25 , p = 29 ; document . write ( modFact ( n , p ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, x
Iterator variables: i, j
Javascript program:
function add ( x , y ) { while ( y > 0 && y != 0 ) { x ++ ; y -- ; } while ( y < 0 && y != 0 ) { x -- ; y ++ ; } return x ; } document . write ( add ( 43 , 23 ) + " " ) ; document . write ( add ( 43 , - 23 ) + " " ) ;

Accumulator variables: x, y
Javascript program:
function countFact ( low , high ) { let fact = 1 ; let x = 1 ; while ( fact < low ) { fact = fact * x ; x ++ ; } let res = 0 ; while ( fact <= high ) { res ++ ; fact = fact * x ; x ++ ; } return res ; } document . write ( " " + countFact ( 2 , 720 ) ) ;

Accumulator variables: res, x
Javascript program:
class Date { constructor ( d , m , y ) { this . d = d ; this . m = m ; this . y = y ; } } let monthDays = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; function countLeapYears ( d ) { let years = d . y ; if ( d . m <= 2 ) { years -- ; } return Math . floor ( years / 4 ) - Math . floor ( years / 100 ) + Math . floor ( years / 400 ) ; } function getDifference ( dt1 , dt2 ) { let n1 = dt1 . y * 365 + dt1 . d ; for ( let i = 0 ; i < dt1 . m - 1 ; i ++ ) { n1 += monthDays [ i ] ; } n1 += countLeapYears ( dt1 ) ; let n2 = dt2 . y * 365 + dt2 . d ; for ( let i = 0 ; i < dt2 . m - 1 ; i ++ ) { n2 += monthDays [ i ] ; } n2 += countLeapYears ( dt2 ) ; return ( n2 - n1 ) ; } let dt1 = new Date ( 1 , 2 , 2000 ) ; let dt2 = new Date ( 1 , 2 , 2004 ) ; document . write ( " " + getDifference ( dt1 , dt2 ) ) ;

Index/key variables: i
Accumulator variables: i, n1, n2, years
Iterator variables: i
Class/struct names: Date
Javascript program:
function getPeriod ( n ) { let rem = 1 ; for ( let i = 1 ; i <= n + 1 ; i ++ ) rem = ( 10 * rem ) % n ; let d = rem ; let count = 0 ; do { rem = ( 10 * rem ) % n ; count ++ ; } while ( rem != d ) ; return count ; } document . write ( getPeriod ( 3 ) + " " ) document . write ( getPeriod ( 7 ) + " " )

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function calculateAddedValue ( number ) { let result = 0 ; let decimalPlace = 1 ; if ( number == 0 ) { result += ( 5 * decimalPlace ) ; } while ( number > 0 ) { if ( number % 10 == 0 ) { result += ( 5 * decimalPlace ) ; } number = Math . floor ( number / 10 ) ; decimalPlace *= 10 ; } return result ; } function replace0with5 ( number ) { return number += calculateAddedValue ( number ) ; } document . write ( replace0with5 ( 1020 ) ) ;

Accumulator variables: decimalPlace, number, result
Javascript program:
function sum ( n ) { let sum = 0 ; let fact = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { fact *= i ; sum += 1.0 / fact ; } return sum . toFixed ( 5 ) ; } let n = 5 ; document . write ( sum ( n ) ) ;

Accumulator variables: fact, i, sum
Iterator variables: i
Javascript program:
function print ( n , k ) { let rem = 1 ; let ans = ' ' ; for ( let i = 0 ; i < k ; i ++ ) { ans += Math . floor ( ( ( 10 * rem ) / n ) ) ; rem = ( 10 * rem ) % n ; } document . write ( ans ) } let n = 7 ; let k = 3 ; print ( n , k ) ; document . write ( " " ) ; n = 21 ; k = 4 ; print ( n , k ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function sum ( n ) { var i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } var n = 5 ; document . write ( sum ( n ) . toFixed ( 5 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function rearrange ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) arr [ i ] += ( arr [ arr [ i ] ] % n ) * n ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = Math . floor ( arr [ i ] / n ) ; } function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 3 , 2 , 0 , 1 ] ; let n = arr . length ; document . write ( " " ) ; printArr ( arr , n ) ; rearrange ( arr , n ) ; document . write ( " " ) ; printArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArray ( arr , size ) { for ( i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; return ; } function printSequencesRecur ( arr , n , k , index ) { var i ; if ( k == 0 ) { printArray ( arr , index ) ; } if ( k > 0 ) { for ( i = 1 ; i <= n ; ++ i ) { arr [ index ] = i ; printSequencesRecur ( arr , n , k - 1 , index + 1 ) ; } } } function printSequences ( n , k ) { var arr = Array . from ( { length : k } , ( _ , i ) => 0 ) ; printSequencesRecur ( arr , n , k , 0 ) ; return ; } var n = 3 ; var k = 2 ; printSequences ( n , k ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPairs ( arr , N , K ) { let mp = new Map ( ) ; let cnt = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( mp . has ( K - arr [ i ] ) ) { cnt += mp . get ( K - arr [ i ] ) ; } if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . set ( arr [ i ] , 1 ) ; } } document . write ( cnt ) ; } let arr = [ 1 , 5 , 4 , 8 , 7 ] ; let N = arr . length ; let K = 9 ; countPairs ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function check ( x ) { if ( ( ( x ) & ( x - 1 ) ) == 0 ) return 1 ; return 0 ; } function query ( l , r , pre ) { if ( l == 0 ) return pre [ r ] ; else return pre [ r ] - pre [ l - 1 ] ; } function countInRange ( arr , N , queries , Q ) { var pre = Array ( N ) . fill ( 0 ) ; pre [ 0 ] = check ( arr [ 0 ] ) ; for ( var i = 1 ; i < N ; i ++ ) { pre [ i ] = pre [ i - 1 ] + check ( arr [ i ] ) ; } var c = 0 ; while ( Q -- ) { var l = queries [ 0 ] ; var r = queries [ 1 ] ; c ++ ; document . write ( query ( l , r , pre ) + ' ' ) ; } } var arr = [ 12 , 11 , 16 , 8 , 2 , 5 , 1 , 3 , 256 , 1 ] ; var N = arr . length ; var queries = [ [ 0 , 9 ] , [ 4 , 9 ] ] ; var Q = queries . length ; countInRange ( arr , N , queries , Q ) ;

Index/key variables: i, r
Accumulator variables: Q, c, i
Iterator variables: i
Javascript program:
function build_num ( bit , k ) { let ans = 0 ; for ( let i = 0 ; i < 32 ; i ++ ) if ( bit [ i ] == k ) ans += ( 1 << i ) ; return ans ; } function minimumAND ( arr , n , k ) { let bit = new Array ( 32 ) ; bit . fill ( 0 ) ; for ( let i = 0 ; i < k ; i ++ ) { for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) bit [ j ] ++ ; } } let min_and = build_num ( bit , k ) ; for ( let i = k ; i < n ; i ++ ) { for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i - k ] & ( 1 << j ) ) > 0 ) bit [ j ] -- ; } for ( let j = 0 ; j < 32 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) bit [ j ] ++ ; } min_and = Math . min ( build_num ( bit , k ) , min_and ) ; } return min_and ; } let arr = [ 2 , 5 , 3 , 6 , 11 , 13 ] ; let k = 3 ; let n = arr . length ; document . write ( minimumAND ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function calculate ( bit_cnt ) { let res = 1 ; while ( bit_cnt -- ) { res = res * 3 ; } return res ; } function unset_bit_count ( n ) { let count = 0 ; while ( n ) { if ( ( n & 1 ) == 0 ) count ++ ; n = n >> 1 ; } return count ; } let n ; n = 2 ; let count = unset_bit_count ( n ) ; let ans = calculate ( count ) ; document . write ( ans ) ;

Accumulator variables: bit_cnt, count
Javascript program:
function solve ( A , B , n ) { var cnt = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { if ( countSetBits ( A [ i ] & A [ j ] ) == B [ j ] ) { cnt ++ ; } } } return cnt ; } function countSetBits ( n ) { var count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } var A = [ 2 , 3 , 1 , 4 , 5 ] ; var B = [ 2 , 2 , 1 , 4 , 2 ] ; var size = A . length ; document . write ( solve ( A , B , size ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, count, i, j
Iterator variables: i, j
Javascript program:
function CalculatePairs ( a , n ) { let cnt_zero = 0 ; let cnt_one = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) cnt_zero += 1 ; else cnt_one += 1 ; } let total_XOR_pairs = cnt_zero * cnt_one ; let total_AND_pairs = ( cnt_one ) * ( cnt_one - 1 ) / 2 ; let total_OR_pairs = cnt_zero * cnt_one + ( cnt_one ) * ( cnt_one - 1 ) / 2 ; document . write ( " " + total_XOR_pairs + " " ) ; document . write ( " " + total_AND_pairs + " " ) ; document . write ( " " + total_OR_pairs + " " ) ; } let a = [ 1 , 3 , 4 , 2 ] ; let n = a . length ; CalculatePairs ( a , n ) ;

Index/key variables: i
Accumulator variables: cnt_one, cnt_zero, i
Iterator variables: i
Javascript program:
function isSubsetAndZero ( array , len , N ) { var arrAnd = array [ 0 ] ; for ( var i = 1 ; i < len ; i ++ ) { arrAnd = arrAnd & array [ i ] ; } if ( ( arrAnd & N ) == 0 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } var array = [ 1 , 2 , 4 ] ; var len = array . length ; var N = 3 ; isSubsetAndZero ( array , len , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculateSum ( n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + ( 1 << i ) ; } return sum ; } let n = 10 ; document . write ( " " + calculateSum ( n ) )

Accumulator variables: i
Iterator variables: i
Javascript program:
function printCombinations ( a , n , m ) { for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { let sum = 0 ; let num = 1 << ( n - 1 ) ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( i & num ) > 0 ) sum += a [ j ] ; else sum += ( - 1 * a [ j ] ) ; num = num >> 1 ; } if ( sum % m == 0 ) { num = 1 << ( n - 1 ) ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( i & num ) > 0 ) document . write ( " " + a [ j ] + " " ) ; else document . write ( " " + a [ j ] + " " ) ; num = num >> 1 ; } document . write ( " " ) ; } } } let a = [ 3 , 5 , 6 , 8 ] ; let n = a . length ; let m = 5 ; printCombinations ( a , n , m ) ;

Index/key variables: j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function __builtin_popcount ( n ) { var d , t = 0 ; while ( n > 0 ) { d = n % 2 ; n = parseInt ( n / 2 ) ; if ( d == 1 ) t ++ ; } return t ; } function smallerNumsWithSameSetBits ( n ) { var temp = __builtin_popcount ( n ) ; var count = 0 ; for ( var i = n - 1 ; i > 0 ; i -- ) { if ( temp == __builtin_popcount ( i ) ) count ++ ; } return count ; } var n = 4 ; document . write ( smallerNumsWithSameSetBits ( n ) ) ;

Accumulator variables: count, i, t
Iterator variables: i
Javascript program:
let N = 1000 ; let tree = new Array ( N ) ; tree . fill ( 0 ) ; let level = new Array ( N ) ; level . fill ( 0 ) ; function constructTree ( low , high , pos , a ) { if ( low == high ) { level [ pos ] = 0 ; tree [ pos ] = a [ high ] ; return ; } let mid = parseInt ( ( low + high ) / 2 , 10 ) ; constructTree ( low , mid , 2 * pos + 1 , a ) ; constructTree ( mid + 1 , high , 2 * pos + 2 , a ) ; level [ pos ] = level [ 2 * pos + 1 ] + 1 ; if ( ( level [ pos ] & 1 ) > 0 ) tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ] ; else tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ] ; } function update ( low , high , pos , index , a ) { if ( low == high && low == index ) { tree [ pos ] = a [ low ] ; return ; } if ( index < low index > high ) return ; if ( low != high ) { let mid = parseInt ( ( low + high ) / 2 , 10 ) ; update ( low , mid , 2 * pos + 1 , index , a ) ; update ( mid + 1 , high , 2 * pos + 2 , index , a ) ; if ( ( level [ pos ] & 1 ) > 0 ) tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ] ; else tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ] ; } } function updateValue ( index , value , a , n ) { a [ index ] = value ; update ( 0 , n - 1 , 0 , index , a ) ; static public void Main ( ) { } let a = [ 1 , 4 , 5 , 6 ] ; let n = a . length ; ; constructTree ( 0 , n - 1 , 0 , a ) ; let index = 0 ; let value = 2 ; updateValue ( index , value , a , n ) ; document . write ( tree [ 0 ] + " " ) ; index = 3 ; value = 5 ; updateValue ( index , value , a , n ) ; document . write ( tree [ 0 ] ) ;

Index/key variables: high, index, low, pos
Javascript program:
function evenbitsetnumber ( n ) { let count = 0 , res = 0 ; for ( let temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return ( n res ) ; } let n = 10 ; document . write ( evenbitsetnumber ( n ) ) ;

Accumulator variables: count, res
Iterator variables: temp
Javascript program:
function getmsb ( n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( n + 1 ) >> 1 ; } function getevenbits ( n ) { n = getmsb ( n ) ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; if ( ( n & 1 ) == 1 ) n = n >> 1 ; return n ; } function setallevenbits ( n ) { return n | getevenbits ( n ) ; } let n = 10 ; document . write ( setallevenbits ( n ) ) ;

Accumulator variables: n
Javascript program:
function oddbitsetnumber ( n ) { let count = 0 ; let res = 0 ; for ( let temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return ( n res ) ; } let n = 10 ; document . write ( oddbitsetnumber ( n ) ) ;

Accumulator variables: count, res
Iterator variables: temp
Javascript program:
function getmsb ( n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( n + 1 ) >> 1 ; } function getevenbits ( n ) { n = getmsb ( n ) ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; if ( ( n & 1 ) == 0 ) n = n >> 1 ; return n ; } function setalloddbits ( n ) { return n | getevenbits ( n ) ; } let n = 10 ; document . write ( setalloddbits ( n ) ) ;

Accumulator variables: n
Javascript program:
function findUniquePair ( arr , n ) { let XOR = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) XOR = XOR ^ arr [ i ] ; let set_bit_no = XOR & ~ ( XOR - 1 ) ; let x = 0 , y = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & set_bit_no ) > 0 ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } document . write ( " " + x + " " + y + " " + " " ) ; } let a = [ 6 , 1 , 3 , 5 , 1 , 3 , 7 , 6 ] ; let n = a . length ; findUniquePair ( a , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countUnsetBits ( n ) { let x = n ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return BitCount ( x ^ n ) ; } function BitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let n = 17 ; document . write ( countUnsetBits ( n ) ) ;

Accumulator variables: n, setBits
Javascript program:
function countBits ( n ) { var count = 0 ; while ( n != 0 ) { count ++ ; n >>= 1 ; } return count ; } var i = 65 ; document . write ( countBits ( i ) ) ;

Accumulator variables: count
Javascript program:
let INT_MAX = 2147483647 ; function isKthBitSet ( x , k ) { return ( ( x & ( 1 << ( k - 1 ) ) ) > 0 ) ? 1 : 0 ; } function leftmostSetBit ( x ) { let count = 0 ; while ( x > 0 ) { count ++ ; x = x >> 1 ; } return count ; } function isBinPalindrome ( x ) { let l = leftmostSetBit ( x ) ; let r = 1 ; while ( l > r ) { if ( isKthBitSet ( x , l ) != isKthBitSet ( x , r ) ) return 0 ; l -- ; r ++ ; } return 1 ; } function findNthPalindrome ( n ) { let pal_count = 0 ; let i = 0 ; for ( i = 1 ; i <= INT_MAX ; i ++ ) { if ( isBinPalindrome ( i ) > 0 ) { pal_count ++ ; } if ( pal_count == n ) break ; } return i ; } let n = 9 ; document . write ( findNthPalindrome ( n ) ) ;

Accumulator variables: count, i, l, pal_count, r
Iterator variables: i
Javascript program:
function getNext ( n ) { let c = n ; let c0 = 0 ; let c1 = 0 ; while ( ( ( c & 1 ) == 0 ) && ( c != 0 ) ) { c0 ++ ; c >>= 1 ; } while ( ( c & 1 ) == 1 ) { c1 ++ ; c >>= 1 ; } if ( c0 + c1 == 31 c0 + c1 == 0 ) return - 1 ; return n + ( 1 << c0 ) + ( 1 << ( c1 - 1 ) ) - 1 ; } let n = 5 ; document . write ( getNext ( n ) + " " ) ; n = 8 ; document . write ( getNext ( n ) ) ;

Accumulator variables: c0, c1
Javascript program:
function totalFlips ( A , B , C , N ) { let count = 0 ; for ( let i = 0 ; i < N ; ++ i ) { if ( A [ i ] == B [ i ] && C [ i ] == ' ' ) ++ count ; else if ( A [ i ] != B [ i ] && C [ i ] == ' ' ) ++ count ; } return count ; } let N = 5 ; let a = " " ; let b = " " ; let c = " " ; document . write ( totalFlips ( a , b , c , N ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function findTwoMissingNumbers ( arr , n ) { let XOR = arr [ 0 ] ; for ( let i = 1 ; i < n - 2 ; i ++ ) XOR ^= arr [ i ] ; for ( let i = 1 ; i <= n ; i ++ ) XOR ^= i ; let set_bit_no = XOR & ~ ( XOR - 1 ) ; for ( let i = 0 ; i < n - 2 ; i ++ ) { if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } for ( let i = 1 ; i <= n ; i ++ ) { if ( i & set_bit_no ) x = x ^ i ; else y = y ^ i ; } document . write ( ` ${ x } ${ y } ` ) ; } let arr = [ 1 , 3 , 5 , 6 ] ; n = 2 + arr . length ; findTwoMissingNumbers ( arr , n ) ;

Index/key variables: i
Accumulator variables: XOR, i
Iterator variables: i
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n != 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } function findProffesion ( level , pos ) { let c = countSetBits ( pos - 1 ) ; return ( c % 2 != 0 ) ? ' ' : ' ' ; } let level = 3 , pos = 4 ; let prof = ( findProffesion ( level , pos ) == ' ' ) ? " " : " " ; document . write ( prof ) ; }

Accumulator variables: count, n
Javascript program:
function Max_Xor ( arr , n , k ) { let maxXor = Number . MIN_VALUE ; for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { if ( bitCount ( i ) == k ) { let cur_xor = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) cur_xor = cur_xor ^ arr [ j ] ; } maxXor = Math . max ( maxXor , cur_xor ) ; } } return maxXor ; } function bitCount ( x ) { let setBits = 0 ; while ( x != 0 ) { x = x & ( x - 1 ) ; setBits ++ ; } return setBits ; } let arr = [ 2 , 5 , 4 , 1 , 3 , 7 , 6 , 8 ] ; let n = arr . length ; let k = 3 ; document . write ( Max_Xor ( arr , n , k ) ) ;

Index/key variables: j
Accumulator variables: i, j, setBits
Iterator variables: i, j
Javascript program:
function Divisible ( arr , n ) { let count_even = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 0 ) count_even ++ ; return count_even + parseInt ( ( n - count_even ) / 2 ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; document . write ( Divisible ( arr , n ) ) ;

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