dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var mod = 1000000007 ; var RUNMAX = 300 ; var BALLMAX = 50 ; var WICKETMAX = 10 ; function CountWays ( r , b , l , R , B , W , dp ) { if ( l > W ) return 0 ; if ( r > R ) return 0 ; if ( b == B && r == R ) return 1 ; if ( b == B ) return 0 ; if ( dp [ r ] [ b ] [ l ] != - 1 ) return dp [ r ] [ b ] [ l ] ; var ans = 0 ; ans += CountWays ( r , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 1 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 2 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 3 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 4 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r + 6 , b + 1 , l , R , B , W , dp ) ; ans = ans % mod ; ans += CountWays ( r , b + 1 , l + 1 , R , B , W , dp ) ; ans = ans % mod ; return dp [ r ] [ b ] [ l ] = ans ; } var R = 40 , B = 10 , W = 4 ; var dp = Array ( RUNMAX ) . fill ( ) . map ( ( ) => Array ( BALLMAX ) . fill ( ) . map ( ( ) => Array ( WICKETMAX ) . fill ( 0 ) ) ) ; for ( i = 0 ; i < RUNMAX ; i ++ ) for ( j = 0 ; j < BALLMAX ; j ++ ) for ( k = 0 ; k < WICKETMAX ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; document . write ( CountWays ( 0 , 0 , 0 , R , B , W , dp ) ) ;

Index/key variables: b, i, j, k, l, r
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Javascript program:
var N = 10 ; function findMinimumDeletion ( l , r , dp , s ) { if ( l > r ) return 0 ; if ( l == r ) return 1 ; if ( dp [ l ] [ r ] != - 1 ) return dp [ l ] [ r ] ; var res = 1 + findMinimumDeletion ( l + 1 , r , dp , s ) ; for ( var i = l + 1 ; i <= r ; ++ i ) { if ( s [ l ] == s [ i ] ) res = Math . min ( res , findMinimumDeletion ( l + 1 , i - 1 , dp , s ) + findMinimumDeletion ( i , r , dp , s ) ) ; } return dp [ l ] [ r ] = res ; } var s = " " ; var n = s . length ; var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( - 1 ) ) ; document . write ( findMinimumDeletion ( 0 , n - 1 , dp , s ) ) ;

Index/key variables: i, l, r
Iterator variables: i
Javascript program:
var C = Array ( 1000 ) . fill ( ) . map ( ( ) => Array ( 1000 ) . fill ( 0 ) ) ; function binomialCoeff ( n ) { var i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } } function numberOfWays ( x , y , z ) { binomialCoeff ( Math . max ( x , Math . max ( y , z ) ) ) ; var sum = 0 ; for ( i = 1 ; i <= z ; i ++ ) { sum = ( sum + C [ z ] [ i ] ) ; } var sum1 = 0 ; for ( i = 1 ; i <= y ; i ++ ) { for ( j = i + 1 ; j <= x ; j ++ ) { sum1 = ( sum1 + ( C [ y ] [ i ] * C [ x ] [ j ] ) ) ; } } sum1 = ( sum * sum1 ) ; return sum1 ; } var x = 3 ; var y = 2 ; var z = 1 ; document . write ( numberOfWays ( x , y , z ) ) ;

Index/key variables: i, j, x, y, z
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findCost ( str , arr , n ) { var costofC = 0 , costofO = 0 , costofD = 0 , costofE = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) costofC += arr [ i ] ; else if ( str [ i ] == ' ' ) costofO = Math . min ( costofC , costofO + arr [ i ] ) ; else if ( str [ i ] == ' ' ) costofD = Math . min ( costofO , costofD + arr [ i ] ) ; else if ( str [ i ] == ' ' ) costofE = Math . min ( costofD , costofE + arr [ i ] ) ; } return costofE ; } var str = " " ; var arr = [ 1 , 2 , 1 , 3 , 4 , 2 , 6 , 4 , 6 , 2 , 3 , 3 , 3 , 2 ] ; var n = arr . length ; document . write ( findCost ( str , arr , n ) ) ;

Index/key variables: i
Accumulator variables: costofC, i
Iterator variables: i
Javascript program:
function findSubsequence ( arr , n ) { let len = 1 ; let tmp ; let i , j , d ; let dp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = new Array ( 10 ) ; for ( let j = 0 ; j < 10 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } let cnt = new Array ( 10 ) ; let locMax ; tmp = arr [ 0 ] ; while ( tmp > 0 ) { dp [ 0 ] [ tmp % 10 ] = 1 ; tmp = Math . floor ( tmp / 10 ) ; } for ( i = 1 ; i < n ; i ++ ) { tmp = arr [ i ] ; locMax = 1 ; for ( let x = 0 ; x < 10 ; x ++ ) cnt [ x ] = 0 ; while ( tmp > 0 ) { cnt [ tmp % 10 ] = 1 ; tmp = Math . floor ( tmp / 10 ) ; } for ( d = 0 ; d <= 9 ; d ++ ) { if ( cnt [ d ] > 0 ) { dp [ i ] [ d ] = 1 ; for ( j = 0 ; j < i ; j ++ ) { dp [ i ] [ d ] = Math . max ( dp [ i ] [ d ] , dp [ j ] [ d ] + 1 ) ; locMax = Math . max ( dp [ i ] [ d ] , locMax ) ; } } } for ( d = 0 ; d <= 9 ; d ++ ) { if ( cnt [ d ] > 0 ) { dp [ i ] [ d ] = locMax ; } } len = Math . max ( len , locMax ) ; } return len ; } let arr = [ 1 , 12 , 44 , 29 , 33 , 96 , 89 ] ; let n = arr . length ; document . write ( findSubsequence ( arr , n ) ) ;

Index/key variables: d, i, j, x
Accumulator variables: d, i, j, x
Iterator variables: d, i, j, x
Javascript program:
var M = 18 ; var a , b ; var dp = Array . from ( Array ( M ) , ( ) => Array ( 90 ) ) ; var prime = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ] ; function count ( pos , even , odd , tight , num ) { if ( pos == num . length ) { if ( num . length & 1 ) [ odd , even ] = [ even , odd ] var d = even - odd ; for ( var i = 0 ; i < 24 ; i ++ ) if ( d == prime [ i ] ) return 1 ; return 0 ; } if ( dp [ pos ] [ even ] [ odd ] [ tight ] != - 1 ) return dp [ pos ] [ even ] [ odd ] [ tight ] ; var ans = 0 ; var limit = ( tight ? 9 : num [ pos ] ) ; for ( var d = 0 ; d <= limit ; d ++ ) { var currF = tight , currEven = even ; var currOdd = odd ; if ( d < num [ pos ] ) currF = 1 ; if ( pos & 1 ) currOdd += d ; else currEven += d ; ans += count ( pos + 1 , currEven , currOdd , currF , num ) ; } return dp [ pos ] [ even ] [ odd ] [ tight ] = ans ; } function solve ( x ) { var num = [ ] ; while ( x ) { num . push ( x % 10 ) ; x = parseInt ( x / 10 ) ; } num . reverse ( ) ; for ( var i = 0 ; i < M ; i ++ ) for ( var j = 0 ; j < 90 ; j ++ ) dp [ i ] [ j ] = Array . from ( Array ( 90 ) , ( ) => Array ( 2 ) . fill ( - 1 ) ) return count ( 0 , 0 , 0 , 0 , num ) ; } var L = 1 , R = 50 ; document . write ( solve ( R ) - solve ( L - 1 ) + " " ) ; L = 50 , R = 100 ; document . write ( solve ( R ) - solve ( L - 1 ) ) ;

Index/key variables: even, i, j, odd, pos, tight
Accumulator variables: ans, currEven, currOdd, d, i, j
Iterator variables: d, i, j
Javascript program:
let N = 5005 ; let n , k ; let gr = new Array ( N ) ; let d = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { d [ i ] = new Array ( 505 ) ; for ( let j = 0 ; j < 505 ; j ++ ) { d [ i ] [ j ] = 0 ; } } let ans = 0 ; function Add_edge ( x , y ) { gr [ x ] . push ( y ) ; gr [ y ] . push ( x ) ; } function dfs ( v , par ) { d [ v ] [ 0 ] = 1 ; for ( let i = 0 ; i < gr [ v ] . length ; i ++ ) { if ( gr [ v ] [ i ] != par ) { dfs ( gr [ v ] [ i ] , v ) ; for ( let j = 1 ; j <= k ; j ++ ) ans += d [ gr [ v ] [ i ] ] [ j - 1 ] * d [ v ] [ k - j ] ; for ( let j = 1 ; j <= k ; j ++ ) d [ v ] [ j ] += d [ gr [ v ] [ i ] ] [ j - 1 ] ; } } } n = 5 ; k = 2 ; for ( let i = 0 ; i < N ; i ++ ) gr [ i ] = [ ] ; Add_edge ( 1 , 2 ) ; Add_edge ( 2 , 3 ) ; Add_edge ( 3 , 4 ) ; Add_edge ( 2 , 5 ) ; dfs ( 1 , 0 ) ; document . write ( ans ) ;

Index/key variables: i, j, v, x, y
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function findXorSum ( arr , n ) { let sum = 0 ; let mul = 1 ; for ( let i = 0 ; i < 30 ; i ++ ) { let c_odd = 0 ; let odd = 0 ; for ( let j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) odd = ( ! odd ) ; if ( odd ) c_odd ++ ; } for ( let j = 0 ; j < n ; j ++ ) { sum += ( mul * c_odd ) ; if ( ( arr [ j ] & ( 1 << i ) ) > 0 ) c_odd = ( n - j - c_odd ) ; } mul *= 2 ; } return sum ; } let arr = [ 3 , 8 , 13 ] ; let n = arr . length ; document . write ( findXorSum ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: c_odd, i, j, mul, sum
Iterator variables: i, j
Javascript program:
function charVal ( s , i ) { if ( s . charAt ( i ) == ' ' ) { return 0 ; } else if ( s . charAt ( i ) == ' ' ) { return 1 ; } else { return 2 ; } } function countMinimalReplacements ( s , i , prev , dp , n ) { if ( i == n ) { return 0 ; } if ( dp [ i ] [ prev ] != - 1 ) { return dp [ i ] [ prev ] ; } var val = charVal ( s , i ) ; var ans = Number . MAX_VALUE ; if ( val == prev ) { val = 0 ; for ( var cur = 0 ; cur <= 2 ; cur ++ ) { if ( cur == prev ) { continue ; } val = 1 + countMinimalReplacements ( s , i + 1 , cur , dp , n ) ; ans = Math . min ( ans , val ) ; } { ans = countMinimalReplacements ( s , i + 1 , val , dp , n ) ; } return dp [ i ] [ val ] = ans ; } var s = " " ; var n = s . length ; var dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( 3 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } var val = charVal ( s , 0 ) ; document . write ( countMinimalReplacements ( s , 1 , val , dp , n ) ) ;

Index/key variables: i, j, prev, val
Accumulator variables: cur, i, j
Iterator variables: cur, i, j
Javascript program:
var MAX = 50 ; function hasPath ( maze , sol , N ) { for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < N ; j ++ ) sol [ i ] [ j ] = 0 ; var CRF = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; ; for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < N ; j ++ ) CRF [ i ] [ j ] = false ; CRF [ N - 1 ] [ N - 1 ] = true ; for ( var k = N - 1 ; k >= 0 ; k -- ) { for ( var j = k ; j >= 0 ; j -- ) { if ( ! ( k == N - 1 && j == N - 1 ) ) { for ( var a = 0 ; a <= maze [ k ] [ j ] ; a ++ ) { if ( ( j + a < N && CRF [ k ] [ j + a ] == true ) || ( k + a < N && CRF [ k + a ] [ j ] == true ) ) { CRF [ k ] [ j ] = true ; break ; } } for ( var a = 0 ; a <= maze [ j ] [ k ] ; a ++ ) { if ( ( k + a < N && CRF [ j ] [ k + a ] == true ) || ( j + a < N && CRF [ j + a ] [ k ] == true ) ) { CRF [ j ] [ k ] = true ; break ; } } } } } if ( CRF [ 0 ] [ 0 ] == false ) return false ; var i = 0 , j = 0 ; while ( ! ( i == N - 1 && j == N - 1 ) ) { sol [ i ] [ j ] = 1 ; if ( maze [ i ] [ j ] > 0 ) for ( var a = 1 ; a <= maze [ i ] [ j ] ; a ++ ) { if ( ( j + a < N && CRF [ i ] [ j + a ] == true ) ) { j = j + a ; break ; } else if ( ( i + a < N && CRF [ i + a ] [ j ] == true ) ) { i = i + a ; break ; } } } sol [ N - 1 ] [ N - 1 ] = 1 ; return true ; } function printMatrix ( sol , N ) { for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) document . write ( sol [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var maze = [ [ 2 , 2 , 1 , 1 , 0 ] , [ 0 , 0 , 3 , 0 , 0 ] , [ 1 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 2 , 0 , 1 ] , [ 0 , 0 , 3 , 0 , 0 ] ] ; var N = maze . length ; var sol = Array . from ( Array ( N ) , ( ) => Array ( MAX ) ) ; if ( hasPath ( maze , sol , N ) ) printMatrix ( sol , N ) ; else document . write ( " " ) ;

Index/key variables: i, j, k
Accumulator variables: a, i, j, k
Iterator variables: a, i, j, k
Javascript program:
function checkCombinations ( a , n ) { var pow_set_size = parseInt ( Math . pow ( 2 , n ) ) ; var counter , j ; for ( counter = 0 ; counter < pow_set_size ; counter ++ ) { var sum = 0 ; for ( j = 0 ; j < n ; j ++ ) { if ( ( counter & ( 1 << j ) ) != 0 ) else } if ( sum % ( 24 * 60 ) == 0 ) return true ; } return false ; } var a = [ 60 , 60 , 120 ] ; var n = a . length ; if ( checkCombinations ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: counter, j
Iterator variables: counter, j
Javascript program:
let n = 4 ; let m = 4 ; function calcProbability ( M , k ) { let dp = new Array ( m ) ; let sum = new Array ( n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) { sum [ i ] = 0 ; } for ( let j = 0 ; j < n ; j ++ ) { dp [ 0 ] [ j ] = M [ 0 ] [ j ] ; sum [ 0 ] = sum [ 0 ] + dp [ 0 ] [ j ] ; } for ( let i = 1 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] / sum [ i - 1 ] + M [ i ] [ j ] ; sum [ i ] += dp [ i ] [ j ] ; } } return dp [ n - 1 ] [ k - 1 ] / sum [ n - 1 ] ; } let M = [ [ 1 , 1 , 0 , 3 ] , [ 2 , 3 , 2 , 3 ] , [ 9 , 3 , 0 , 2 ] , [ 2 , 3 , 2 , 2 ] ] ; let k = 3 ; document . write ( calcProbability ( M , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function MaximumNumbers ( s ) { let n = s . length ; let remIndex = [ - 1 , - 1 , - 1 ] ; remIndex [ 0 ] = 0 ; let res = new Array ( n + 1 ) ; for ( let i = 0 ; i < res . length ; i ++ ) { res [ i ] = 0 ; } let r = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { r = ( r + s [ i - 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) % 3 ; res [ i ] = res [ i - 1 ] ; if ( remIndex [ r ] != - 1 ) res [ i ] = Math . max ( res [ i ] , res [ remIndex [ r ] ] + 1 ) ; remIndex [ r ] = i + 1 ; } return res [ n ] ; } let s = " " ; document . write ( MaximumNumbers ( s ) ) ;

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Javascript program:
var INF = 99999 ; function findMinimumSteps ( mat , x , y , n ) { var i , j , k ; var dist = Array ( n ) . fill ( ) . map ( ( ) => Array ( n ) . fill ( 0 ) ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 0 ) dist [ i ] [ j ] = INF ; else dist [ i ] [ j ] = 1 ; if ( i == j ) dist [ i ] [ j ] = 1 ; } } for ( k = 0 ; k < n ; k ++ ) { for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } if ( dist [ x ] [ y ] < INF ) return dist [ x ] [ y ] ; else return - 1 ; } var mat = [ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ] ; var x = 2 , y = 3 ; var size = mat . length ; document . write ( findMinimumSteps ( mat , x , y , size ) ) ;

Index/key variables: i, j, k, x, y
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let max = 4 ; let c = 2 ; function countPaths ( sum , get , m , n , dp ) { if ( sum < 0 ) return 0 ; if ( sum == 0 ) return get ; if ( dp [ sum ] [ get ] != - 1 ) return dp [ sum ] [ get ] ; let res = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i == m ) res += countPaths ( sum - i , 1 , m , n , dp ) ; else res += countPaths ( sum - i , get , m , n , dp ) ; } dp [ sum ] [ get ] = res ; return dp [ sum ] [ get ] ; } let n = 3 , m = 2 , x = 3 ; let dp = new Array ( max + 1 ) ; for ( let i = 0 ; i <= max ; i ++ ) { dp [ i ] = new Array ( 2 ) for ( let j = 0 ; j < 2 ; j ++ ) dp [ i ] [ j ] = - 1 ; } document . write ( countPaths ( x , 0 , m , n , dp ) ) ;

Index/key variables: get, i, j, sum
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function addEdge ( adj , u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function printGraph ( adj , V ) { for ( var v = 0 ; v < V ; ++ v ) { document . write ( " " + v + " " ) ; for ( var x of adj [ v ] ) document . write ( " " + x ) ; document . write ( " " ) ; } } function findMinOperationUtil ( dp , adj , A , src , parent ) { dp [ src ] [ 0 ] = dp [ src ] [ 1 ] = 0 ; for ( var V of adj [ src ] ) { if ( V == parent ) continue ; findMinOperationUtil ( dp , adj , A , V , src ) ; dp [ src ] [ 0 ] = Math . max ( dp [ src ] [ 0 ] , dp [ V ] [ 0 ] ) ; dp [ src ] [ 1 ] = Math . max ( dp [ src ] [ 1 ] , dp [ V ] [ 1 ] ) ; } A [ src - 1 ] += dp [ src ] [ 0 ] - dp [ src ] [ 1 ] ; if ( A [ src - 1 ] > 0 ) { dp [ src ] [ 1 ] += A [ src - 1 ] ; } else { dp [ src ] [ 0 ] += Math . abs ( A [ src - 1 ] ) ; } } function findMinOperation ( adj , A , V ) { var dp = Array . from ( Array ( V + 1 ) , ( ) => Array ( 2 ) . fill ( 0 ) ) ; findMinOperationUtil ( dp , adj , A , 1 , 0 ) ; var minOperations = dp [ 1 ] [ 0 ] + dp [ 1 ] [ 1 ] ; return minOperations ; } var V = 5 ; var adj = Array . from ( Array ( V + 1 ) , ( ) => Array ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; var A = [ 1 , - 1 , 1 ] ; var minOperations = findMinOperation ( adj , A , V ) ; document . write ( minOperations ) ;

Index/key variables: V, src, u, v
Iterator variables: V, v, x
Javascript program:
var MAX_K = 15 ; var fac = Array ( MAX_K ) . fill ( 0 ) ; function factorial ( k ) { fac [ 0 ] = 1 ; for ( i = 1 ; i <= k + 1 ; i ++ ) { fac [ i ] = ( i * fac [ i - 1 ] ) ; } } function bin ( a , b ) { var ans = ( ( fac [ a ] ) / ( fac [ a - b ] * fac [ b ] ) ) ; return ans ; } function sumofn ( n , k ) { var p = 0 ; var num1 , temp ; var arr = Array ( 1000 ) . fill ( 0 ) ; for ( j = 1 ; j <= k ; j ++ ) { if ( j == 1 ) { num1 = ( n * ( n + 1 ) ) / 2 ; arr [ p ++ ] = num1 ; temp = num1 ; } else { temp = ( parseInt ( Math . pow ( n + 1 , j + 1 ) - 1 - n ) ) ; for ( s = 1 ; s < j ; s ++ ) { temp = temp - ( arr [ j - s - 1 ] * bin ( j + 1 , s + 1 ) ) ; } temp = temp / ( j + 1 ) ; arr [ p ++ ] = temp ; } } temp = arr [ p - 1 ] ; return temp ; } var n = 5 , k = 2 ; factorial ( k ) ; document . write ( sumofn ( n , k ) ) ;

Index/key variables: a, b, i
Accumulator variables: i, j, p, s
Iterator variables: i, j, s
Javascript program:
let max = 4 ; function countWays ( index , cnt , dp , n , m , k ) { if ( index == n ) { if ( cnt == k ) return 1 ; else return 0 ; } if ( dp [ index ] [ cnt ] != - 1 ) return dp [ index ] [ cnt ] ; let ans = 0 ; ans += countWays ( index + 1 , cnt , dp , n , m , k ) ; ans += ( m - 1 ) * countWays ( index + 1 , cnt + 1 , dp , n , m , k ) ; return dp [ index ] [ cnt ] = ans ; } let n = 3 , m = 3 , k = 2 ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = new Array ( max ) ; for ( let j = 0 ; j < max ; j ++ ) dp [ i ] [ j ] = - 1 ; } document . write ( m * countWays ( 1 , 0 , dp , n , m , k ) ) ;

Index/key variables: cnt, i, index, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let MAX = 300 ; function checkFunc ( i , j , st ) { if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; if ( st [ i ] == ' ' && st [ j ] == ' ' ) return 1 ; return 0 ; } function countRec ( start , end , dp , st ) { let sum = 0 ; if ( start > end ) return 1 ; if ( dp [ start ] [ end ] != - 1 ) return dp [ start ] [ end ] ; let i , r = 0 ; for ( i = start + 1 ; i <= end ; i += 2 ) { if ( checkFunc ( start , i , st ) == 1 ) { sum = sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) ; } else if ( st [ start ] == ' ' && st [ i ] == ' ' ) { sum = sum + countRec ( start + 1 , i - 1 , dp , st ) * countRec ( i + 1 , end , dp , st ) * 3 ; } } return dp [ start ] [ end ] = sum ; } function countWays ( st ) { let n = st . length ; if ( n % 2 == 1 ) return 0 ; let dp = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) dp [ i ] [ j ] = - 1 ; } return countRec ( 0 , n - 1 , dp , st ) ; } let st = " " ; document . write ( countWays ( st ) ) ;

Index/key variables: end, i, j, start
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function calculateEvenSum ( n ) { if ( n <= 0 ) return 0 ; let fibo = Array ( 2 * n + 1 ) ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; let sum = 0 ; for ( i = 2 ; i <= 2 * n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; if ( i % 2 == 0 ) sum += fibo [ i ] ; } return sum ; } let n = 8 ; document . write ( " " + n + " " + + calculateEvenSum ( n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
var MAX = 1000 ; var f = Array ( MAX ) . fill ( 0 ) ; function fib ( n ) { if ( n == 0 ) { return 0 ; } if ( n == 1 n == 2 ) { return ( f [ n ] = 1 ) ; } if ( f [ n ] == 1 ) { return f [ n ] ; } var k = ( n % 2 == 1 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( n % 2 == 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } function calculateEvenSum ( n ) { return ( fib ( 2 * n + 1 ) - 1 ) ; } var n = 8 ; document . write ( " " + n + " " + calculateEvenSum ( n ) ) ;

Index/key variables: n
Javascript program:
var MAX = 32768 ; var arr = Array ( 2 * MAX ) ; function gouldSequence ( ) { arr [ 0 ] = 1 ; var i = 1 ; var p = 1 ; while ( i <= MAX ) { var j = 0 ; while ( j < i ) { arr [ i + j ] = 2 * arr [ j ] ; j ++ ; } i = ( 1 << p ) ; p ++ ; } } function printSequence ( n ) { for ( var i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } gouldSequence ( ) ; var n = 16 ; printSequence ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j, p
Iterator variables: i
Javascript program:
function factorial ( n ) { var res = 1 , i ; for ( i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } function countWays ( m , n ) { m = m - 1 ; n = n - 1 ; return factorial ( m + n ) / ( factorial ( m ) * factorial ( n ) ) ; } var m = 5 ; var n = 5 ; var result = countWays ( m , n ) ; document . write ( result ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
function MatrixChainOrder ( p , n ) { var dp = Array . from ( Array ( n ) , ( ) => Array ( n ) ) ; for ( var i = 1 ; i < n ; i ++ ) dp [ i ] [ i ] = 0 ; for ( var L = 1 ; L < n - 1 ; L ++ ) for ( var i = 1 ; i < n - L ; i ++ ) dp [ i ] [ i + L ] = Math . min ( dp [ i + 1 ] [ i + L ] + p [ i - 1 ] * p [ i ] * p [ i + L ] , dp [ i ] [ i + L - 1 ] + p [ i - 1 ] * p [ i + L - 1 ] * p [ i + L ] ) ; return dp [ 1 ] [ n - 1 ] ; } var arr = [ 10 , 20 , 30 , 40 , 30 ] ; var size = arr . length ; document . write ( " " + MatrixChainOrder ( arr , size ) ) ;

Index/key variables: i
Accumulator variables: L, i
Iterator variables: L, i
Javascript program:
function CommomSubsequencesCount ( s , t ) { var n1 = s . length ; var n2 = t . length ; var dp = Array . from ( Array ( n1 + 1 ) , ( ) => Array ( n2 + 1 ) ) ; for ( var i = 0 ; i <= n1 ; i ++ ) { for ( var j = 0 ; j <= n2 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( var i = 1 ; i <= n1 ; i ++ ) { for ( var j = 1 ; j <= n2 ; j ++ ) { if ( s [ i - 1 ] == t [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j ] ; else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j ] - dp [ i - 1 ] [ j - 1 ] ; } } return dp [ n1 ] [ n2 ] ; } var s = " " ; var t = " " ; document . write ( CommomSubsequencesCount ( s , t ) ) ;

Index/key variables: i, j, n1, n2
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function createPalindrome ( input , isOdd ) { var n = input ; var palin = input ; if ( isOdd % 2 == 1 ) { n = parseInt ( n / 10 ) ; } while ( n > 0 ) { palin = palin * 10 + ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return palin ; } function generatePalindromes ( N ) { var palindromes = [ ] ; var number ; for ( var j = 0 ; j < 2 ; j ++ ) { var i = 1 ; while ( ( number = createPalindrome ( i ++ , j ) ) <= N ) { palindromes . push ( number ) ; } } return palindromes ; } function reverse ( input ) { var temparray = input . split ( ' ' ) ; var left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { var temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return temparray . join ( ' ' ) ; } function minimumNoOfPalindromes ( N ) { var a = N . toString ( ) ; var b = N . toString ( ) ; b = reverse ( b ) ; if ( a == b ) { return 1 ; } var palindromes = generatePalindromes ( N ) ; palindromes . sort ( ) ; var l = 0 , r = palindromes . length - 1 ; while ( l < r ) { if ( palindromes [ l ] + palindromes [ r ] == N ) { return 2 ; } else if ( palindromes [ l ] + palindromes [ r ] < N ) { ++ l ; } else { -- r ; } } return 3 ; } var N = 65 ; document . write ( minimumNoOfPalindromes ( N ) ) ;

Index/key variables: l, left, r, right
Accumulator variables: i, j, left, right
Iterator variables: j, left