dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function sum ( freq , i , j ) { var s = 0 ; for ( var k = i ; k <= j ; k ++ ) s += freq [ k ] ; return s ; } function optCost ( freq , i , j ) { if ( j < i ) return 0 ; if ( j == i ) return freq [ i ] ; var fsum = sum ( freq , i , j ) ; var min = Number . MAX_SAFE_INTEGER ; for ( var r = i ; r <= j ; ++ r ) { var cost = optCost ( freq , i , r - 1 ) + optCost ( freq , r + 1 , j ) ; if ( cost < min ) min = cost ; } return min + fsum ; } function optimalSearchTree ( keys , freq , n ) { return optCost ( freq , 0 , n - 1 ) ; } var keys = [ 10 , 12 , 20 ] ; var freq = [ 34 , 8 , 50 ] ; var n = keys . length ; document . write ( " " + optimalSearchTree ( keys , freq , n ) ) ;

Index/key variables: i, k
Accumulator variables: k, s
Iterator variables: k, r
Javascript program:
function sum ( freq , i , j ) { var s = 0 ; for ( var k = i ; k <= j ; k ++ ) s += freq [ k ] ; return s ; } function optimalSearchTree ( keys , freq , n ) { var cost = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) cost [ i ] = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) cost [ i ] [ i ] = freq [ i ] ; for ( var L = 2 ; L <= n ; L ++ ) { for ( var i = 0 ; i <= n - L + 1 ; i ++ ) { var j = i + L - 1 ; if ( i >= n j >= n ) break cost [ i ] [ j ] = Number . MAX_SAFE_INTEGER ; for ( var r = i ; r <= j ; r ++ ) { var c = 0 ; if ( r > i ) c += cost [ i ] [ r - 1 ] if ( r < j ) c += cost [ r + 1 ] [ j ] c += sum ( freq , i , j ) ; if ( c < cost [ i ] [ j ] ) cost [ i ] [ j ] = c ; } } } return cost [ 0 ] [ n - 1 ] ; } var keys = [ 10 , 12 , 20 ] ; var freq = [ 34 , 8 , 50 ] ; var n = keys . length ; document . write ( " " + optimalSearchTree ( keys , freq , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: L, c, i, k, r, s
Iterator variables: L, i, k, r
Javascript program:
function countParenth ( symb , oper , n ) { let F = new Array ( n ) ; let T = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { F [ i ] = new Array ( n ) ; T [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { F [ i ] [ j ] = 0 ; T [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) { F [ i ] [ i ] = ( symb [ i ] == ' ' ) ? 1 : 0 ; T [ i ] [ i ] = ( symb [ i ] == ' ' ) ? 1 : 0 ; } for ( let gap = 1 ; gap < n ; ++ gap ) { for ( let i = 0 , j = gap ; j < n ; ++ i , ++ j ) { T [ i ] [ j ] = F [ i ] [ j ] = 0 ; for ( let g = 0 ; g < gap ; g ++ ) { let k = i + g ; let tik = T [ i ] [ k ] + F [ i ] [ k ] ; let tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ; if ( oper [ k ] == ' ' ) { T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ; F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ; } if ( oper [ k ] == ' ' ) { F [ i ] [ j ] += F [ i ] [ k ] * F [ k + 1 ] [ j ] ; T [ i ] [ j ] += ( tik * tkj - F [ i ] [ k ] * F [ k + 1 ] [ j ] ) ; } if ( oper [ k ] == ' ' ) { T [ i ] [ j ] += F [ i ] [ k ] * T [ k + 1 ] [ j ] + T [ i ] [ k ] * F [ k + 1 ] [ j ] ; F [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] + F [ i ] [ k ] * F [ k + 1 ] [ j ] ; } } } } return T [ 0 ] [ n - 1 ] ; } let symbols = " " . split ( ' ' ) ; let operators = " " . split ( ' ' ) ; let n = symbols . length ; document . write ( countParenth ( symbols , operators , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: g, i, j
Iterator variables: g, gap, i, j
Javascript program:
function getCount ( keypad , n ) { if ( keypad == null n <= 0 ) return 0 ; if ( n == 1 ) return 10 ; let row = [ 0 , 0 , - 1 , 0 , 1 ] ; let col = [ 0 , - 1 , 0 , 1 , 0 ] ; let count = new Array ( 10 ) ; for ( let i = 0 ; i < 10 ; i ++ ) { count [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) { count [ i ] [ j ] = 0 ; } } let i = 0 , j = 0 , k = 0 , move = 0 , ro = 0 , co = 0 , num = 0 ; let nextNum = 0 , totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) { count [ i ] [ 0 ] = 0 ; count [ i ] [ 1 ] = 1 ; } for ( k = 2 ; k <= n ; k ++ ) { for ( i = 0 ; i < 4 ; i ++ ) { for ( j = 0 ; j < 3 ; j ++ ) { if ( keypad [ i ] [ j ] != ' ' && keypad [ i ] [ j ] != ' ' ) { num = keypad [ i ] [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; count [ num ] [ k ] = 0 ; for ( move = 0 ; move < 5 ; move ++ ) { ro = i + row [ move ] ; co = j + col [ move ] ; if ( ro >= 0 && ro <= 3 && co >= 0 && co <= 2 && keypad [ ro ] [ co ] != ' ' && keypad [ ro ] [ co ] != ' ' ) { nextNum = keypad [ ro ] [ co ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; count [ num ] [ k ] += count [ nextNum ] [ k - 1 ] ; } } } } } } totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) totalCount += count [ i ] [ n ] ; return totalCount ; } let keypad = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; document . write ( " " + 1 + " " + getCount ( keypad , 1 ) + " " ) document . write ( " " + 2 + " " + getCount ( keypad , 2 ) + " " ) document . write ( " " + 3 + " " + getCount ( keypad , 3 ) + " " ) document . write ( " " + 4 + " " + getCount ( keypad , 4 ) + " " ) document . write ( " " + 5 + " " + getCount ( keypad , 5 ) + " " )

Index/key variables: co, i, j, k, move, n, nextNum, num, ro
Accumulator variables: i, j, k, move, totalCount
Iterator variables: i, j, k, move
Javascript program:
function getCount ( keypad , n ) { if ( keypad == null n <= 0 ) return 0 ; if ( n == 1 ) return 10 ; var odd = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; var even = Array . from ( { length : 10 } , ( _ , i ) => 0 ) ; var i = 0 , j = 0 , useOdd = 0 , totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) odd [ i ] = 1 ; for ( j = 2 ; j <= n ; j ++ ) { useOdd = 1 - useOdd ; if ( useOdd == 1 ) { even [ 0 ] = odd [ 0 ] + odd [ 8 ] ; even [ 1 ] = odd [ 1 ] + odd [ 2 ] + odd [ 4 ] ; even [ 2 ] = odd [ 2 ] + odd [ 1 ] + odd [ 3 ] + odd [ 5 ] ; even [ 3 ] = odd [ 3 ] + odd [ 2 ] + odd [ 6 ] ; even [ 4 ] = odd [ 4 ] + odd [ 1 ] + odd [ 5 ] + odd [ 7 ] ; even [ 5 ] = odd [ 5 ] + odd [ 2 ] + odd [ 4 ] + odd [ 8 ] + odd [ 6 ] ; even [ 6 ] = odd [ 6 ] + odd [ 3 ] + odd [ 5 ] + odd [ 9 ] ; even [ 7 ] = odd [ 7 ] + odd [ 4 ] + odd [ 8 ] ; even [ 8 ] = odd [ 8 ] + odd [ 0 ] + odd [ 5 ] + odd [ 7 ] + odd [ 9 ] ; even [ 9 ] = odd [ 9 ] + odd [ 6 ] + odd [ 8 ] ; } else { odd [ 0 ] = even [ 0 ] + even [ 8 ] ; odd [ 1 ] = even [ 1 ] + even [ 2 ] + even [ 4 ] ; odd [ 2 ] = even [ 2 ] + even [ 1 ] + even [ 3 ] + even [ 5 ] ; odd [ 3 ] = even [ 3 ] + even [ 2 ] + even [ 6 ] ; odd [ 4 ] = even [ 4 ] + even [ 1 ] + even [ 5 ] + even [ 7 ] ; odd [ 5 ] = even [ 5 ] + even [ 2 ] + even [ 4 ] + even [ 8 ] + even [ 6 ] ; odd [ 6 ] = even [ 6 ] + even [ 3 ] + even [ 5 ] + even [ 9 ] ; odd [ 7 ] = even [ 7 ] + even [ 4 ] + even [ 8 ] ; odd [ 8 ] = even [ 8 ] + even [ 0 ] + even [ 5 ] + even [ 7 ] + even [ 9 ] ; odd [ 9 ] = even [ 9 ] + even [ 6 ] + even [ 8 ] ; } } totalCount = 0 ; if ( useOdd == 1 ) { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += even [ i ] ; } else { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += odd [ i ] ; } return totalCount ; } var keypad = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; document . write ( " " + 1 + " " + getCount ( keypad , 1 ) ) ; document . write ( " " + 2 + " " + getCount ( keypad , 2 ) ) ; document . write ( " " + 3 + " " + getCount ( keypad , 3 ) ) ; document . write ( " " + 4 + " " + getCount ( keypad , 4 ) ) ; document . write ( " " + 5 + " " + getCount ( keypad , 5 ) ) ;

Index/key variables: i
Accumulator variables: i, j, totalCount
Iterator variables: i, j
Javascript program:
function countRec ( n , sum ) { if ( n == 0 ) return sum == 0 ; if ( sum == 0 ) return 1 ; let ans = 0 ; for ( let i = 0 ; i <= 9 ; i ++ ) { if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; } return ans ; } function finalCount ( n , sum ) { let ans = 0 ; for ( let i = 1 ; i <= 9 ; i ++ ) { if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; } return ans ; } let n = 2 , sum = 5 ; document . write ( finalCount ( n , sum ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let lookup = new Array ( 101 ) ; function countRec ( n , sum ) { if ( n == 0 ) return sum == 0 ? 1 : 0 ; if ( lookup [ n ] [ sum ] != - 1 ) return lookup [ n ] [ sum ] ; let ans = 0 ; for ( let i = 0 ; i < 10 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return lookup [ n ] [ sum ] = ans ; } function finalCount ( n , sum ) { for ( let i = 0 ; i < 101 ; i ++ ) { lookup [ i ] = new Array ( 501 ) ; for ( let j = 0 ; j < 501 ; j ++ ) { lookup [ i ] [ j ] = - 1 ; } } let ans = 0 ; for ( let i = 1 ; i <= 9 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return ans ; } let n = 3 , sum = 5 ; document . write ( finalCount ( n , sum ) ) ;

Index/key variables: i, j, n, sum
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function findCount ( n , sum ) { let start = Math . pow ( 10 , n - 1 ) ; let end = Math . pow ( 10 , n ) - 1 ; let count = 0 ; let i = start ; while ( i <= end ) { let cur = 0 ; let temp = i ; while ( temp != 0 ) { cur += temp % 10 ; temp = parseInt ( temp / 10 ) ; } if ( cur == sum ) { count ++ ; i += 9 ; } else i ++ ; } document . write ( count ) ; } let n = 3 ; let sum = 5 ; findCount ( n , sum ) ;

Accumulator variables: count, cur, i
Javascript program:
function getMinSquares ( n ) { if ( n <= 3 ) return n ; let res = n ; for ( let x = 1 ; x <= n ; x ++ ) { let temp = x * x ; if ( temp > n ) break ; else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ; } return res ; } document . write ( getMinSquares ( 6 ) ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function getMinSquares ( n ) { if ( n <= 3 ) return n ; var dp = new Array ( n + 1 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; dp [ 3 ] = 3 ; for ( var i = 4 ; i <= n ; i ++ ) { dp [ i ] = i ; for ( var x = 1 ; x <= Math . ceil ( Math . sqrt ( i ) ) ; x ++ ) { var temp = x * x ; if ( temp > i ) break ; else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ; } } var res = dp [ n ] ; return res ; } document . write ( getMinSquares ( 6 ) ) ;

Index/key variables: i, n
Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
function minCoins ( coins , m , V ) { if ( V == 0 ) return 0 ; let res = Number . MAX_VALUE ; for ( let i = 0 ; i < m ; i ++ ) { if ( coins [ i ] <= V ) { let sub_res = minCoins ( coins , m , V - coins [ i ] ) ; if ( sub_res != Number . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ; } } return res ; } let coins = [ 9 , 6 , 5 , 1 ] ; let m = coins . length ; let V = 11 ; document . write ( " " + minCoins ( coins , m , V ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCoins ( coins , m , v ) { let table = new Array ( V + 1 ) ; for ( let i = 0 ; i < V + 1 ; i ++ ) { table [ i ] = 0 ; } for ( let i = 1 ; i <= V ; i ++ ) { table [ i ] = Number . MAX_VALUE ; } for ( let i = 1 ; i <= V ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) if ( coins [ j ] <= i ) { let sub_res = table [ i - coins [ j ] ] ; if ( sub_res != Number . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ; } } if ( table [ V ] == Number . MAX_VALUE ) return - 1 ; return table [ V ] ; } let coins = [ 9 , 6 , 5 , 1 ] ; let m = coins . length ; let V = 11 ; document . write ( " " + minCoins ( coins , m , V ) )

Index/key variables: V, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function superSeq ( X , Y , m , n ) { var dp = Array ( m + 1 ) . fill ( 0 ) . map ( x => Array ( n + 1 ) . fill ( 0 ) ) ; for ( var i = 0 ; i <= m ; i ++ ) { for ( var j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) dp [ i ] [ j ] = j ; else if ( j == 0 ) dp [ i ] [ j ] = i ; else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return dp [ m ] [ n ] ; } var X = " " ; var Y = " " ; document . write ( " " + superSeq ( X , Y , X . length , Y . length ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sumOfDigitsFrom1ToN ( n ) { let result = 0 ; for ( let x = 1 ; x <= n ; x ++ ) result += sumOfDigits ( x ) ; return result ; } function sumOfDigits ( x ) { let sum = 0 ; while ( x != 0 ) { sum += x % 10 ; x = parseInt ( x / 10 , 10 ) ; } return sum ; } let n = 328 ; document . write ( " " + " " + n + " " + sumOfDigitsFrom1ToN ( n ) ) ;

Accumulator variables: result, sum, x
Iterator variables: x
Javascript program:
function sumOfDigitsFrom1ToN ( n ) { if ( n < 10 ) return ( n * ( n + 1 ) / 2 ) ; let d = parseInt ( Math . log ( n ) / Math . log ( 10 ) , 10 ) ; let a = new Array ( d + 1 ) ; a [ 0 ] = 0 ; a [ 1 ] = 45 ; for ( let i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * parseInt ( Math . ceil ( Math . pow ( 10 , i - 1 ) ) , 10 ) ; let p = parseInt ( Math . ceil ( Math . pow ( 10 , d ) ) , 10 ) ; let msd = parseInt ( n / p , 10 ) ; return ( msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + sumOfDigitsFrom1ToN ( n % p ) ) ; } let n = 328 ; document . write ( " " + n + " " + sumOfDigitsFrom1ToN ( n ) ) ;

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfDigitsFrom1ToNUtil ( n , a ) { if ( n < 10 ) return ( n * ( n + 1 ) / 2 ) ; var d = ( parseInt ) ( Math . log10 ( n ) ) ; var p = ( Math . ceil ( Math . pow ( 10 , d ) ) ) ; var msd = ( parseInt ) ( n / p ) ; return ( msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + sumOfDigitsFrom1ToNUtil ( n % p , a ) ) ; } function sumOfDigitsFrom1ToN ( n ) { var d = ( parseInt ) ( Math . log10 ( n ) ) ; var a = new Array ( d + 1 ) . fill ( 0 ) ; a [ 0 ] = 0 ; a [ 1 ] = 45 ; for ( var i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ( parseInt ) ( Math . ceil ( Math . pow ( 10 , i - 1 ) ) ) ; return sumOfDigitsFrom1ToNUtil ( n , a ) ; } var n = 328 ; document . write ( " " + n + " " + sumOfDigitsFrom1ToN ( n ) )

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countWays ( N ) { if ( N == 1 ) return 4 ; let countB = 1 , countS = 1 , prev_countB , prev_countS ; for ( let i = 2 ; i <= N ; i ++ ) { prev_countB = countB ; prev_countS = countS ; countS = prev_countB + prev_countS ; countB = prev_countS ; } let result = countS + countB ; return ( result * result ) ; } N = 3 ; document . write ( " " + N + " " + countWays ( N ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( n ) { let table = new Array ( n + 1 ) , i ; for ( let j = 0 ; j < n + 1 ; j ++ ) table [ j ] = 0 ; table [ 0 ] = 1 ; for ( i = 3 ; i <= n ; i ++ ) table [ i ] += table [ i - 3 ] ; for ( i = 5 ; i <= n ; i ++ ) table [ i ] += table [ i - 5 ] ; for ( i = 10 ; i <= n ; i ++ ) table [ i ] += table [ i - 10 ] ; return table [ n ] ; } let n = 20 ; document . write ( " " + n + " " + count ( n ) + " " ) ; n = 13 ; document . write ( " " + n + " " + count ( n ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function search ( txt , pat ) { let M = pat . length ; let N = txt . length ; for ( let i = 0 ; i <= N - M ; i ++ ) { let j ; for ( j = 0 ; j < M ; j ++ ) if ( txt [ i + j ] != pat [ j ] ) break ; if ( j == M ) document . write ( " " + i + " " ) ; } } let txt = " " ; let pat = " " ; search ( txt , pat ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getMedian ( ar1 , ar2 , n ) { var i = 0 ; var j = 0 ; var count ; var m1 = - 1 , m2 = - 1 ; for ( count = 0 ; count <= n ; count ++ ) { if ( i == n ) { m1 = m2 ; m2 = ar2 [ 0 ] ; break ; } else if ( j == n ) { m1 = m2 ; m2 = ar1 [ 0 ] ; break ; } if ( ar1 [ i ] <= ar2 [ j ] ) { m1 = m2 ; m2 = ar1 [ i ] ; i ++ ; } else { m1 = m2 ; m2 = ar2 [ j ] ; j ++ ; } } return ( m1 + m2 ) / 2 ; } var ar1 = [ 1 , 12 , 15 , 26 , 38 ] ; var ar2 = [ 2 , 13 , 17 , 30 , 45 ] ; var n1 = ar1 . length ; var n2 = ar2 . length ; if ( n1 == n2 ) document . write ( " " + getMedian ( ar1 , ar2 , n1 ) ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: count
Javascript program:
function isLucky ( n ) { let counter = 2 ; let next_position = n ; if ( counter > n ) return 1 ; if ( n % counter == 0 ) return 0 ; next_position -= Math . floor ( next_position / counter ) ; counter ++ ; return isLucky ( next_position ) ; } let x = 5 ; if ( isLucky ( x ) ) document . write ( x + " " ) ; else document . write ( x + " " ) ;

Accumulator variables: counter, next_position
Javascript program:
function pow ( a , b ) { if ( b == 0 ) return 1 ; var answer = a ; var increment = a ; var i , j ; for ( i = 1 ; i < b ; i ++ ) { for ( j = 1 ; j < a ; j ++ ) { answer += increment ; } increment = answer ; } return answer ; } document . write ( pow ( 5 , 3 ) ) ;

Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function maximumNumberDistinctPrimeRange ( m , n ) { let factorCount = new Array ( n + 1 ) ; let prime = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { factorCount [ i ] = 0 ; prime [ i ] = true ; } for ( let i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] == true ) { factorCount [ i ] = 1 ; for ( let j = i * 2 ; j <= n ; j += i ) { factorCount [ j ] ++ ; prime [ j ] = false ; } } } let max = factorCount [ m ] ; let num = m ; for ( let i = m ; i <= n ; i ++ ) { if ( factorCount [ i ] > max ) { max = factorCount [ i ] ; num = i ; } } return num ; } let m = 4 , n = 6 ; document . write ( maximumNumberDistinctPrimeRange ( m , n ) ) ;

Index/key variables: i, j, m
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function fact ( n ) { return ( n <= 1 ) ? 1 : n * fact ( n - 1 ) ; } function findSmallerInRight ( str , low , high ) { let countRight = 0 ; let i ; for ( i = low + 1 ; i <= high ; ++ i ) if ( str [ i ] < str [ low ] ) ++ countRight ; return countRight ; } function findRank ( str ) { let len = ( str ) . length ; let mul = fact ( len ) ; let rank = 1 ; let countRight ; let i ; for ( i = 0 ; i < len ; ++ i ) { mul /= len - i ; countRight = findSmallerInRight ( str , i , len - 1 ) ; rank += countRight * mul ; } return rank ; } let str = " " ; document . write ( findRank ( str ) ) ;

Index/key variables: i, low
Accumulator variables: mul, rank
Iterator variables: i
Javascript program:
function exponential ( n , x ) { var sum = 1 ; for ( i = n - 1 ; i > 0 ; -- i ) sum = 1 + x * sum / i ; return sum ; } var n = 10 ; var x = 1 ; document . write ( " " + exponential ( n , x ) . toFixed ( 6 ) ) ;

Iterator variables: i
Javascript program:
function findCeil ( arr , r , l , h ) { let mid ; while ( l < h ) { mid = l + ( ( h - l ) >> 1 ) ; ( r > arr [ mid ] ) ? ( l = mid + 1 ) : ( h = mid ) ; } return ( arr [ l ] >= r ) ? l : - 1 ; } function myRand ( arr , freq , n ) { let prefix = [ ] ; let i ; prefix [ 0 ] = freq [ 0 ] ; for ( i = 1 ; i < n ; ++ i ) prefix [ i ] = prefix [ i - 1 ] + freq [ i ] ; let r = Math . floor ( ( Math . random ( ) * prefix [ n - 1 ] ) ) + 1 ; let indexc = findCeil ( prefix , r , 0 , n - 1 ) ; return arr [ indexc ] ; } let arr = [ 1 , 2 , 3 , 4 ] ; let freq = [ 10 , 5 , 20 , 100 ] ; let i ; let n = arr . length ; for ( i = 0 ; i < 5 ; i ++ ) document . write ( myRand ( arr , freq , n ) ) ;

Index/key variables: i, indexc, l, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPerfectSquare ( x ) { let s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } for ( let i = 1 ; i <= 10 ; i ++ ) isFibonacci ( i ) ? document . write ( i + " " ) : document . write ( i + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findTrailingZeros ( n ) { let count = 0 ; for ( let i = 5 ; Math . floor ( n / i ) >= 1 ; i *= 5 ) count += Math . floor ( n / i ) ; return count ; } let n = 100 ; document . write ( " " + 100 + " " + findTrailingZeros ( n ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function catalan ( n ) { if ( n <= 1 ) return 1 ; let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ; return res ; } for ( let i = 0 ; i < 10 ; i ++ ) document . write ( catalan ( i ) + " " ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function catalanDP ( n ) { let catalan = [ ] ; catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( let j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } for ( let i = 0 ; i < 10 ; i ++ ) document . write ( catalanDP ( i ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res = Math . floor ( res / ( i + 1 ) ) ; } return res ; } function catalan ( n ) { c = binomialCoeff ( 2 * ( n ) , n ) ; return Math . floor ( c / ( n + 1 ) ) ; } for ( let i = 0 ; i < 10 ; i ++ ) document . write ( catalan ( i ) + " " ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function catalan ( n ) { let cat_ = 1 ; document . write ( cat_ + " " ) ; for ( let i = 1 ; i < n ; i ++ ) { cat_ *= ( 4 * i - 2 ) ; cat_ /= ( i + 1 ) ; document . write ( cat_ + " " ) ; } } let n = 5 ; catalan ( n ) ;

Accumulator variables: cat_, i
Iterator variables: i
Javascript program:
function printString ( n ) { let arr = [ ] ; let i = 0 ; while ( n ) { arr [ i ] = n % 26 ; n = Math . floor ( n / 26 ) ; i ++ ; } for ( let j = 0 ; j < i - 1 ; j ++ ) { if ( arr [ j ] <= 0 ) { arr [ j ] += 26 ; arr [ j + 1 ] = arr [ j + 1 ] - 1 ; } } let ans = ' ' ; for ( let j = i ; j >= 0 ; j -- ) { if ( arr [ j ] > 0 ) ans += String . fromCharCode ( 65 + arr [ j ] - 1 ) ; } document . write ( ans + " " ) ; } printString ( 26 ) ; printString ( 51 ) ; printString ( 52 ) ; printString ( 80 ) ; printString ( 676 ) ; printString ( 702 ) ; printString ( 705 ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: j
Javascript program:
function min ( x , y ) { return ( x < y ) ? x : y ; } function calcAngle ( h , m ) { if ( h < 0 m < 0 h > 12 m > 60 ) document . write ( " " ) ; if ( h == 12 ) h = 0 ; if ( m == 60 ) { m = 0 ; h += 1 ; if ( h > 12 ) h = h - 12 ; } let hour_angle = 0.5 * ( h * 60 + m ) ; let minute_angle = 6 * m ; let angle = Math . abs ( hour_angle - minute_angle ) ; angle = min ( 360 - angle , angle ) ; return angle ; } document . write ( calcAngle ( 9 , 60 ) + " " ) ; document . write ( calcAngle ( 3 , 30 ) + " " ) ;

Accumulator variables: h
Javascript program:
function getInvCount ( arr ) { let inv_count = 0 ; for ( let i = 0 ; i < 2 ; i ++ ) { for ( let j = i + 1 ; j < 3 ; j ++ ) { if ( arr [ j ] [ i ] > 0 && arr [ j ] [ i ] > arr [ i ] [ j ] ) inv_count += 1 ; } } return inv_count ; } function isSolvable ( puzzle ) { let invCount = getInvCount ( puzzle ) ; return ( invCount % 2 == 0 ) ; } puzzle = [ [ 1 , 8 , 2 ] , [ 0 , 4 , 3 ] , [ 7 , 6 , 5 ] ] ; if ( isSolvable ( puzzle ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, inv_count, j
Iterator variables: i, j
Javascript program:
let MAX_ITER = 1000000 function func ( x ) { return x * x * x - x * x + 2 ; } function regulaFalsi ( a , b ) { if ( func ( a ) * func ( b ) >= 0 ) { document . write ( " " ) ; return ; } let c = a ; for ( let i = 0 ; i < MAX_ITER ; i ++ ) { c = Math . floor ( ( a * func ( b ) - b * func ( a ) ) / ( func ( b ) - func ( a ) ) ) ; if ( func ( c ) == 0 ) { break ; } else if ( func ( c ) * func ( a ) < 0 ) { b = c ; } else { a = c ; } } document . write ( " " + c ) ; } let a = - 200 ; let b = 300 ; regulaFalsi ( a , b ) ;

Accumulator variables: i
Iterator variables: i