dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( val ) { this . data = val this . next = null this . prev = null this . top = null this . bottom = null } } class LinkedList { constructor ( ) { this . head = null } Quad ( grid , n , m ) { this . head = new Node ( grid [ 0 ] [ 0 ] ) let temp = this . head let i = 0 let j = 1 while ( temp . top != this . head ) { if ( j < m && i == 0 ) { temp . next = new Node ( grid [ i ] [ j ] ) temp = temp . next j += 1 } else if ( j == m && i < n - 1 ) { i = i + 1 temp . bottom = new Node ( grid [ i ] [ j - 1 ] ) temp = temp . bottom } else if ( i == n - 1 && j <= m && j >= 1 ) { if ( j == m ) j = j - 1 j = j - 1 temp . prev = new Node ( grid [ i ] [ j ] ) temp = temp . prev } else if ( i <= n - 1 && j == 0 ) { i = i - 1 temp . top = new Node ( grid [ i ] [ j ] ) temp = temp . top if ( i == 1 ) temp . top = this . head } } } printList ( root ) { let temp = root document . write ( temp . data + " " ) while ( temp . top != root ) { if ( temp . next ) { document . write ( temp . next . data + " " ) temp = temp . next } if ( temp . prev ) { document . write ( temp . prev . data + " " ) temp = temp . prev } if ( temp . bottom ) { document . write ( temp . bottom . data + " " ) temp = temp . bottom } if ( temp . top ) { document . write ( temp . top . data + " " ) temp = temp . top } } } } let grid = [ [ 13 , 42 , 93 , 88 ] , [ 26 , 38 , 66 , 42 ] , [ 75 , 63 , 78 , 12 ] ] let n = grid . length let m = grid [ 0 ] . length let l = new LinkedList ( ) l . Quad ( grid , n , m ) l . printList ( l . head )

Index/key variables: i, j
Accumulator variables: j
Class/struct names: LinkedList, Node
Javascript program:
function isPossibleToReach ( A , N , X , Y ) { let distance = Math . sqrt ( ( X * X + Y * Y ) ) ; let mx = 0 ; for ( let i = 0 ; i < N ; i ++ ) { mx += A [ i ] ; } if ( mx < distance ) { document . write ( " " ) ; return 0 ; } if ( ( mx - distance ) < 0.000001 ) { document . write ( " " ) ; return 0 ; } for ( let i = 0 ; i < N ; i ++ ) { if ( distance + mx < 2 * A [ i ] ) { document . write ( " " ) ; return 0 ; } } document . write ( " " ) ; return 0 ; } let A = [ 2 , 5 ] ; let X = 5 , Y = 4 ; let N = A . length ; isPossibleToReach ( A , N , X , Y ) ;

Index/key variables: i
Accumulator variables: i, mx
Iterator variables: i
Javascript program:
function canReach ( X , Y ) { var steps = 0 ; while ( X != 0 Y != 0 ) { var pos1 = X % 3 ; var pos2 = Y % 3 ; if ( pos1 == 2 pos2 == 2 ) { return false ; } if ( pos1 == 1 && pos2 == 1 ) { return false ; } if ( pos1 == 0 && pos2 == 0 ) { return false ; } X /= 3 ; Y /= 3 ; steps ++ ; } return true ; } var X = 10 , Y = 30 ; if ( canReach ( X , Y ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Accumulator variables: X, Y, steps
Javascript program:
function minimumRectangleArea ( A , N ) { let ans ; A . sort ( ) ; ans = ( A [ N - 1 ] - A [ 0 ] ) * ( A [ 2 * N - 1 ] - A [ N ] ) ; for ( let i = 1 ; i < N ; i ++ ) ans = Math . min ( ans , ( A [ 2 * N - 1 ] - A [ 0 ] ) * ( A [ i + N - 1 ] - A [ i ] ) ) ; return ans ; } let A = [ 2 , 4 , 1 , 5 , 3 , 6 , 7 , 8 ] ; let N = A . length N = Math . floor ( N / 2 ) ; document . write ( minimumRectangleArea ( A , N ) + " " ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function find ( a , b , N , K ) { for ( let i = 0 ; i < N ; i ++ ) { let count = 0 ; for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) { continue ; } let dis = Math . abs ( a [ i ] - a [ j ] ) + Math . abs ( b [ i ] - b [ j ] ) ; if ( dis <= K ) { count ++ ; } if ( count == N - 1 ) { return " " ; } } } return " " ; } let N = 5 ; let A = [ 1 , 0 , 2 , 1 , 1 ] ; let B = [ 1 , 1 , 1 , 0 , 2 ] ; let K = 1 ; document . write ( find ( A , B , N , K ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function findPairs ( x , y , K ) { let n = x . length ; let ans = 0 ; for ( let i = 0 ; i < n ; ++ i ) { for ( let j = i + 1 ; j < n ; ++ j ) { if ( K * Math . abs ( x [ i ] - x [ j ] ) >= Math . abs ( y [ i ] - y [ j ] ) ) { ++ ans ; } } } document . write ( ans ) ; } let X = [ 2 , 1 , 0 ] , Y = [ 1 , 2 , 0 ] ; let K = 1 ; findPairs ( X , Y , K ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = ( 1e6 + 5 ) function query ( arr , Q ) { let pre = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) pre [ i ] = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] [ 0 ] < 0 arr [ i ] [ 1 ] < 0 ) continue ; let sum = Math . ceil ( ( arr [ i ] [ 0 ] + arr [ i ] [ 1 ] ) ) ; pre [ sum ] ++ ; } for ( let i = 1 ; i < MAX ; i ++ ) pre [ i ] += pre [ i - 1 ] ; for ( let i = 0 ; i < Q . length ; i ++ ) { document . write ( pre [ Q [ i ] ] + " " ) ; } document . write ( " " ) ; } let arr = [ [ 2.1 , 3.0 ] , [ 3.7 , 1.2 ] , [ 1.5 , 6.5 ] , [ 1.2 , 0.0 ] ] ; let Q = [ 2 , 8 , 5 ] ; let N = arr . length ; let M = Q . length ; query ( arr , Q ) ;

Index/key variables: i, sum
Accumulator variables: i
Iterator variables: i
Javascript program:
function doIntersect ( X , Y ) { if ( X [ 0 ] > X [ 3 ] X [ 2 ] > X [ 1 ] ) return false ; if ( Y [ 0 ] > Y [ 3 ] Y [ 2 ] > Y [ 1 ] ) return false ; return true ; } function getUnionPerimeter ( X , Y ) { let perimeter = 0 ; if ( ! doIntersect ( X , Y ) ) { perimeter += 2 * ( Math . abs ( X [ 1 ] - X [ 0 ] ) + Math . abs ( Y [ 1 ] - Y [ 0 ] ) ) ; perimeter += 2 * ( Math . abs ( X [ 3 ] - X [ 2 ] ) + Math . abs ( Y [ 3 ] - Y [ 2 ] ) ) ; } else { let w = Math . max ( ... X ) - Math . min ( ... X ) ; let l = Math . max ( ... Y ) - Math . min ( ... Y ) ; perimeter = 2 * ( l + w ) ; } return perimeter ; } let X = [ - 1 , 2 , 4 , 6 ] ; let Y = [ 2 , 5 , 3 , 7 ] ; document . write ( getUnionPerimeter ( X , Y ) ) ;

Accumulator variables: perimeter
Javascript program:
function CrossProduct ( A ) { var X1 = ( A [ 1 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; var Y1 = ( A [ 1 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; var X2 = ( A [ 2 ] [ 0 ] - A [ 0 ] [ 0 ] ) ; var Y2 = ( A [ 2 ] [ 1 ] - A [ 0 ] [ 1 ] ) ; return ( X1 * Y2 - Y1 * X2 ) ; } function isConvex ( points ) { var N = points . length ; var prev = 0 ; var curr = 0 ; for ( i = 0 ; i < N ; i ++ ) { var temp = [ points [ i ] , points [ ( i + 1 ) % N ] , points [ ( i + 2 ) % N ] ] ; curr = CrossProduct ( temp ) ; if ( curr != 0 ) { if ( curr * prev < 0 ) { return false ; } else { prev = curr ; } } } return true ; } var points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ; if ( isConvex ( points ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const samePerimeterAndArea = ( ) => { let se = [ ] ; for ( let i = 1 ; i <= 256 ; ++ i ) { for ( let j = 1 ; j <= 256 ; ++ j ) { for ( let k = 1 ; k <= 256 ; ++ k ) { let peri = i + j + k ; let mul1 = - i + j + k ; let mul2 = i - j + k ; let mul3 = i + j - k ; if ( 16 * peri == mul1 * mul2 * mul3 ) { let v = [ i , j , k ] ; v . sort ( ( a , b ) => a - b ) ; let check = - 1 ; for ( let i = 0 ; i < se . length ; ++ i ) { if ( se [ i ] [ 0 ] == v [ 0 ] && se [ i ] [ 1 ] == v [ 1 ] && se [ i ] [ 2 ] == v [ 2 ] ) check = 1 ; } if ( check === - 1 ) se . push ( v ) ; } } } } for ( let it = 0 ; it < se . length ; ++ it ) { document . write ( ` ${ se [ it ] } ` ) ; } } samePerimeterAndArea ( ) ;

Index/key variables: i, it
Iterator variables: i, it, j, k
Javascript program:
function cntRect ( points , N , rectangle ) { var cntHor = new Set ( ) ; var cntVer = new Set ( ) ; cntHor . add ( 0 ) ; cntVer . add ( 0 ) ; cntHor . add ( rectangle [ 3 ] [ 0 ] ) ; cntVer . add ( rectangle [ 3 ] [ 1 ] ) ; for ( var i = 0 ; i < N ; i ++ ) { cntHor . add ( points [ i ] [ 0 ] ) ; cntVer . add ( points [ i ] [ 1 ] ) ; } return ( cntHor . size - 1 ) * ( cntVer . size - 1 ) ; } var rectangle = [ [ 0 , 0 ] , [ 0 , 5 ] , [ 5 , 0 ] , [ 5 , 5 ] ] ; var points = [ [ 1 , 2 ] , [ 3 , 4 ] ] ; var N = points . length ; document . write ( cntRect ( points , N , rectangle ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function numberOfSquares ( X , Y , N , M ) { var m1 = new Map ( ) , m2 = new Map ( ) ; var i , j , ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { var dist = Math . abs ( X [ i ] - X [ j ] ) ; if ( m1 . has ( dist ) ) m1 . set ( dist , m1 . get ( dist ) + 1 ) else m1 . set ( dist , 1 ) ; } } for ( i = 0 ; i < M ; i ++ ) { for ( j = i + 1 ; j < M ; j ++ ) { var dist = Math . abs ( Y [ i ] - Y [ j ] ) ; if ( m2 . has ( dist ) ) m2 . set ( dist , m2 . get ( dist ) + 1 ) else m2 . set ( dist , 1 ) ; } } m1 . forEach ( ( value , key ) => { if ( m2 . has ( key ) ) { ans += ( value * m2 . get ( key ) ) ; } } ) ; return ans ; } var X = [ 1 , 3 , 7 ] ; var Y = [ 2 , 4 , 6 , 1 ] ; var N = X . length ; var M = Y . length ; document . write ( numberOfSquares ( X , Y , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function calculateTriangles ( sides ) { let count = Math . pow ( sides [ 0 ] + sides [ 1 ] + sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 0 ] , 2 ) ; count -= Math . pow ( sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 4 ] , 2 ) ; return ( count ) ; } let sides = [ 1 , 1 , 1 , 1 , 1 , 1 ] ; document . write ( ( calculateTriangles ( sides ) ) + " " ) ; let sides1 = [ 2 , 2 , 1 , 3 , 1 , 2 ] ; document . write ( ( calculateTriangles ( sides1 ) ) + " " ) ;

Accumulator variables: count
Javascript program:
function find ( x , y , p ) { let mind = 0 ; for ( let i = 0 ; i < p . length ; i ++ ) { let a = p [ i ] [ 0 ] , b = p [ i ] [ 1 ] ; mind += Math . sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) ) ; } return mind ; } function getMinDistSum ( p ) { let x = 0 , y = 0 ; for ( let i = 0 ; i < p . length ; i ++ ) { x += p [ i ] [ 0 ] ; y += p [ i ] [ 1 ] ; } x = x / p . length ; y = y / p . length ; let mind = find ( x , y , p ) ; return mind ; } let vec = [ [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] , [ 2 , 1 ] ] ; let d = getMinDistSum ( vec ) ; document . write ( d ) ;

Index/key variables: i
Accumulator variables: i, mind, x, y
Iterator variables: i
Javascript program:
function det ( d ) { let Sum = d [ 0 ] [ 0 ] * ( ( d [ 1 ] [ 1 ] * d [ 2 ] [ 2 ] ) - ( d [ 2 ] [ 1 ] * d [ 1 ] [ 2 ] ) ) ; Sum -= d [ 0 ] [ 1 ] * ( ( d [ 1 ] [ 0 ] * d [ 2 ] [ 2 ] ) - ( d [ 1 ] [ 2 ] * d [ 2 ] [ 0 ] ) ) ; Sum += d [ 0 ] [ 2 ] * ( ( d [ 0 ] [ 1 ] * d [ 1 ] [ 2 ] ) - ( d [ 0 ] [ 2 ] * d [ 1 ] [ 1 ] ) ) ; return Sum ; } let x1 = - 3 , y1 = 1 , z1 = 5 ; let a1 = - 3 , b1 = 1 , c1 = 5 ; let x2 = - 1 , y2 = 2 , z2 = 5 ; let a2 = - 1 , b2 = 2 , c2 = 5 ; let det_list = [ [ x2 - x1 , y2 - y1 , z2 - z1 ] , [ a1 , b1 , c1 ] , [ a2 , b2 , c2 ] ] ; if ( det ( det_list ) == 0 ) document . write ( " " ) ; else document . write ( " " ) ;

Accumulator variables: Sum
Javascript program:
function checkValidPolygon ( arr , N ) { var sum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 180 * ( N - 2 ) ) document . write ( " " ) ; else document . write ( " " ) ; } var N = 3 ; var arr = [ 60 , 60 , 60 ] ; checkValidPolygon ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let MAX = 1001 ; let arr = new Array ( MAX ) ; for ( var i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new Array ( 2 ) ; } function updateArray ( x1 , y1 , x2 , y2 ) { for ( let i = x1 ; i < x2 ; i ++ ) { for ( let j = y1 ; j < y2 ; j ++ ) { arr [ i ] [ j ] = true ; } } } function findAreaCovered ( ) { let area = 0 ; for ( let i = 0 ; i < MAX ; i ++ ) { for ( let j = 0 ; j < MAX ; j ++ ) { if ( arr [ i ] [ j ] == true ) { area ++ ; } } } return area ; } let N = 3 ; let A = [ [ 1 , 3 , 4 , 5 ] , [ 3 , 1 , 7 , 4 ] , [ 5 , 3 , 8 , 6 ] ] ; for ( let i = 0 ; i < N ; i ++ ) { updateArray ( A [ i ] [ 0 ] , A [ i ] [ 1 ] , A [ i ] [ 2 ] , A [ i ] [ 3 ] ) ; } let area = findAreaCovered ( ) ; document . write ( area ) ;

Index/key variables: i, j
Accumulator variables: area, i, j
Iterator variables: i, j
Javascript program:
function fact ( n ) { let res = 1 ; for ( let i = 2 ; i < n + 1 ; i ++ ) res = res * i ; return res ; } function nCr ( n , r ) { return ( fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ) ; } let n = 5 ; document . write ( nCr ( n , 4 ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let pi = Math . acos ( - 1.0 ) ; function nGon ( N ) { let proAngleVar ; if ( N % 4 == 0 ) { proAngleVar = pi * ( 180.0 / N ) / 180 ; } else { proAngleVar = pi * ( 180.0 / ( 2 * N ) ) / 180 ; } let negX = 1.0e+99 , posX = - 1.0e+99 , negY = 1.0e+99 , posY = - 1.0e+99 ; for ( let j = 0 ; j < N ; ++ j ) { let px = Math . cos ( 2 * pi * j / N + proAngleVar ) ; let py = Math . sin ( 2 * pi * j / N + proAngleVar ) ; negX = Math . min ( negX , px ) ; posX = Math . max ( posX , px ) ; negY = Math . min ( negY , py ) ; posY = Math . max ( posY , py ) ; } let opt2 = Math . max ( posX - negX , posY - negY ) ; return opt2 / Math . sin ( pi / N ) / 2 ; } let N = 10 ; document . write ( nGon ( N ) . toFixed ( 5 ) ) ;

Iterator variables: j
Javascript program:
function numTrip ( points ) { let res = 0 ; for ( let i = 0 ; i < points . length ; ++ i ) { let map = new Map ( ) ; for ( let j = 0 ; j < points . length ; ++ j ) { if ( j == i ) continue ; let dy = points [ i ] [ 1 ] - points [ j ] [ 1 ] ; let dx = points [ i ] [ 0 ] - points [ j ] [ 0 ] ; let key = dy * dy ; key += dx * dx ; if ( map . has ( key ) ) { map . set ( key , map . get ( key ) + 1 ) ; } else { map . set ( key , 1 ) ; } } for ( let [ key , value ] of map . entries ( ) ) res += value * ( value - 1 ) ; } return res ; } let mat = [ ] ; mat . push ( [ 0 , 0 ] ) ; mat . push ( [ 1 , 0 ] ) ; mat . push ( [ 2 , 0 ] ) ; document . write ( numTrip ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: key, res
Iterator variables: i, j
Javascript program:
function NotParallel ( p , n ) { var x_axis = new Map ( ) , y_axis = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( x_axis . has ( p [ i ] [ 0 ] ) ) x_axis . set ( p [ i ] [ 0 ] , x_axis . get ( p [ i ] [ 0 ] ) + 1 ) else x_axis . set ( p [ i ] [ 0 ] , 1 ) if ( y_axis . has ( p [ i ] [ 1 ] ) ) y_axis . set ( p [ i ] [ 1 ] , y_axis . get ( p [ i ] [ 1 ] ) + 1 ) else y_axis . set ( p [ i ] [ 1 ] , 1 ) } var total = ( n * ( n - 1 ) ) / 2 ; x_axis . forEach ( ( value , key ) => { var c = value ; total -= ( c * ( c - 1 ) ) / 2 ; } ) ; y_axis . forEach ( ( value , key ) => { var c = value ; total -= ( c * ( c - 1 ) ) / 2 ; } ) ; return total ; } var p = [ [ 1 , 2 ] , [ 1 , 5 ] , [ 1 , 15 ] , [ 2 , 10 ] ] ; var n = p . length ; document . write ( NotParallel ( p , n ) ) ;

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Javascript program:
function times ( steps , n ) { let current_level = 0 ; let previous_level = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { previous_level = current_level ; current_level = current_level + steps [ i ] ; if ( ( previous_level < 0 && current_level >= 0 ) || ( previous_level > 0 && current_level <= 0 ) ) { count ++ ; } } return count ; } let steps = [ 1 , - 1 , 0 , 0 , 1 , 1 , - 3 , 2 ] ; let n = steps . length ; document . write ( times ( steps , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function XandYandZintercept ( A , B , C , D ) { let rslt = new Array ( 3 ) ; let x = - D / A ; let y = - D / B ; let z = - D / C ; rslt [ 0 ] = x ; rslt [ 1 ] = y ; rslt [ 2 ] = z ; return rslt ; } function equation_plane ( p , q , r ) { let x1 = p [ 0 ] ; let y1 = p [ 1 ] ; let z1 = p [ 2 ] ; let x2 = q [ 0 ] ; let y2 = q [ 1 ] ; let z2 = q [ 2 ] ; let x3 = r [ 0 ] ; let y3 = r [ 1 ] ; let z3 = r [ 2 ] ; let a1 = x2 - x1 ; let b1 = y2 - y1 ; let c1 = z2 - z1 ; let a2 = x3 - x1 ; let b2 = y3 - y1 ; let c2 = z3 - z1 ; let A = b1 * c2 - b2 * c1 ; let B = a2 * c1 - a1 * c2 ; let C = a1 * b2 - b1 * a2 ; let D = ( - A * x1 - B * y1 - C * z1 ) ; let rslt = XandYandZintercept ( A , B , C , D ) ; for ( let i = 0 ; i < 3 ; i ++ ) { document . write ( rslt [ i ] + " " ) ; } } let x1 = - 1 ; let y1 = 2 ; let z1 = 1 ; let x2 = 0 ; let y2 = - 3 ; let z2 = 2 ; let x3 = 1 ; let y3 = 1 ; let z3 = - 4 ; let p = [ x1 , y1 , z1 ] ; let q = [ x2 , y2 , z2 ] ; let r = [ x3 , y3 , z3 ] ; equation_plane ( p , q , r ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dx = [ - 1 , 0 , 1 , 0 ] ; let dy = [ 0 , 1 , 0 , - 1 ] ; function ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) { let a = ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ; let b = ( ( x1 - x3 ) * ( x1 - x3 ) ) + ( ( y1 - y3 ) * ( y1 - y3 ) ) ; let c = ( ( x2 - x3 ) * ( x2 - x3 ) ) + ( ( y2 - y3 ) * ( y2 - y3 ) ) ; if ( ( a == ( b + c ) && a != 0 && b != 0 && c != 0 ) || ( b == ( a + c ) && a != 0 && b != 0 && c != 0 ) || ( c == ( a + b ) && a != 0 && b != 0 && c != 0 ) ) { return 1 ; } return 0 ; } function isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) { let x , y ; let possible = 0 ; if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { document . write ( " " ) ; return ; } else { for ( let i = 0 ; i < 4 ; i ++ ) { x = dx [ i ] + x1 ; y = dy [ i ] + y1 ; if ( ifRight ( x , y , x2 , y2 , x3 , y3 ) ) { document . write ( " " ) ; return ; } x = dx [ i ] + x2 ; y = dy [ i ] + y2 ; if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) { document . write ( " " ) ; return ; } x = dx [ i ] + x3 ; y = dy [ i ] + y3 ; if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) { document . write ( " " ) ; return ; } } } if ( ! possible ) document . write ( " " ) ; } let x1 = - 49 , y1 = 0 ; let x2 = 0 , y2 = 50 ; let x3 = 0 , y3 = - 50 ; isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let PI = 3.14 ; function find_area ( r , d ) { let R = d / PI ; R += Math . pow ( r , 2 ) ; R = Math . sqrt ( R ) ; let area = PI * Math . pow ( R , 2 ) ; return area ; } let r = 4 , d = 5 ; document . write ( find_area ( r , d ) . toFixed ( 2 ) ) ;

Accumulator variables: R
Javascript program:
function isPerfect ( N ) { let sumOfDivisors = 1 ; for ( let i = 2 ; i <= Math . floor ( N / 2 ) ; ++ i ) { if ( N % i === 0 ) { sumOfDivisors += i ; } } if ( sumOfDivisors === N ) { return 1 ; } else return 0 ; } function sumOfDigits ( N ) { let sum = 0 ; while ( N != 0 ) { sum += ( N % 10 ) ; N = Math . floor ( N / 10 ) ; } return sum ; } function countPerfectNumbers ( arr , N ) { for ( let i = 0 ; i < N ; ++ i ) { if ( isPerfect ( arr [ i ] ) ) { let sum = sumOfDigits ( arr [ i ] ) ; if ( isPerfect ( sum ) ) { document . write ( arr [ i ] + " " ) ; } } } } let arr = [ 3 , 8 , 12 , 28 , 6 ] ; let N = arr . length ; countPerfectNumbers ( arr , N ) ;

Index/key variables: i
Accumulator variables: sum, sumOfDivisors
Iterator variables: i
Javascript program:
class TreeNode { constructor ( x ) { this . val = x ; this . left = null ; this . right = null ; } } function findSum ( root ) { let que = [ ] ; que . push ( root ) ; let ans = 0 ; while ( que . length > 0 ) { let leaf = 0 ; let nonleaf = 0 ; let length = que . length ; while ( length > 0 ) { let temp = que . shift ( ) ; if ( temp . left == null && temp . right == null ) leaf += temp . val ; else nonleaf += temp . val ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; length -= 1 ; } ans += leaf & nonleaf ; } return ans ; } let root = new TreeNode ( 5 ) ; root . left = new TreeNode ( 3 ) ; root . right = new TreeNode ( 9 ) ; root . left . left = new TreeNode ( 6 ) ; root . left . right = new TreeNode ( 4 ) ; root . left . left . right = new TreeNode ( 7 ) ; document . write ( findSum ( root ) ) ;

Accumulator variables: ans, leaf, nonleaf
Class/struct names: TreeNode
Javascript program:
function Mletime ( a , b , n , m ) { let ans = 2147483647 ; let prefix_a = [ ] ; for ( let i = 0 ; i < 10 ; i ++ ) { prefix_a [ i ] = 0 ; } let prefix_b = [ ] ; for ( let i = 0 ; i < 10 ; i ++ ) { prefix_b [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { prefix_a [ a [ i ] ] ++ ; } for ( let i = 0 ; i < m ; i ++ ) { prefix_b [ b [ i ] ] ++ ; } for ( let i = 1 ; i <= 9 ; i ++ ) { prefix_a [ i ] += prefix_a [ i - 1 ] ; } for ( let i = 1 ; i <= 9 ; i ++ ) { prefix_b [ i ] += prefix_b [ i - 1 ] ; } for ( let i = 0 ; i <= 9 ; i ++ ) { ans = Math . min ( ans , prefix_a [ i ] + m - prefix_b [ i ] ) ; ans = Math . min ( ans , n - prefix_a [ i ] + prefix_b [ i ] ) ; } document . write ( ans ) ; } let A = [ 0 , 0 , 1 , 3 , 3 ] ; let B = [ 2 , 0 , 3 ] ; let N = A . length ; let M = B . length ; Mletime ( A , B , N , M ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findReverse ( N ) { let rev = 0 ; while ( N > 0 ) { rev <<= 1 ; if ( N & 1 == 1 ) rev ^= 1 ; N >>= 1 ; } return rev ; } function countElements ( arr , N ) { let ans = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { ans . push ( findReverse ( arr [ i ] ) ) ; } let cnt = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { cnt [ arr [ i ] ] = 1 ; } let count = 0 ; for ( let i = 0 ; i < ans . length ; i ++ ) { if ( cnt [ ans [ i ] ] ) count ++ ; } document . write ( count , ' ' ) ; } let arr = [ 1 , 30 , 3 , 8 , 12 ] ; let N = arr . length ; countElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: count, i, rev
Iterator variables: i
Javascript program:
function fizzBuzz ( N ) { let count3 = 0 ; let count5 = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { count3 ++ ; count5 ++ ; let flag = false ; if ( count3 == 3 ) { document . write ( " " ) ; count3 = 0 ; flag = true ; } if ( count5 == 5 ) { document . write ( " " ) ; count5 = 0 ; flag = true ; } if ( ! flag ) { document . write ( i ) ; } document . write ( " " ) ; } } let N = 15 ; fizzBuzz ( N ) ;

Accumulator variables: count3, count5, i
Iterator variables: i
Boolean variables: flag
Javascript program:
var prime = Array ( 1000005 ) . fill ( true ) ; function SieveOfEratosthenes ( N ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p <= N ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * p ; i <= N ; i += p ) prime [ i ] = false ; } } } function checkElementsOnDiagonal ( M , N ) { var flag = 1 ; SieveOfEratosthenes ( 1000000 ) ; for ( var i = 0 ; i < N ; i ++ ) { flag &= ( prime [ M [ i ] [ i ] ] && prime [ M [ i ] [ N - 1 - i ] ] ) ; } if ( flag ) document . write ( " " ) ; else document . write ( " " ) ; } var M = [ [ 1 , 2 , 3 , 13 ] , [ 5 , 3 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 7 ] ] ; var N = M . length ; checkElementsOnDiagonal ( M , N ) ;

Index/key variables: i, p
Accumulator variables: flag, i, p
Iterator variables: i, p
Javascript program:
function circularPermutation ( n , start ) { var res = [ 0 ] ; var ret = [ ] ; var index = - 1 ; for ( var k = 0 , add = 1 << k ; k < n ; k ++ , add = 1 << k ) { for ( var i = res . length - 1 ; i >= 0 ; i -- ) { if ( res [ i ] + add == start ) index = res . length ; res . push ( res [ i ] + add ) ; } } if ( start == 0 ) return res ; while ( ret . length < res . length ) { ret . push ( res [ index ] ) ; index = ( index + 1 ) % res . length ; } return ret ; } var N = 2 , S = 3 ; var print = circularPermutation ( N , S ) ; document . write ( " " ) ; for ( var i = 0 ; i < print . length - 1 ; i ++ ) { document . write ( print [ i ] + " " ) ; } document . write ( print [ print . length - 1 ] + " " ) ;

Index/key variables: i, index
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function countPairs ( a , n ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) { if ( a [ j ] != 0 && a [ i ] % a [ j ] == 0 ) { if ( ( a [ i ] + a [ j ] ) == ( a [ i ] / a [ j ] ) ) count ++ ; } } } return count ; } var arr = [ - 4 , - 3 , 0 , 2 , 1 ] ; var N = arr . length ; document . write ( countPairs ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j