dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function sumOfSeries ( a , num ) { let res = 0 , prev = 1 ; for ( let i = 1 ; i <= num ; i ++ ) { prev *= ( a / i ) ; res = res + prev ; } return ( res ) ; } let n = 5 , a = 2 ; document . write ( sumOfSeries ( a , n ) ) ;

Accumulator variables: i, prev
Iterator variables: i
Javascript program:
function print_sequence ( n , k ) { let b = parseInt ( n / ( k * ( k + 1 ) / 2 ) ) ; if ( b == 0 ) { document . write ( - 1 ) ; } else { let r = 1 ; for ( let x = 1 ; x * x <= n ; x ++ ) { if ( n % x != 0 ) continue ; if ( x <= b && x > r ) r = x ; if ( n / x <= b && n / x > r ) r = n / x ; } for ( let i = 1 ; i < k ; i ++ ) document . write ( r * i + " " ) ; let res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ; document . write ( res + " " ) ; } } let n = 24 ; let k = 4 ; print_sequence ( n , k ) ; n = 24 ; k = 5 ; print_sequence ( n , k ) ; n = 6 ; k = 4 ; print_sequence ( n , k ) ;

Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
function printTrib ( n ) { let dp = Array . from ( { length : n } , ( _ , i ) => 0 ) ; dp [ 0 ] = dp [ 1 ] = 0 ; dp [ 2 ] = 1 ; for ( let i = 3 ; i < n ; i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + dp [ i - 3 ] ; for ( let i = 0 ; i < n ; i ++ ) document . write ( dp [ i ] + " " ) ; } let n = 10 ; printTrib ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function multiply ( T , M ) { var a , b , c , d , e , f , g , h , i ; a = T [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 0 ] ; b = T [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 1 ] ; c = T [ 0 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 2 ] ; d = T [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 0 ] ; e = T [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 1 ] ; f = T [ 1 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 2 ] ; g = T [ 2 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 0 ] ; h = T [ 2 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 1 ] ; i = T [ 2 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 2 ] ; T [ 0 ] [ 0 ] = a ; T [ 0 ] [ 1 ] = b ; T [ 0 ] [ 2 ] = c ; T [ 1 ] [ 0 ] = d ; T [ 1 ] [ 1 ] = e ; T [ 1 ] [ 2 ] = f ; T [ 2 ] [ 0 ] = g ; T [ 2 ] [ 1 ] = h ; T [ 2 ] [ 2 ] = i ; } function power ( T , n ) { if ( n == 0 n == 1 ) return ; var M = [ [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ] ; power ( T , parseInt ( n / 2 ) ) ; multiply ( T , T ) ; if ( n % 2 != 0 ) multiply ( T , M ) ; } function tribonacci ( n ) { var T = [ [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ] ; if ( n == 0 n == 1 ) return 0 ; else power ( T , n - 2 ) ; return T [ 0 ] [ 0 ] ; } var n = 10 ; for ( var i = 0 ; i < n ; i ++ ) document . write ( tribonacci ( i ) + " " ) ; document . write ( ' ' ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function geometricMean ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum = sum + Math . log ( arr [ i ] ) ; sum = sum / n ; return Math . exp ( sum ) ; } var arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ; var n = arr . length ; document . write ( geometricMean ( arr , n ) . toFixed ( 5 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallestNumber ( n ) { if ( n >= 0 && n <= 9 ) { return n ; } let digits = [ ] ; for ( let i = 9 ; i >= 2 && n > 1 ; i -- ) { while ( n % i == 0 ) { digits . push ( i ) ; n = Math . floor ( n / i ) ; } } if ( n != 1 ) { return - 1 ; } let k = 0 ; while ( digits . length != 0 ) { k = k * 10 + digits [ digits . length - 1 ] ; digits . pop ( ) ; } return k ; } let n = 100 ; document . write ( smallestNumber ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function isMagic ( n ) { var sum = 0 ; while ( n > 0 sum > 9 ) { if ( n = 0 ) { n = sum ; sum = 0 ; } sum += n % 10 ; n /= 10 ; } return ( sum = 1 ) ; } var n = 1234 ; if ( isMagic ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: n, sum
Javascript program:
let N = 1000000007 ; function printSequence ( n ) { let a = 1 ; let ans = 2 ; for ( let i = 1 ; i <= n ; i ++ ) { document . write ( ans + " " ) ; ans = ( ( a % N ) * ( ans % N ) ) % N ; a = ans ; ans = ( ans + 1 ) % N ; } } let n = 6 ; printSequence ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findSum ( n ) { let sum = 0 ; for ( let x = 1 ; x <= n ; x ++ ) sum = sum + x ; return sum ; } let n = 5 ; document . write ( findSum ( n ) ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
let c = 0 ; function HailstoneNumbers ( N ) { document . write ( N + " " ) ; if ( N == 1 && c == 0 ) { return c ; } else if ( N == 1 && c != 0 ) { c ++ ; return c ; } else if ( N % 2 == 0 ) { c ++ ; HailstoneNumbers ( N / 2 ) ; } else if ( N % 2 != 0 ) { c ++ ; HailstoneNumbers ( 3 * N + 1 ) ; } return c ; } let N = 7 ; let x ; x = HailstoneNumbers ( N ) ; document . write ( " " ) ; document . write ( " " + x ) ;

Accumulator variables: c
Javascript program:
function count ( x , y ) { let m = new Map ( ) ; while ( x % y != 0 ) { x = x % y ; ans ++ ; if ( m . has ( x ) ) return - 1 ; m . set ( x , 1 ) ; x = x * 10 ; } return ans ; } let res = count ( 1 , 2 ) ; if ( ( res == - 1 ) ) document . write ( " " + " " ) ; else document . write ( res + " " ) ; res = count ( 5 , 3 ) ; if ( ( res == - 1 ) ) document . write ( " " + " " ) ; else document . write ( res + " " ) ; res = count ( 3 , 5 ) ; if ( ( res == - 1 ) ) document . write ( " " + " " ) ; else document . write ( res + " " ) ;

Accumulator variables: ans
Javascript program:
function divCount ( n ) { var hash = Array ( n + 1 ) . fill ( true ) ; for ( var p = 2 ; p * p < n ; p ++ ) if ( hash [ p ] == true ) for ( var i = p * 2 ; i < n ; i += p ) hash [ i ] = false ; var total = 1 ; for ( var p = 2 ; p <= n ; p ++ ) { if ( hash [ p ] ) { var count = 0 ; if ( n % p == 0 ) { while ( n % p == 0 ) { n = parseInt ( n / p ) ; count ++ ; } total = total * ( count + 1 ) ; } } } return total ; } var n = 24 ; document . write ( divCount ( n ) ) ;

Index/key variables: i, p
Accumulator variables: count, i, p
Iterator variables: i, p
Javascript program:
function getMax ( Arr ) { let max = Arr [ 0 ] ; for ( let i = 1 ; i < Arr . length ; i ++ ) if ( Arr [ i ] > max ) max = Arr [ i ] ; return max ; } function maxPrimefactorNum ( N ) { let arr = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 2 ; i * i <= N ; i ++ ) { if ( arr [ i ] == 0 ) for ( let j = 2 * i ; j <= N ; j += i ) arr [ j ] ++ ; arr [ i ] = 1 ; } return getMax ( arr ) ; } let N = 40 ; document . write ( maxPrimefactorNum ( N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isBalancePossible ( T , a ) { let baseForm = [ ] ; let s = 0 ; while ( T > 0 ) { baseForm . push ( T % a ) ; T = Math . floor ( T / a ) ; s ++ ; } baseForm . push ( 0 ) ; for ( let i = 0 ; i < s ; i ++ ) { if ( baseForm [ i ] != 0 && baseForm [ i ] != 1 && baseForm [ i ] != ( a - 1 ) && baseForm [ i ] != a ) { return false ; } if ( baseForm [ i ] == a || baseForm [ i ] == ( a - 1 ) ) { baseForm . splice ( i + 1 , 0 , baseForm [ i + 1 ] + 1 ) ; } } return true ; } let T = 11 ; let a = 4 ; let balancePossible = isBalancePossible ( T , a ) ; if ( balancePossible ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
function primesInRange ( n ) { let fact = 1 ; for ( let k = 2 ; k < n ; k ++ ) { fact = fact * ( k - 1 ) ; if ( ( fact + 1 ) % k == 0 ) document . write ( ( k + " " ) ) ; } } let n = 15 ; primesInRange ( n ) ;

Accumulator variables: k
Iterator variables: k
Javascript program:
var EPS = 1e-9 ; function productPuzzle ( a , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += Math . log10 ( a [ i ] ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( parseInt ( ( EPS + Math . pow ( 10.00 , sum - Math . log10 ( a [ i ] ) ) ) ) + " " ) ; } var a = [ 10 , 3 , 5 , 6 , 2 ] ; var n = a . length ; document . write ( " " ) ; productPuzzle ( a , n ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function changeEvenBits ( n ) { let to_subtract = 0 ; let m = 0 ; for ( x = n ; x ; x >>= 2 ) { if ( x & 1 ) to_subtract += ( 1 << m ) ; m += 2 ; } return n - to_subtract ; } n = 30 ; document . write ( changeEvenBits ( n ) ) ;

Accumulator variables: m, to_subtract
Iterator variables: x
Javascript program:
function checkPronic ( x ) { for ( var i = 0 ; i <= parseInt ( Math . sqrt ( x ) ) ; i ++ ) if ( x == i * ( i + 1 ) ) return true ; return false ; } for ( var i = 0 ; i <= 200 ; i ++ ) if ( checkPronic ( i ) ) document . write ( i + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinSum ( num ) { let sum = 0 ; for ( let i = 2 ; i * i <= num ; i ++ ) { while ( num % i == 0 ) { sum += i ; num /= i ; } } sum += num ; return sum ; } let num = 12 ; document . write ( findMinSum ( num ) ) ;

Accumulator variables: i, num, sum
Iterator variables: i
Javascript program:
function findMin ( sum ) { var a = 0 , b = 0 ; while ( sum > 0 ) { if ( sum % 7 == 0 ) { b ++ ; sum -= 7 ; } else if ( sum % 4 == 0 ) { a ++ ; sum -= 4 ; } else { a ++ ; sum -= 4 ; } } if ( sum < 0 ) { document . write ( " " ) ; return ; } for ( i = 0 ; i < a ; i ++ ) document . write ( " " ) ; for ( i = 0 ; i < b ; i ++ ) document . write ( " " ) ; document . write ( ) ; } findMin ( 15 ) ;

Accumulator variables: a, b, i, sum
Iterator variables: i
Javascript program:
function minNum ( arr , n ) { let odd = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 != 0 ) odd += 1 ; return ( ( odd % 2 ) != 0 ) ? 1 : 2 ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let n = arr . length ; document . write ( minNum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Javascript program:
function printMaxNum ( num ) { let count = new Array ( 10 ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } let str = num . toString ( ) ; for ( let i = 0 ; i < str . length ; i ++ ) count [ str [ i ] - ' ' ] ++ ; let result = 0 , multiplier = 1 ; for ( let i = 0 ; i <= 9 ; i ++ ) { while ( count [ i ] > 0 ) { result = result + ( i * multiplier ) ; count [ i ] -- ; multiplier = multiplier * 10 ; } } return result ; } let num = 38293367 ; document . write ( printMaxNum ( num ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function largestNumber ( num ) { var n = num . length ; var rightMax = Array ( n ) , right ; rightMax [ n - 1 ] = - 1 ; right = n - 1 ; for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( num [ i ] < num [ right ] ) rightMax [ i ] = right ; else { rightMax [ i ] = - 1 ; right = i ; } } for ( var i = 0 ; i < n ; i ++ ) { if ( rightMax [ i ] != - 1 ) { var tmp = num [ i ] ; num [ i ] = num [ rightMax [ i ] ] ; num [ rightMax [ i ] ] = tmp break ; } } return num . join ( ' ' ) ; } var num = " " . split ( ' ' ) ; document . write ( " " + largestNumber ( num ) ) ;

Index/key variables: i, right
Accumulator variables: i
Iterator variables: i
Javascript program:
function nCr ( n , r ) { if ( r > n / 2 ) r = n - r ; let answer = 1 ; for ( let i = 1 ; i <= r ; i ++ ) { answer *= ( n - r + i ) ; answer /= i ; } return answer ; } function binomialProbability ( n , k , p ) { return nCr ( n , k ) * Math . pow ( p , k ) * Math . pow ( 1 - p , n - k ) ; } let n = 10 ; let k = 5 ; let p = 1.0 / 3 ; let probability = binomialProbability ( n , k , p ) ; document . write ( " " + k ) ; document . write ( " " + n ) ; document . write ( " " + p ) ; document . write ( " " + probability ) ;

Accumulator variables: answer, i
Iterator variables: i
Javascript program:
function findMaxGCD ( arr , n ) { var high = 0 ; for ( var i = 0 ; i < n ; i ++ ) high = Math . max ( high , arr [ i ] ) ; var divisors = Array . from ( { length : high + 1 } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 1 ; j <= Math . sqrt ( arr [ i ] ) ; j ++ ) { if ( arr [ i ] % j == 0 ) { divisors [ j ] ++ ; if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ; } } } for ( var i = high ; i >= 1 ; i -- ) if ( divisors [ i ] > 1 ) return i ; return 1 ; } var arr = [ 1 , 2 , 4 , 8 , 8 , 12 ] ; var n = arr . length ; document . write ( findMaxGCD ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMaxGCD ( arr , n ) { var high = 0 ; for ( let i = 0 ; i < n ; i ++ ) high = Math . max ( high , arr [ i ] ) ; var count = Array ( high + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] ++ ; var counter = 0 ; for ( let i = high ; i >= 1 ; i -- ) { var j = i ; while ( j <= high ) { if ( count [ j ] > 0 ) counter += count [ j ] ; j += i ; if ( counter == 2 ) return i ; } counter = 0 ; } return 1 ; } var arr = [ 1 , 2 , 4 , 8 , 8 , 12 ] ; var n = arr . length ; document . write ( findMaxGCD ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: counter, i, j
Iterator variables: i
Javascript program:
function CountPairs ( n ) { let k = n ; let imin = 1 ; let ans = 0 ; while ( imin <= n ) { let imax = Math . floor ( n / k ) ; ans += k * ( imax - imin + 1 ) ; imin = imax + 1 ; k = Math . floor ( n / imin ) ; } return ans ; } document . write ( CountPairs ( 1 ) + " " ) ; document . write ( CountPairs ( 2 ) + " " ) ; document . write ( CountPairs ( 3 ) + " " ) ;

Accumulator variables: ans
Javascript program:
let MAX = 100001 ; class pair { constructor ( f , s ) { this . F = f ; this . S = s ; } } let factors = new Array ( MAX ) ; function sieveOfEratothenese ( ) { let isPrime = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { isPrime [ i ] = true ; } isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( let i = 2 ; i < MAX ; i ++ ) { if ( isPrime [ i ] ) { for ( let j = i ; j < MAX ; j += i ) { let k , l ; isPrime [ j ] = false ; for ( k = j , l = 0 ; k % i == 0 ; l ++ , k = Math . floor ( k / i ) ) ; factors [ j ] . push ( new pair ( i , l ) ) ; } } } } function sumOfProperDivisors ( num ) { let mul = 1 ; for ( let i = 0 ; i < factors [ num ] . length ; i ++ ) mul *= Math . floor ( ( Math . pow ( factors [ num ] [ i ] . F , factors [ num ] [ i ] . S + 1 ) - 1 ) / ( factors [ num ] [ i ] . F - 1 ) ) ; return mul - num ; } for ( let i = 0 ; i < MAX ; i ++ ) factors [ i ] = [ ] ; sieveOfEratothenese ( ) ; let arr = [ 8 , 13 , 24 , 36 , 59 , 75 , 91 ] ; for ( let i = 0 ; i < arr . length ; i ++ ) document . write ( sumOfProperDivisors ( arr [ i ] ) + " " ) ; document . write ( " " ) ;

Index/key variables: i, j, num
Accumulator variables: i, j, l, mul
Iterator variables: i, j, k
Class/struct names: pair
Javascript program:
function PowerOFPINnfactorial ( n , p ) { let ans = 0 ; let temp = p ; while ( temp <= n ) { ans += n / temp ; temp = temp * p ; } return ans ; } document . write ( PowerOFPINnfactorial ( 4 , 2 ) ) ;

Accumulator variables: ans
Javascript program:
function decimalToBinary ( N ) { var B_Number = 0 ; var cnt = 0 ; while ( N != 0 ) { var rem = N % 2 ; var c = Math . pow ( 10 , cnt ) ; B_Number += rem * c ; N = parseInt ( N / 2 ) ; cnt ++ ; } return B_Number ; } var N = 17 ; document . write ( decimalToBinary ( N ) ) ;

Accumulator variables: B_Number, cnt
Javascript program:
function binaryToDecimal ( n ) { let num = n ; let dec_value = 0 ; let base = 1 ; let temp = num ; while ( temp ) { let last_digit = temp % 10 ; temp = Math . floor ( temp / 10 ) ; dec_value += last_digit * base ; base = base * 2 ; } return dec_value ; } let num = 10101001 ; document . write ( binaryToDecimal ( num ) + " " ) ;

Accumulator variables: dec_value
Javascript program:
function countXorPair ( arr , n ) { let odd = 0 , even = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } return odd * even ; } let arr = [ 1 , 2 , 3 ] ; document . write ( countXorPair ( arr , arr . length ) ) ;

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Javascript program:
var MAX_ITERATIONS = 20 ; function isLychrel ( number ) { for ( var i = 0 ; i < MAX_ITERATIONS ; i ++ ) { number = number + reverse ( number ) ; if ( isPalindrome ( number ) ) return false ; } return true ; } function isPalindrome ( number ) { return number == reverse ( number ) ; } function reverse ( number ) { var reverse = 0 ; while ( number > 0 ) { var remainder = number % 10 ; reverse = ( reverse * 10 ) + remainder ; number = parseInt ( number / 10 ) ; } return reverse ; } var number = 295 ; document . write ( number + " " + isLychrel ( number ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
const MAX_ITERATIONS = 10000 ; function f ( x ) { return 1 * Math . pow ( x , 3 ) + 2 * x * x + 10 * x - 20 ; } function Muller ( a , b , c ) { let i ; let res ; for ( i = 0 ; ; ++ i ) { let f1 = f ( a ) ; let f2 = f ( b ) ; let f3 = f ( c ) ; let d1 = f1 - f3 ; let d2 = f2 - f3 ; let h1 = a - c ; let h2 = b - c ; let a0 = f3 ; let a1 = ( ( ( d2 * Math . pow ( h1 , 2 ) ) - ( d1 * Math . pow ( h2 , 2 ) ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ; let a2 = ( ( ( d1 * h2 ) - ( d2 * h1 ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ; let x = ( ( - 2 * a0 ) / ( a1 + Math . abs ( Math . sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ; let y = ( ( - 2 * a0 ) / ( a1 - Math . abs ( Math . sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ; if ( x >= y ) res = x + c ; else res = y + c ; let m = res * 100 ; let n = c * 100 ; m = Math . floor ( m ) ; n = Math . floor ( n ) ; if ( m == n ) break ; a = b ; b = c ; c = res ; if ( i > MAX_ITERATIONS ) { document . write ( " " + " " ) ; break ; } } if ( i <= MAX_ITERATIONS ) document . write ( " " + res . toFixed ( 4 ) ) ; } let a = 0 , b = 1 , c = 2 ; Muller ( a , b , c ) ;

Iterator variables: i
Javascript program:
function nthprimedigitsnumber ( n ) { var len = 1 ; var prev_count = 0 ; while ( true ) { var curr_count = ( prev_count + Math . pow ( 4 , len ) ) ; if ( prev_count < n && curr_count >= n ) break ; len ++ ; prev_count = curr_count ; } for ( var i = 1 ; i <= len ; i ++ ) { for ( var j = 1 ; j <= 4 ; j ++ ) { if ( prev_count + Math . pow ( 4 , len - i ) < n ) prev_count += Math . pow ( 4 , len - i ) ; else { if ( j == 1 ) document . write ( " " ) ; else if ( j == 2 ) document . write ( " " ) ; else if ( j == 3 ) document . write ( " " ) ; else if ( j == 4 ) document . write ( " " ) ; break ; } } } document . write ( ' ' ) ; } nthprimedigitsnumber ( 10 ) ; nthprimedigitsnumber ( 21 ) ;

Accumulator variables: i, j, len, prev_count
Iterator variables: i, j
Javascript program:
function findNoIsDivisibleOrNot ( a , n , l ) { for ( let i = 0 ; i < l ; i ++ ) { if ( a [ i ] % n != 0 ) return false ; } return true ; } let a = [ 14 , 12 , 4 , 18 ] ; let n = 2 ; let l = a . length ; if ( findNoIsDivisibleOrNot ( a , n , l ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinValue ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n ; i ++ ) { val += ( Math . log ( ( arr [ i ] ) ) ) ; } let left = arr [ 0 ] , right = arr [ n - 1 ] ; let ans = 0 ; while ( left <= right ) { let mid = Math . floor ( ( left + right ) / 2 ) ; let temp = n * ( Math . log ( ( mid ) ) ) ; if ( val < temp ) { ans = mid ; right = mid - 1 ; } else { left = mid + 1 ; } } return ans ; } let arr = [ 4 , 2 , 1 , 10 , 6 ] ; let n = arr . length ; document . write ( findMinValue ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, val
Iterator variables: i
Javascript program:
function getOccurence ( n , d ) { let result = 0 ; let itr = d ; while ( itr <= n ) { if ( itr % 10 == d ) result ++ ; if ( itr != 0 && Math . floor ( itr / 10 ) == d ) { result ++ ; itr ++ ; } else if ( Math . floor ( itr / 10 ) == d - 1 ) itr = itr + ( 10 - d ) ; else itr = itr + 10 ; } return result ; } let n = 11 ; let d = 1 ; document . write ( getOccurence ( n , d ) ) ;

Accumulator variables: itr, result
Javascript program:
function printUnique ( l , r ) { for ( let i = l ; i <= r ; i ++ ) { let s = String ( i ) ; let uniDigits = new Set ( ) ; for ( let c of s . split ( " " ) ) uniDigits . add ( c ) ; if ( s . length == uniDigits . size ) { document . write ( i + " " ) ; } } } let l = 1 , r = 20 ; printUnique ( l , r ) ;

Accumulator variables: i
Iterator variables: c, i
Javascript program:
let v = [ ] ; function multiply ( x ) { let carry = 0 ; let size = v . length ; for ( let i = 0 ; i < size ; i ++ ) { let res = carry + v [ i ] * x ; v [ i ] = res % 10 ; carry = Math . floor ( res / 10 ) ; } while ( carry != 0 ) { v . push ( carry % 10 ) ; carry = Math . floor ( carry / 10 ) ; } } function findSumOfDigits ( n ) { for ( let i = 1 ; i <= n ; i ++ ) multiply ( i ) ; let sum = 0 ; let size = v . length ; for ( let i = 0 ; i < size ; i ++ ) sum += v [ i ] ; return sum ; } let n = 1000 ; document . write ( findSumOfDigits ( n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function makeOdd ( n ) { if ( n % 2 != 0 ) return 1 ; var i ; for ( i = 2 ; i <= n ; i ++ ) if ( ( n % i == 0 ) && ( ( n / i ) % 2 == 1 ) ) break ; return i ; } var n = 36 ; var res = makeOdd ( n ) ; document . write ( res ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getTotalXorOfSubarrayXors ( arr , N ) { if ( N % 2 == 0 ) return 0 ; let res = 0 ; for ( let i = 0 ; i < N ; i += 2 ) { res ^= arr [ i ] ; } return res ; } let arr = [ 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; document . write ( getTotalXorOfSubarrayXors ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function countIterations ( arr , n ) { var oneFound = false ; var res = 0 ; for ( var i = 0 ; i < n ; ) { if ( arr [ i ] == 1 ) oneFound = true ; while ( i < n && arr [ i ] == 1 ) i ++ ; var count_zero = 0 ; while ( i < n && arr [ i ] == 0 ) { count_zero ++ ; i ++ ; } if ( oneFound == false && i == n ) return - 1 ; var curr_count ; if ( i < n && oneFound == true ) { if ( ( count_zero & 1 ) == 0 ) curr_count = count_zero / 2 ; else curr_count = ( count_zero + 1 ) / 2 ; count_zero = 0 ; } else { curr_count = count_zero ; count_zero = 0 ; } res = Math . max ( res , curr_count ) ; } return res ; } var arr = [ 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ; document . write ( countIterations ( arr , arr . length ) ) ;

Index/key variables: i
Accumulator variables: count_zero, i
Iterator variables: i
Boolean variables: oneFound
Javascript program:
var MAX = 100 ; var arr = new Array ( MAX ) ; arr [ 0 ] = 0 ; arr [ 1 ] = 1 ; for ( var i = 2 ; i < MAX ; i ++ ) arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ] ; document . write ( " " ) ; for ( var i = 1 ; i < MAX ; i ++ ) if ( arr [ i ] % i == 0 ) document . write ( i + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printConsecutive ( last , first ) { document . write ( first ++ ) ; for ( let x = first ; x <= last ; x ++ ) document . write ( " " + x ) ; } function findConsecutive ( N ) { for ( let last = 1 ; last < N ; last ++ ) { for ( let first = 0 ; first < last ; first ++ ) { if ( 2 * N == ( last - first ) * ( last + first + 1 ) ) { document . write ( N + " " ) ; printConsecutive ( last , first + 1 ) ; return ; } } } document . write ( " " ) ; } let n = 12 ; findConsecutive ( n ) ;

Accumulator variables: first, last, x
Iterator variables: first, last, x
Javascript program:
function printNthElement ( n ) { var arr = Array ( n + 1 ) . fill ( 0 ) ; arr [ 1 ] = 4 ; arr [ 2 ] = 7 ; for ( var i = 3 ; i <= n ; i ++ ) { if ( i % 2 != 0 ) arr [ i ] = arr [ i / 2 ] * 10 + 4 ; else arr [ i ] = arr [ ( i / 2 ) - 1 ] * 10 + 7 ; } return arr [ n ] ; } var n = 6 ; document . write ( printNthElement ( n ) ) ;

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