dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function isPerfectSquare ( x ) { sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function isProduct ( num ) { var cnt = 0 ; for ( var i = 2 ; cnt < 2 && ( i * i ) <= num ; ++ i ) { while ( num % i == 0 ) { num = parseInt ( num / i ) ; ++ cnt ; } } if ( num > 1 ) ++ cnt ; return cnt == 2 ; } function findNumbers ( N ) { vec = [ ] ; for ( var i = 1 ; i <= N ; i ++ ) { if ( isProduct ( i ) && ! isPerfectSquare ( i ) ) { vec . push ( i ) ; } } for ( var i = 0 ; i < vec . length ; i ++ ) { document . write ( vec [ i ] + " " ) ; } } var N = 30 ; findNumbers ( N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
MAX = 16 var nCr = Array . from ( Array ( MAX ) , ( ) => new Array ( MAX ) ) ; function binomial ( ) { for ( var i = 0 ; i < MAX ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] ; } } } function findTanNTheta ( tanTheta , n ) { ans = 0 , numerator = 0 , denominator = 0 ; toggle = 1 ; for ( var i = 1 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n ] [ i ] * Math . pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } denominator = 1 ; toggle = - 1 ; for ( var i = 2 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n ] [ i ] * Math . pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } ans = numerator / denominator ; return ans . toFixed ( 5 ) ; } binomial ( ) ; var tanTheta = 0.3 ; var n = 10 ; document . write ( findTanNTheta ( tanTheta , n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isDivisible ( n ) { while ( parseInt ( n / 100 ) > 0 ) { var d = n % 10 ; n = parseInt ( n / 10 ) ; n += d * 2 ; } return ( n % 19 == 0 ) ; } var n = 101156 ; if ( isDivisible ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: n
Javascript program:
function printCombination ( n ) { for ( let i = 1 ; i < n ; i ++ ) { if ( i % 3 != 0 ) { for ( let j = 1 ; j < n ; j ++ ) { if ( j % 3 != 0 ) { for ( let k = 1 ; k < n ; k ++ ) { if ( k % 3 != 0 && ( i + j + k ) == n ) { document . write ( i + " " + j + " " + k ) ; return ; } } } } } } } let n = 233 ; printCombination ( n ) ;

Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
var MAXN = 100005 ; var spf = Array . from ( { length : MAXN } , ( _ , i ) => 0 ) ; var sum_digits = Array . from ( { length : MAXN } , ( _ , i ) => 0 ) ; var isValid = Array . from ( { length : MAXN } , ( _ , i ) => false ) ; var ans = Array . from ( { length : MAXN } , ( _ , i ) => 0 ) ; function Smallest_prime_factor ( ) { for ( i = 1 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( i = 3 ; i * i <= MAXN ; i += 2 ) if ( spf [ i ] == i ) for ( j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } function Digit_Sum ( copy ) { var d = 0 ; while ( copy > 0 ) { d += copy % 10 ; copy = parseInt ( copy / 10 ) ; } return d ; } function Sum_Of_All_Digits ( ) { for ( n = 2 ; n < MAXN ; n ++ ) { sum_digits [ n ] = sum_digits [ parseInt ( n / spf [ n ] ) ] + Digit_Sum ( spf [ n ] ) ; if ( Digit_Sum ( n ) == sum_digits [ n ] ) isValid [ n ] = true ; } for ( n = 2 ; n < MAXN ; n ++ ) { if ( isValid [ n ] ) ans [ n ] = 1 ; ans [ n ] += ans [ n - 1 ] ; } } Smallest_prime_factor ( ) ; Sum_Of_All_Digits ( ) ; var l , r ; l = 2 ; r = 3 ; document . write ( " " + l + " " + r + " " + ( ans [ r ] - ans [ l - 1 ] ) ) ; l = 2 ; r = 10 ; document . write ( " " + l + " " + r + " " + ( ans [ r ] - ans [ l - 1 ] ) ) ;

Index/key variables: i, j, n, r
Accumulator variables: d, i, j, n
Iterator variables: i, j, n
Javascript program:
function calculate ( ar , size ) { var count = 0 ; for ( i = 0 ; i < size ; i ++ ) if ( ar [ i ] % 2 == 0 && ar [ i ] != 0 && ar [ i ] != 2 ) count ++ ; return count ; } var a = [ 1 , 3 , 4 , 6 ] ; var size = a . length ; document . write ( calculate ( a , size ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
const N = 1000001 ; let v = new Array ( ) ; for ( let i = 0 ; i < N ; i ++ ) { v . push ( new Array ( ) ) } function preprocess ( ) { for ( let i = 1 ; i < N ; i ++ ) { let num = i ; for ( let j = 2 ; j <= Math . sqrt ( num ) ; j ++ ) { if ( num % j == 0 ) { v [ i ] . push ( j ) ; while ( num % j == 0 ) { num = num / j ; } } } if ( num > 2 ) v [ i ] . push ( num ) ; } } function query ( number , n ) { return v [ number ] [ n - 1 ] ; } preprocess ( ) ; let number = 6 , n = 1 ; document . write ( query ( number , n ) + " " ) ; number = 210 , n = 3 ; document . write ( query ( number , n ) + " " ) ; number = 210 , n = 2 ; document . write ( query ( number , n ) + " " ) ; number = 60 , n = 2 ; document . write ( query ( number , n ) + " " ) ;

Index/key variables: i, number
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function dig ( a ) { var count = 0 ; while ( a > 0 ) { a /= 10 ; count ++ ; } return count ; } function required_number ( num , n , d ) { var i , j , power = 1 , a , flag = 0 ; for ( i = num ; i >= 1 ; i -- ) { power = Math . pow ( 10 , i ) ; a = n % power ; if ( d > a ) { flag = 1 ; break ; } } if ( flag > 0 ) { var t = 0 ; for ( j = 0 ; j < i ; j ++ ) { t += 9 * Math . pow ( 10 , j ) ; } if ( n % power == t ) document . write ( n ) ; else { document . write ( n - ( n % power ) - 1 ) ; } } else document . write ( n ) ; } var n = 1029 , d = 102 ; var num = dig ( n ) ; required_number ( num , n , d ) ;

Accumulator variables: a, count, i, j, t
Iterator variables: i, j
Javascript program:
function ways ( n ) { var first = 2 ; var second = 3 ; var res = 0 ; for ( i = 3 ; i <= n ; i ++ ) { res = first + second ; first = second ; second = res ; } return res ; } var n = 7 ; document . write ( " " + ways ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function countDigits ( n ) { let ans = 0 ; for ( let i = 1 ; i <= n ; i ++ ) ans += Math . log10 ( i ) ; ans = ans * n ; return 1 + Math . floor ( ans ) ; } let n = 4 ; document . write ( countDigits ( n ) + " " ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function printTwinPrime ( n ) { let prime = [ ] ; for ( let i = 0 ; i <= n ; i ++ ) prime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( let i = 2 ; i <= n - 2 ; i ++ ) { if ( prime [ i ] == true && prime [ i + 2 ] == true ) document . write ( " " + i + " " + ( i + 2 ) + " " ) ; } } let n = 25 ; printTwinPrime ( n ) ;

Index/key variables: i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function isCubeFree ( n ) { if ( n == 1 ) return false ; for ( let i = 2 ; i * i * i <= n ; i ++ ) if ( n % ( i * i * i ) == 0 ) return false ; return true ; } function prletCubeFree ( n ) { for ( let i = 2 ; i <= n ; i ++ ) { if ( isCubeFree ( i ) ) { document . write ( i + " " ) ; } } } let N = 20 ; prletCubeFree ( N ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function inversegrayCode ( n ) { let inv = 0 ; for ( ; n ; n = n >> 1 ) inv ^= n ; return inv ; } let n = 15 ; document . write ( inversegrayCode ( n ) ) ;

Accumulator variables: inv
Javascript program:
function productPrimeFactors ( n ) { var product = 1 ; if ( n % 2 == 0 ) { product *= 2 ; while ( n % 2 == 0 ) n = n / 2 ; } for ( i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { product = product * i ; while ( n % i == 0 ) n = n / i ; } } if ( n > 2 ) product = product * n ; return product ; } var n = 44 ; document . write ( productPrimeFactors ( n ) ) ;

Accumulator variables: product
Iterator variables: i
Javascript program:
function mean ( mid , freq , n ) { let sum = 0 , freqSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = sum + mid [ i ] * freq [ i ] ; freqSum = freqSum + freq [ i ] ; } return sum / freqSum ; } function groupedSD ( lower_limit , upper_limit , freq , n ) { let mid = [ ] ; let sum = 0 , freqSum = 0 , sd ; for ( let i = 0 ; i < n ; i ++ ) { mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2 ; sum = sum + freq [ i ] * mid [ i ] * mid [ i ] ; freqSum = freqSum + freq [ i ] ; } sd = Math . sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) ) ; return sd ; } let lower_limit = [ 50 , 61 , 71 , 86 , 96 ] ; let upper_limit = [ 60 , 70 , 85 , 95 , 100 ] ; let freq = [ 9 , 7 , 9 , 12 , 8 ] ; let n = lower_limit . length ; document . write ( groupedSD ( lower_limit , upper_limit , freq , n ) ) ;

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

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function isPrime ( n ) { if ( n % 2 == 0 ) return false ; for ( let i = 3 ; i * i <= n ; i += 2 ) if ( n % i == 0 ) return false ; return true ; } function nextPrime ( start ) { let next = start + 1 ; while ( ! isPrime ( next ) ) next ++ ; return next ; } function areAdjacentPrimes ( a , b , c ) { if ( ! isPrime ( a ) || ! isPrime ( b ) || ! isPrime ( c ) ) return false ; let next = nextPrime ( a ) ; if ( next != b ) return false ; if ( nextPrime ( b ) != c ) return false ; return true ; } if ( areAdjacentPrimes ( 11 , 13 , 19 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: i, next
Iterator variables: i
Javascript program:
function checkSemiprime ( num ) { let cnt = 0 ; for ( let i = 2 ; cnt < 2 && i * i <= num ; ++ i ) while ( num % i == 0 ) { num /= i ; ++ cnt ; } if ( num > 1 ) ++ cnt ; return cnt == 2 ? 1 : 0 ; } function semiprime ( n ) { if ( checkSemiprime ( n ) != 0 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let n = 6 ; semiprime ( n ) ; n = 8 ; semiprime ( n ) ;

Accumulator variables: num
Iterator variables: i
Javascript program:
function sumOfSeries ( n ) { var sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) sum = sum + i * i ; return sum ; } var n = 10 ; document . write ( sumOfSeries ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function binomialCoeff ( n , k ) { let C = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { C [ i ] = new Array ( k + 1 ) ; } for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } function maxcoefficientvalue ( n ) { if ( n % 2 == 0 ) return binomialCoeff ( n , n / 2 ) ; else return binomialCoeff ( n , ( n + 1 ) / 2 ) ; } let n = 4 ; document . write ( maxcoefficientvalue ( n ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) { return a ; } else { return __gcd ( b , a % b ) ; } } function LCM ( x , y , z ) { let ans = ( ( x * y ) / ( __gcd ( x , y ) ) ) ; return ( ( z * ans ) / ( __gcd ( ans , z ) ) ) ; } function findDivisible ( n , x , y , z ) { let lcm = LCM ( x , y , z ) ; let ndigitnumber = Math . pow ( 10 , n - 1 ) ; let reminder = ndigitnumber % lcm ; if ( reminder == 0 ) return ndigitnumber ; ndigitnumber += lcm - reminder ; if ( ndigitnumber < Math . pow ( 10 , n ) ) return ndigitnumber ; else return 0 ; } let n = 4 , x = 2 , y = 3 , z = 5 ; let res = findDivisible ( n , x , y , z ) ; if ( res != 0 ) document . write ( res ) ; else document . write ( " " ) ;

Accumulator variables: ndigitnumber
Javascript program:
function accumulate ( s ) { let acc = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { acc += s [ i ] - ' ' ; } return acc ; } function isDivisible ( s ) { let n = s . length ; if ( s [ n - 1 ] != ' ' && s [ n - 1 ] != ' ' ) return false ; let sum = accumulate ( s ) ; return ( sum % 3 == 0 ) ; } let s = " " ; isDivisible ( s ) ? document . write ( " " ) : document . write ( " " ) ; s = " " ; isDivisible ( s ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i
Accumulator variables: acc, i
Iterator variables: i
Javascript program:
function findCount ( s ) { var freq = Array ( 26 ) . fill ( 0 ) ; var dp = Array . from ( Array ( 26 ) , ( ) => Array ( 26 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < s . length ; ++ i ) { for ( var j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += freq [ j ] ; } freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } var ans = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) ans = Math . max ( freq [ i ] , ans ) ; for ( var i = 0 ; i < 26 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) { ans = Math . max ( dp [ i ] [ j ] , ans ) ; } } return ans ; } var str = " " ; document . write ( findCount ( str ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function constructArray ( N , K , X ) { let ans = new Array ( K ) . fill ( 0 ) ; ans [ 0 ] = X ; for ( let i = 0 ; i < N ; ++ i ) { document . write ( ans [ i % K ] + " " ) ; } document . write ( " " ) ; } let N = 5 , K = 2 , X = 4 ; constructArray ( N , K , X ) ;

Iterator variables: i
Javascript program:
function game ( v , n ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! m . has ( v [ i ] ) ) m . set ( v [ i ] , 1 ) ; else m . set ( v [ i ] , m . get ( v [ i ] ) + 1 ) ; } let count = 0 ; let check = 0 ; for ( let [ key , value ] of m . entries ( ) ) { if ( value > 1 ) { if ( value >= 4 && value % 2 == 0 ) check ++ ; count ++ ; } } let flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) document . write ( " " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 3 , 2 , 2 , 3 , 3 , 5 ] ; let size = arr . length ; game ( arr , size ) ;

Index/key variables: i
Accumulator variables: check, count, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function solve ( A , n ) { let i , cnt = 0 , j ; let parent = new Array ( n ) ; let vis = new Array ( n ) ; parent . fill ( - 1 ) ; vis . fill ( 0 ) ; for ( i = 0 ; i < n ; i ++ ) { j = i ; if ( parent [ j ] == - 1 ) { while ( parent [ j ] == - 1 ) { parent [ j ] = i ; j = __gcd ( j , A [ j ] ) % n ; } if ( parent [ j ] == i ) { while ( vis [ j ] == 0 ) { vis [ j ] = 1 ; cnt ++ ; j = __gcd ( j , A [ j ] ) % n ; } } } } return cnt ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let A = [ 1 , 1 , 6 , 2 ] ; let n = A . length ; document . write ( solve ( A , n ) ) ;

Index/key variables: j
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
let N = 10000 ; let adj = new Array ( N ) ; let lvl = new Array ( N ) ; let dist1 = new Array ( N ) ; let dist2 = new Array ( N ) ; let end = 0 , end2 = 0 , maxi = 0 ; for ( let i = 0 ; i < N ; i ++ ) { lvl [ i ] = 0 ; dist1 [ i ] = - 1 ; dist2 [ i ] = - 1 ; } function AddEdge ( u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } function findFirstEnd ( u , p ) { lvl [ u ] = 1 + lvl [ p ] ; if ( lvl [ u ] > maxi ) { maxi = lvl [ u ] ; end1 = u ; } for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { findFirstEnd ( adj [ u ] [ i ] , u ) ; } } } function clear ( n ) { for ( let i = 0 ; i <= n ; i ++ ) { lvl [ i ] = 0 ; } maxi = 0 ; dist1 [ 0 ] = dist2 [ 0 ] = - 1 ; } function findSecondEnd ( u , p ) { lvl [ u ] = 1 + lvl [ p ] ; if ( lvl [ u ] > maxi ) { maxi = lvl [ u ] ; end2 = u ; } for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { findSecondEnd ( adj [ u ] [ i ] , u ) ; } } } function findDistancefromFirst ( u , p ) { dist1 [ u ] = 1 + dist1 [ p ] ; for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { findDistancefromFirst ( adj [ u ] [ i ] , u ) ; } } } function findDistancefromSecond ( u , p ) { dist2 [ u ] = 1 + dist2 [ p ] ; for ( let i = 0 ; i < adj [ u ] . length ; i ++ ) { if ( adj [ u ] [ i ] != p ) { findDistancefromSecond ( adj [ u ] [ i ] , u ) ; } } } function findNodes ( ) { let n = 5 ; AddEdge ( 1 , 2 ) ; AddEdge ( 1 , 3 ) ; AddEdge ( 3 , 4 ) ; AddEdge ( 3 , 5 ) ; findFirstEnd ( 1 , 0 ) ; clear ( n ) ; findSecondEnd ( end1 , 0 ) ; findDistancefromFirst ( end1 , 0 ) ; findDistancefromSecond ( end2 , 0 ) ; for ( let i = 1 ; i <= n ; i ++ ) { let x = dist1 [ i ] ; let y = dist2 [ i ] ; if ( x >= y ) { document . write ( end1 + " " ) ; } else { document . write ( end2 + " " ) ; } } } for ( let i = 0 ; i < N ; i ++ ) { adj [ i ] = [ ] ; } findNodes ( ) ;

Index/key variables: i, p, u, v
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function digitSum ( num ) { var sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num = parseInt ( num / 10 ) ; } return sum ; } function sumAndProduct ( head_ref ) { var prod = 1 ; var sum = 0 ; var ptr = head_ref ; while ( ptr != null ) { if ( ( digitSum ( ptr . data ) % 2 != 1 ) ) { prod *= ptr . data ; sum += ptr . data ; } ptr = ptr . next ; } document . write ( " " + sum + " " ) ; document . write ( " " + prod ) ; } var head = null ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 8 ) ; head = push ( head , 16 ) ; head = push ( head , 15 ) ; sumAndProduct ( head ) ;

Accumulator variables: prod, sum
Class/struct names: Node
Javascript program:
function ShortestPalindrome ( s ) { let n = s . length ; let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { let l = i ; let r = i ; let ans1 = " " ; let ans2 = " " ; while ( l >= 0 && r < n && s [ l ] == s [ r ] ) { ans1 += s [ l ] ; l -- ; r ++ ; } l = i - 1 ; r = i ; while ( l >= 0 && r < n && s [ l ] == s [ r ] ) { ans2 += s [ l ] ; l -- ; r ++ ; } v . push ( ans1 ) ; v . push ( ans2 ) ; } let ans = v [ 0 ] ; for ( let i = 0 ; i < v . length ; i ++ ) { if ( v [ i ] != " " ) { if ( ans [ 0 ] >= v [ i ] [ 0 ] ) { ans = v [ i ] ; } } } return ans ; } let s = " " ; document . write ( ShortestPalindrome ( s ) ) ;

Index/key variables: i, l, r
Accumulator variables: ans1, ans2, i, l, r
Iterator variables: i
Javascript program:
function getMinimumOps ( ar ) { var n = ar . length ; var small = Math . min . apply ( Math , ar ) ; var large = Math . max . apply ( Math , ar ) ; var dp = new Array ( n ) ; var i , j ; for ( i = 0 ; i < dp . length ; i ++ ) dp [ i ] = new Array ( large + 1 ) ; for ( j = small ; j <= large ; j ++ ) { dp [ 0 ] [ j ] = Math . abs ( ar [ 0 ] - j ) ; } for ( i = 1 ; i < n ; i ++ ) { var minimum = 2147483647 ; for ( j = small ; j <= large ; j ++ ) { minimum = Math . min ( minimum , dp [ i - 1 ] [ j ] ) ; dp [ i ] [ j ] = minimum + Math . abs ( ar [ i ] - j ) ; } } var ans = 2147483647 ; for ( j = small ; j <= large ; j ++ ) { ans = Math . min ( ans , dp [ n - 1 ] [ j ] ) ; } return ans ; } var ar = [ 1 , 2 , 1 , 4 , 3 ] ; document . write ( getMinimumOps ( ar ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function getMinimumOps ( ar , k ) { let n = ar . length ; let dp = new Array ( n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( k + 1 ) ; for ( let j = 0 ; j < ( k + 1 ) ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 1 ] = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let maxGroups = Math . min ( k , i + 1 ) ; for ( let j = 1 ; j <= maxGroups ; j ++ ) { dp [ i ] [ j ] = Number . MAX_VALUE ; if ( j == 1 ) { let freq = new Array ( 100000 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } let freqOfMode = 0 ; for ( let it = 0 ; it <= i ; it ++ ) { freq [ ar [ it ] ] ++ ; let newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; } dp [ i ] [ 1 ] = ( i + 1 ) - freqOfMode ; } else { let freq = new Array ( 100000 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } let freqOfMode = 0 ; for ( let it = i ; it >= j - 1 ; it -- ) { freq [ ar [ it ] ] ++ ; let newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; let elementsToChange = i - it + 1 ; elementsToChange -= freqOfMode ; dp [ i ] [ j ] = Math . min ( dp [ it - 1 ] [ j - 1 ] + elementsToChange , dp [ i ] [ j ] ) ; } } } } return dp [ n - 1 ] [ k ] ; } let k = 3 ; let ar = [ 3 , 1 , 3 , 3 , 2 , 1 , 8 , 5 ] ; document . write ( getMinimumOps ( ar , k ) ) ;

Index/key variables: i, it, j, k
Accumulator variables: elementsToChange, i, it, j
Iterator variables: i, it, j
Javascript program:
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function lcm ( x , y ) { var temp = ( x * y ) / __gcd ( x , y ) ; return temp ; } function findNumbers ( a , n , b , m ) { var lcmA = 1 , gcdB = 0 ; for ( var i = 0 ; i < n ; i ++ ) lcmA = lcm ( lcmA , a [ i ] ) ; for ( var i = 0 ; i < m ; i ++ ) gcdB = __gcd ( gcdB , b [ i ] ) ; if ( gcdB % lcmA != 0 ) { document . write ( " " ) ; return ; } var num = lcmA ; while ( num <= gcdB ) { if ( gcdB % num == 0 ) document . write ( num + " " ) ; num += lcmA ; } } var a = [ 1 , 2 , 2 , 4 ] ; var b = [ 16 , 32 , 64 ] ; var n = a . length ; var m = b . length ; findNumbers ( a , n , b , m ) ;

Index/key variables: i
Accumulator variables: i, num
Iterator variables: i
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 = parseInt ( res / ( i + 1 ) ) ; } return res ; } function power ( x , y ) { let res = 1 ; while ( y > 0 ) { if ( y & 1 ) res = res * x ; y = y >> 1 ; x = x * x ; } return res ; } function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function FindProbability ( n ) { let up = binomialCoeff ( 2 * n , n ) ; let down = power ( 2 , 2 * n ) ; let g = gcd ( up , down ) ; up = parseInt ( up / g ) , down = parseInt ( down / g ) ; document . write ( up + " " + down + " " ) ; } let N = 8 ; FindProbability ( N ) ;

Accumulator variables: res
Iterator variables: i
Javascript program:
var N = 4 , i , j , min ; document . write ( " " + N + " " ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; } for ( i = N - 1 ; i >= 1 ; i -- ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; }

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkPerfectSquare ( n ) { let d = Math . sqrt ( n ) ; if ( d * d == n ) return true ; return false ; } function largestPerfectSquareNumber ( a , n ) { let maxi = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( checkPerfectSquare ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } let a = [ 16 , 20 , 25 , 2 , 3 , 10 ] ; let n = a . length ; document . write ( largestPerfectSquareNumber ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function convert ( n , a ) { let z = a [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] > z ) z = a [ i ] ; } z = z + 1 ; let ff = new Array ( z ) ; ff . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { ff [ a [ i ] ] += 1 ; } let cc = 0 ; for ( let i = 0 ; i < z ; i ++ ) { cc += parseInt ( ff [ i ] / 4 , 10 ) ; ff [ i ] = ff [ i ] % 4 ; } let vv = 0 ; for ( let i = 0 ; i < z ; i ++ ) { if ( ff [ i ] >= 2 ) vv += 1 ; } cc += parseInt ( vv / 2 , 10 ) ; document . write ( cc ) ; } let n = 4 ; let a = [ 1 , 2 , 1 , 2 ] ; convert ( n , a ) ;

Index/key variables: i
Accumulator variables: cc, i, vv
Iterator variables: i