dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function preprocess ( p , x , y , n ) { for ( let i = 0 ; i < n ; i ++ ) p [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ; p . sort ( function ( a , b ) { return a - b ; } ) ; } function query ( p , n , rad ) { let start = 0 , end = n - 1 ; while ( ( end - start ) > 1 ) { let mid = Math . floor ( ( start + end ) / 2 ) ; let tp = Math . sqrt ( p [ mid ] ) ; if ( tp > ( rad * 1.0 ) ) end = mid - 1 ; else start = mid ; } let tp1 = Math . sqrt ( p [ start ] ) ; let tp2 = Math . sqrt ( p [ end ] ) ; if ( tp1 > ( rad * 1.0 ) ) return 0 ; else if ( tp2 <= ( rad * 1.0 ) ) return end + 1 ; else return start + 1 ; } let x = [ 1 , 2 , 3 , - 1 , 4 ] ; let y = [ 1 , 2 , 3 , - 1 , 4 ] ; let n = x . length ; let p = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { p [ i ] = 0 ; } preprocess ( p , x , y , n ) ; document . write ( query ( p , n , 3 ) + " " ) ; document . write ( query ( p , n , 32 ) + " " ) ;

Index/key variables: end, i, mid, start
Accumulator variables: i
Iterator variables: i
Javascript program:
function isSpiralSorted ( arr , n ) { let start = 0 ; let end = n - 1 ; while ( start < end ) { if ( arr [ start ] > arr [ end ] ) { return false ; } start ++ ; if ( arr [ end ] > arr [ start ] ) { return false ; } end -- ; } return true ; } let arr = [ 1 , 10 , 14 , 20 , 18 , 12 , 5 ] ; let N = arr . length ; if ( isSpiralSorted ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: end, start
Accumulator variables: end, start
Javascript program:
function findWordsSameRow ( arr ) { var mp = { } ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 1 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 2 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; mp [ " " ] = 3 ; for ( const word of arr ) { if ( word . length !== 0 ) { var flag = true ; var rowNum = mp [ word [ 0 ] . toLowerCase ( ) ] ; var M = word . length ; for ( var i = 1 ; i < M ; i ++ ) { if ( mp [ word [ i ] . toLowerCase ( ) ] !== rowNum ) { flag = false ; break ; } } if ( flag ) { document . write ( word + " " ) ; } } } } var words = [ " " , " " , " " , " " ] ; findWordsSameRow ( words ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, word
Boolean variables: flag
Javascript program:
function countSubsequece ( a , n ) { let i , j , k , l ; let answer = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { for ( k = j + 1 ; k < n ; k ++ ) { for ( l = k + 1 ; l < n ; l ++ ) { if ( a [ j ] == a [ l ] && a [ i ] == a [ k ] ) { answer ++ ; } } } } } return answer ; } let a = [ 1 , 2 , 3 , 2 , 1 , 3 , 2 ] ; document . write ( countSubsequece ( a , 7 ) ) ;

Index/key variables: i, j, k, l
Accumulator variables: answer, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function minDistChar ( s ) { let n = s . length ; let first = new Array ( 26 ) ; let last = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { first [ i ] = - 1 ; last [ i ] = - 1 ; } for ( let i = 0 ; i < n ; i ++ ) { if ( first [ s [ i ] - ' ' ] == - 1 ) { first [ s [ i ] - ' ' ] = i ; } last [ s [ i ] - ' ' ] = i ; } let min = 100000 ; var ans = ' ' ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( last [ i ] == first [ i ] ) continue ; if ( min > last [ i ] - first [ i ] ) { min = last [ i ] - first [ i ] ; ans = String . fromCharCode ( i + 97 ) ; } } return ans ; } str = " " ; document . write ( minDistChar ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var n = 3 ; function minSteps ( arr ) { var v = Array . from ( Array ( n ) , ( ) => Array ( n ) . fill ( 0 ) ) ; var q = [ ] ; q . push ( [ 0 , 0 ] ) ; var depth = 0 ; while ( q . length != 0 ) { var x = q . length ; while ( x -- ) { var y = q [ 0 ] ; var i = y [ 0 ] , j = y [ 1 ] ; q . shift ( ) ; if ( v [ i ] [ j ] ) continue ; if ( i == n - 1 && j == n - 1 ) return depth ; v [ i ] [ j ] = 1 ; if ( i + arr [ i ] [ j ] < n ) q . push ( [ i + arr [ i ] [ j ] , j ] ) ; if ( j + arr [ i ] [ j ] < n ) q . push ( [ i , j + arr [ i ] [ j ] ] ) ; } depth ++ ; } return - 1 ; } var arr = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ; document . write ( minSteps ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: depth, x
Javascript program:
function solve ( a , n ) { let max1 = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( Math . abs ( a [ i ] - a [ j ] ) > max1 ) { max1 = Math . abs ( a [ i ] - a [ j ] ) ; } } } return max1 ; } let arr = [ - 1 , 2 , 3 , - 4 , - 10 , 22 ] ; let size = arr . length ; document . write ( " " + solve ( arr , size ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function solve ( a , n ) { let min1 = a [ 0 ] ; let max1 = a [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > max1 ) max1 = a [ i ] ; if ( a [ i ] < min1 ) min1 = a [ i ] ; } return Math . abs ( min1 - max1 ) ; } let arr = [ - 1 , 2 , 3 , 4 , - 10 ] ; let size = arr . length ; document . write ( " " + solve ( arr , size ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function replaceOriginal ( s , n ) { var r = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { r [ i ] = s . charAt ( n - 1 - i ) ; if ( s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' && s . charAt ( i ) != ' ' ) { document . write ( r [ i ] ) ; } } document . write ( " " ) ; } var s = " " ; var n = s . length ; replaceOriginal ( s , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sameStrings ( str1 , str2 ) { var N = str1 . length ; var M = str2 . length ; if ( N !== M ) { return false ; } var a = new Array ( 256 ) . fill ( 0 ) ; var b = new Array ( 256 ) . fill ( 0 ) ; for ( var j = 0 ; j < N ; j ++ ) { a [ str1 [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; b [ str2 [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var i = 0 ; while ( i < 256 ) { if ( ( a [ i ] === 0 && b [ i ] === 0 ) || ( a [ i ] !== 0 && b [ i ] !== 0 ) ) { i ++ ; } else { return false ; } } a . sort ( ( x , y ) => x - y ) ; b . sort ( ( x , y ) => x - y ) ; for ( var j = 0 ; j < 256 ; j ++ ) { if ( a [ j ] !== b [ j ] ) return false ; } return true ; } var S1 = " " , S2 = " " ; if ( sameStrings ( S1 , S2 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function search ( arr , l , h , key ) { if ( l > h ) return - 1 ; let mid = parseInt ( ( l + h ) / 2 , 10 ) ; if ( arr [ mid ] == key ) return mid ; if ( ( arr [ l ] == arr [ mid ] ) && ( arr [ h ] == arr [ mid ] ) ) { ++ l ; -- h ; return search ( arr , l , h , key ) } if ( arr [ l ] <= arr [ mid ] ) { if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ; return search ( arr , mid + 1 , h , key ) ; } if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ; return search ( arr , l , mid - 1 , key ) ; } let arr = [ 3 , 3 , 1 , 2 , 3 , 3 ] ; let n = arr . length ; let key = 3 ; document . write ( search ( arr , 0 , n - 1 , key ) ) ;

Index/key variables: h, l, mid
Javascript program:
function getSortedString ( s , n ) { var v1 = [ ] ; var v2 = [ ] ; var i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) v1 . push ( s [ i ] ) ; if ( s [ i ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) v2 . push ( s [ i ] ) ; } console . log ( v1 ) ; v1 . sort ( ) ; v2 . sort ( ) ; var j = 0 ; i = 0 ; for ( var k = 0 ; k < n ; k ++ ) { if ( s [ k ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) { s [ k ] = v1 [ i ] ; ++ i ; } else if ( s [ k ] . charCodeAt ( 0 ) > " " . charCodeAt ( 0 ) && s [ k ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) { s [ k ] = v2 [ j ] ; ++ j ; } } return s . join ( " " ) ; } var s = " " ; var n = s . length ; document . write ( getSortedString ( s . split ( " " ) , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function check ( s ) { let l = s . length ; s . sort ( ) ; for ( let i = 1 ; i < l ; i ++ ) { if ( ( s [ i ] . charCodeAt ( ) - s [ i - 1 ] . charCodeAt ( ) ) != 1 ) return false ; } return true ; } let str = " " ; if ( check ( str . split ( ' ' ) ) == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; let str1 = " " ; if ( check ( str1 . split ( ' ' ) ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minElements ( arr , n ) { let halfSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) halfSum = halfSum + arr [ i ] ; halfSum = parseInt ( halfSum / 2 , 10 ) ; arr . sort ( function ( a , b ) { return a - b } ) ; arr . reverse ( ) ; let res = 0 , curr_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { curr_sum += arr [ i ] ; res ++ ; if ( curr_sum > halfSum ) return res ; } return res ; } let arr = [ 3 , 1 , 7 , 1 ] ; let n = arr . length ; document . write ( minElements ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: curr_sum, i, res
Iterator variables: i
Javascript program:
function arrayElementEqual ( arr , N ) { var sum = 0 ; for ( i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum % N == 0 ) { document . write ( " " ) ; } else { document . write ( " " + " " ) ; } } var arr = [ 1 , 5 , 6 , 4 ] ; var N = arr . length ; arrayElementEqual ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function pairProductMean ( arr , N ) { var suffixSumArray = Array ( N ) ; suffixSumArray [ N - 1 ] = arr [ N - 1 ] ; for ( var i = N - 2 ; i >= 0 ; i -- ) { suffixSumArray [ i ] = suffixSumArray [ i + 1 ] + arr [ i ] ; } var length = ( N * ( N - 1 ) ) / 2 ; var res = 0 ; for ( var i = 0 ; i < N - 1 ; i ++ ) { res += arr [ i ] * suffixSumArray [ i + 1 ] ; } var mean ; if ( length != 0 ) mean = res / length ; else mean = 0 ; return mean ; } var arr = [ 1 , 2 , 4 , 8 ] ; var N = arr . length ; document . write ( pairProductMean ( arr , N ) . toFixed ( 2 ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function ncr ( n , k ) { var res = 1 ; if ( k > n - k ) k = n - k ; for ( var i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countPath ( N , M , K ) { var answer ; if ( K >= 2 ) answer = 0 ; else if ( K == 0 ) answer = ncr ( N + M - 2 , N - 1 ) ; else { answer = ncr ( N + M - 2 , N - 1 ) ; var X = ( N - 1 ) / 2 + ( M - 1 ) / 2 ; var Y = ( N - 1 ) / 2 ; var midCount = ncr ( X , Y ) ; X = ( ( N - 1 ) - ( N - 1 ) / 2 ) + ( ( M - 1 ) - ( M - 1 ) / 2 ) ; Y = ( ( N - 1 ) - ( N - 1 ) / 2 ) ; midCount *= ncr ( X , Y ) ; answer -= midCount ; } return answer ; } var N = 3 ; var M = 3 ; var K = 1 ; document . write ( countPath ( N , M , K ) ) ;

Accumulator variables: answer, midCount, res
Iterator variables: i
Javascript program:
function find_max ( v , n ) { let count = 0 ; if ( n >= 2 ) count = 2 ; else count = 1 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( v [ i - 1 ] [ 0 ] < ( v [ i ] [ 0 ] - v [ i ] [ 1 ] ) ) count ++ ; else if ( v [ i + 1 ] [ 0 ] > ( v [ i ] [ 0 ] + v [ i ] [ 1 ] ) ) { count ++ ; v [ i ] [ 0 ] = v [ i ] [ 0 ] + v [ i ] [ 1 ] ; } else continue ; } return count ; } let n = 3 ; let v = [ [ 10 , 20 ] , [ 15 , 10 ] , [ 20 , 16 ] ] ; document . write ( find_max ( v , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function numberofsubstrings ( str , k , charArray ) { var N = str . length ; var available = [ 26 ] ; for ( var i = 0 ; i < k ; i ++ ) { available [ charArray [ i ] - ' ' ] = 1 ; } var lastPos = - 1 ; var ans = ( N * ( N + 1 ) ) / 2 ; for ( var i = 0 ; i < N ; i ++ ) { if ( available [ str . charAt ( i ) - ' ' ] == 0 ) { ans -= ( ( i - lastPos ) * ( N - i ) ) ; lastPos = i ; } } document . write ( ans ) ; } var str = " " ; var k = 2 ; var charArray = [ ' ' , ' ' ] ; numberofsubstrings ( str , k , charArray ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function minCost ( N , P , Q ) { var cost = 0 ; while ( N > 0 ) { if ( N & 1 ) { cost += P ; N -- ; } else { var temp = parseInt ( N / 2 ) ; if ( temp * P > Q ) cost += Q ; else cost += P * temp ; N = parseInt ( N / 2 ) ; } } return cost ; } var N = 9 , P = 5 , Q = 1 ; document . write ( minCost ( N , P , Q ) ) ;

Accumulator variables: N, cost
Javascript program:
function numberOfWays ( n , k ) { let dp = Array ( 1000 ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = 0 ; } dp [ 0 ] = 1 ; for ( let i = 1 ; i <= k ; i ++ ) { let numWays = 0 ; for ( let j = 0 ; j < n ; j ++ ) { numWays += dp [ j ] ; } for ( let j = 0 ; j < n ; j ++ ) { dp [ j ] = numWays - dp [ j ] ; } } document . write ( dp [ 0 ] ) ; } let N = 5 ; let K = 3 ; numberOfWays ( N , K ) ;

Index/key variables: i, j
Accumulator variables: i, j, numWays
Iterator variables: i, j
Javascript program:
let M = 1000000007 ; function waysOfDecoding ( s ) { let first = 1 , second = s [ 0 ] == ' ' ? 9 : s [ 0 ] == ' ' ? 0 : 1 ; for ( let i = 1 ; i < s . length ; i ++ ) { let temp = second ; if ( s [ i ] == ' ' ) { second = 9 * second ; if ( s [ i - 1 ] == ' ' ) second = ( second + 9 * first ) % M ; else if ( s [ i - 1 ] == ' ' ) second = ( second + 6 * first ) % M ; else if ( s [ i - 1 ] == ' ' ) second = ( second + 15 * first ) % M ; } else { second = s [ i ] != ' ' ? second : 0 ; if ( s [ i - 1 ] == ' ' ) second = ( second + first ) % M ; else if ( s [ i - 1 ] == ' ' && s [ i ] <= ' ' ) second = ( second + first ) % M ; else if ( s [ i - 1 ] == ' ' ) second = ( second + ( s [ i ] <= ' ' ? 2 : 1 ) * first ) % M ; } first = temp ; } return second ; } let s = " " ; document . write ( waysOfDecoding ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMinCost ( arr , X , n , i = 0 ) { if ( X <= 0 ) return 0 ; if ( i >= n ) return Number . MAX_SAFE_INTEGER ; let inc = findMinCost ( arr , X - arr [ i ] [ 0 ] , n , i + 1 ) ; if ( inc != Number . MAX_SAFE_INTEGER ) inc += arr [ i ] [ 1 ] ; let exc = findMinCost ( arr , X , n , i + 1 ) ; return Math . min ( inc , exc ) ; } let arr = [ [ 4 , 3 ] , [ 3 , 2 ] , [ 2 , 4 ] , [ 1 , 3 ] , [ 4 , 2 ] ] ; let X = 7 ; let n = arr . length ; let ans = findMinCost ( arr , X , n ) ; if ( ans != Number . MAX_SAFE_INTEGER ) document . write ( ans ) else document . write ( - 1 )

Index/key variables: i
Accumulator variables: inc
Javascript program:
function find ( N , sum ) { if ( sum > 6 * N sum < N ) return 0 ; if ( N == 1 ) { if ( sum >= 1 && sum <= 6 ) return 1.0 / 6 ; else return 0 ; } let s = 0 ; for ( let i = 1 ; i <= 6 ; i ++ ) s = s + find ( N - 1 , sum - i ) / 6 ; return s ; } let N = 4 , a = 13 , b = 17 ; let probability = 0.0 ; for ( let sum = a ; sum <= b ; sum ++ ) probability = probability + find ( N , sum ) ; document . write ( probability . toFixed ( 6 ) ) ;

Accumulator variables: i, sum
Iterator variables: i, sum
PHP program:
< ? php function maxOfMin ( $ a , $ n , $ S ) { $ mi = PHP_INT_MAX ; $ s1 = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ s1 += $ a [ $ i ] ; $ mi = min ( $ a [ $ i ] , $ mi ) ; } if ( $ s1 < $ S ) return -1 ; if ( $ s1 == $ S ) return 0 ; $ low = 0 ; $ high = $ mi ; $ ans ; while ( $ low <= $ high ) { $ mid = ( $ low + $ high ) / 2 ; if ( $ s1 - ( $ mid * $ n ) >= $ S ) { $ ans = $ mid ; $ low = $ mid + 1 ; } else $ high = $ mid - 1 ; } return $ ans ; } $ a = array ( 10 , 10 , 10 , 10 , 10 ) ; $ S = 10 ; $ n = sizeof ( $ a ) ; echo maxOfMin ( $ a , $ n , $ S ) ; ? >

Index/key variables: i
Accumulator variables: i, s1
Iterator variables: i
PHP program:
< ? php function Alphabet_N_Pattern ( $ N ) { $ index ; $ side_index ; $ size ; $ Right = 1 ; $ Left = 1 ; $ Diagonal = 2 ; for ( $ index = 0 ; $ index < $ N ; $ index ++ ) { echo $ Left ++ ; for ( $ side_index = 0 ; $ side_index < 2 * ( $ index ) ; $ side_index ++ ) echo " ▁ " ; if ( $ index != 0 && $ index != $ N - 1 ) echo $ Diagonal ++ ; else echo " ▁ " ; for ( $ side_index = 0 ; $ side_index < 2 * ( $ N - $ index - 1 ) ; $ side_index ++ ) echo " ▁ " ; echo $ Right ++ ; echo " STRNEWLINE " ; } } $ Size = 6 ; Alphabet_N_Pattern ( $ Size ) ; ? >

Accumulator variables: Diagonal, Left, Right, index, side_index
Iterator variables: index, side_index
PHP program:
< ? php function isSumDivides ( $ N ) { $ temp = $ N ; $ sum = 0 ; while ( $ temp ) { $ sum += $ temp % 10 ; $ temp = ( int ) $ temp / 10 ; } if ( $ N % $ sum == 0 ) return 1 ; else return 0 ; } $ N = 12 ; if ( isSumDivides ( $ N ) ) echo " YES " ; else echo " NO " ; ? >

Accumulator variables: sum
PHP program:
< ? php function nextGreater ( $ N ) { $ power_of_2 = 1 ; $ shift_count = 0 ; while ( true ) { if ( ( ( $ N >> $ shift_count ) & 1 ) % 2 == 0 ) break ; $ shift_count ++ ; $ power_of_2 = $ power_of_2 * 2 ; } return ( $ N + $ power_of_2 ) ; } $ N = 11 ; echo " The ▁ next ▁ number ▁ is ▁ = ▁ " , nextGreater ( $ N ) ; ? >

Accumulator variables: shift_count
PHP program:
< ? php function printTetra ( $ n ) { $ dp = array_fill ( 0 , $ n + 5 , 0 ) ; $ dp [ 0 ] = 0 ; $ dp [ 1 ] = $ dp [ 2 ] = 1 ; $ dp [ 3 ] = 2 ; for ( $ i = 4 ; $ i <= $ n ; $ i ++ ) $ dp [ $ i ] = $ dp [ $ i - 1 ] + $ dp [ $ i - 2 ] + $ dp [ $ i - 3 ] + $ dp [ $ i - 4 ] ; echo $ dp [ $ n ] ; } $ n = 10 ; printTetra ( $ n ) ; ? >

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
PHP program:
< ? php function maxSum1 ( $ arr , $ n ) { $ dp [ $ n ] = array ( ) ; $ maxi = 0 ; for ( $ i = 0 ; $ i < $ n - 1 ; $ i ++ ) { $ dp [ $ i ] = $ arr [ $ i ] ; if ( $ maxi < $ arr [ $ i ] ) $ maxi = $ arr [ $ i ] ; } for ( $ i = 2 ; $ i < $ n - 1 ; $ i ++ ) { for ( $ j = 0 ; $ j < $ i - 1 ; $ j ++ ) { if ( $ dp [ $ i ] < $ dp [ $ j ] + $ arr [ $ i ] ) { $ dp [ $ i ] = $ dp [ $ j ] + $ arr [ $ i ] ; if ( $ maxi < $ dp [ $ i ] ) $ maxi = $ dp [ $ i ] ; } } } return $ maxi ; } function maxSum2 ( $ arr , $ n ) { $ dp [ $ n ] = array ( ) ; $ maxi = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ dp [ $ i ] = $ arr [ $ i ] ; if ( $ maxi < $ arr [ $ i ] ) $ maxi = $ arr [ $ i ] ; } for ( $ i = 3 ; $ i < $ n ; $ i ++ ) { for ( $ j = 1 ; $ j < $ i - 1 ; $ j ++ ) { if ( $ dp [ $ i ] < $ arr [ $ i ] + $ dp [ $ j ] ) { $ dp [ $ i ] = $ arr [ $ i ] + $ dp [ $ j ] ; if ( $ maxi < $ dp [ $ i ] ) $ maxi = $ dp [ $ i ] ; } } } return $ maxi ; } function findMaxSum ( $ arr , $ n ) { return max ( maxSum1 ( $ arr , $ n ) , maxSum2 ( $ arr , $ n ) ) ; } $ arr = array ( 1 , 2 , 3 , 1 ) ; $ n = sizeof ( $ arr ) ; echo findMaxSum ( $ arr , $ n ) ; ? >

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
PHP program:
< ? php function permutationCoeff ( $ n , $ k ) { $ P = array ( array ( ) ) ; for ( $ i = 0 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= min ( $ i , $ k ) ; $ j ++ ) { if ( $ j == 0 ) $ P [ $ i ] [ $ j ] = 1 ; else $ P [ $ i ] [ $ j ] = $ P [ $ i - 1 ] [ $ j ] + ( $ j * $ P [ $ i - 1 ] [ $ j - 1 ] ) ; $ P [ $ i ] [ $ j + 1 ] = 0 ; } } return $ P [ $ n ] [ $ k ] ; } $ n = 10 ; $ k = 2 ; echo " Value ▁ of ▁ P ( " , $ n , " ▁ , " , $ k , " ) ▁ is ▁ " , permutationCoeff ( $ n , $ k ) ; ? >

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
PHP program:
< ? php function permutationCoeff ( $ n , $ k ) { $ fact = array ( ) ; $ fact [ 0 ] = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ fact [ $ i ] = $ i * $ fact [ $ i - 1 ] ; return $ fact [ $ n ] / $ fact [ $ n - $ k ] ; } $ n = 10 ; $ k = 2 ; echo " Value ▁ of ▁ P ( " , $ n , " ▁ " , $ k , " ) ▁ is ▁ " , permutationCoeff ( $ n , $ k ) ; ? >

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
PHP program:
< ? php function no_of_ways ( $ s ) { $ n = strlen ( $ s ) ; $ count_left = 0 ; $ count_right = 0 ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { if ( $ s [ $ i ] == $ s [ 0 ] ) { ++ $ count_left ; } else break ; } for ( $ i = $ n - 1 ; $ i >= 0 ; -- $ i ) { if ( $ s [ $ i ] == $ s [ $ n - 1 ] ) { ++ $ count_right ; } else break ; } if ( $ s [ 0 ] == $ s [ $ n - 1 ] ) return ( ( $ count_left + 1 ) * ( $ count_right + 1 ) ) ; else return ( $ count_left + $ count_right + 1 ) ; } $ s = " geeksforgeeks " ; echo no_of_ways ( $ s ) ; ? >

Index/key variables: i
Iterator variables: i
PHP program:
< ? php function preCompute ( $ n , $ s , & $ pref ) { $ pref [ 0 ] = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ pref [ $ i ] = $ pref [ $ i - 1 ] ; if ( $ s [ $ i - 1 ] == $ s [ $ i ] ) $ pref [ $ i ] ++ ; } } function query ( & $ pref , $ l , $ r ) { return $ pref [ $ r ] - $ pref [ $ l ] ; } $ s = " ggggggg " ; $ n = strlen ( $ s ) ; $ pref = array_fill ( 0 , $ n , NULL ) ; preCompute ( $ n , $ s , $ pref ) ; $ l = 1 ; $ r = 2 ; echo query ( $ pref , $ l , $ r ) . " STRNEWLINE " ; $ l = 1 ; $ r = 5 ; echo query ( $ pref , $ l , $ r ) . " STRNEWLINE " ; ? >

Index/key variables: i, l, r
Accumulator variables: i
Iterator variables: i
PHP program:
< ? php function findDirection ( $ s ) { $ count = 0 ; $ d = " " ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) { if ( $ s [ 0 ] == ' ' ) return null ; if ( $ s [ $ i ] == ' L ' ) $ count -= 1 ; else { if ( $ s [ $ i ] == ' R ' ) $ count += 1 ; } } if ( $ count > 0 ) { if ( $ count % 4 == 0 ) $ d = " N " ; else if ( $ count % 4 == 1 ) $ d = " E " ; else if ( $ count % 4 == 2 ) $ d = " S " ; else if ( $ count % 4 == 3 ) $ d = " W " ; } if ( $ count < 0 ) { if ( $ count % 4 == 0 ) $ d = " N " ; else if ( $ count % 4 == -1 ) $ d = " W " ; else if ( $ count % 4 == -2 ) $ d = " S " ; else if ( $ count % 4 == -3 ) $ d = " E " ; } return $ d ; } $ s = " LLRLRRL " ; echo findDirection ( $ s ) . " STRNEWLINE " ; $ s = " LL " ; echo findDirection ( $ s ) . " STRNEWLINE " ; ? >

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
PHP program:
< ? php function encode ( $ s , $ k ) { $ newS = " " ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; ++ $ i ) { $ val = ord ( $ s [ $ i ] ) ; $ dup = $ k ; if ( $ val + $ k > 122 ) { $ k -= ( 122 - $ val ) ; $ k = $ k % 26 ; $ newS = $ newS . chr ( 96 + $ k ) ; } else $ newS = $ newS . chr ( $ val + $ k ) ; $ k = $ dup ; } echo $ newS ; } $ str = " abc " ; $ k = 28 ; encode ( $ str , $ k ) ; ? >

Index/key variables: i
Accumulator variables: k
Iterator variables: i
PHP program:
< ? php function isVowel ( $ x ) { if ( $ x == ' a ' $ x == ' e ' $ x == ' i ' $ x == ' o ' $ x == ' u ' ) return true ; else return false ; } function updateSandwichedVowels ( $ a ) { $ n = strlen ( $ a ) ; $ updatedString = " " ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( ! $ i $ i == $ n - 1 ) { $ updatedString . = $ a [ $ i ] ; continue ; } if ( isVowel ( $ a [ $ i ] ) && ! isVowel ( $ a [ $ i - 1 ] ) && ! isVowel ( $ a [ $ i + 1 ] ) ) { continue ; } $ updatedString . = $ a [ $ i ] ; } return $ updatedString ; } $ str = " geeksforgeeks " ; $ updatedString = updateSandwichedVowels ( $ str ) ; echo $ updatedString ; ? >

Index/key variables: i
Accumulator variables: i
Iterator variables: i
PHP program:
< ? php function MaximumHeight ( $ a , $ n ) { $ result = 1 ; for ( $ i = 1 ; $ i <= $ n ; ++ $ i ) { $ y = ( $ i * ( $ i + 1 ) ) / 2 ; if ( $ y < $ n ) $ result = $ i ; else break ; } return $ result ; } $ arr = array ( 40 , 100 , 20 , 30 ) ; $ n = count ( $ arr ) ; echo MaximumHeight ( $ arr , $ n ) ; ? >

Iterator variables: i
PHP program:
< ? php function findK ( $ n , $ k ) { $ a ; $ index = 0 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ i % 2 == 1 ) $ a [ $ index ++ ] = $ i ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ i % 2 == 0 ) $ a [ $ index ++ ] = $ i ; return ( $ a [ $ k - 1 ] ) ; } $ n = 10 ; $ k = 3 ; echo findK ( $ n , $ k ) ; ? >

Accumulator variables: i, index
Iterator variables: i