codeparrot/xlcost-text-to-code huggingface dataset:
Lexicographically largest N | Function to find the lexicographically largest bitonic sequence of size N elements lies in the range [ low , high ] ; Store index of highest element ; If high_index > ( N - 1 ) / 2 , then remaining N / 2 elements cannot be placed in bitonic order ; If high_index <= 0 , then set high_index as 1 ; Stores the resultant sequence ; Store the high value ; Maintain strictly decreasing sequence from index high_index to 0 starting with temp ; Store the value and decrement the temp variable by 1 ; Maintain the strictly decreasing sequence from index high_index + 1 to N - 1 starting with high - 1 ; Store the value and decrement high by 1 ; Print the resultant sequence ; Driver Code ; Function Call
function LargestArray ( N , low , high ) { let high_index = N - ( high - low + 1 ) ; if ( high_index > ( N - 1 ) / 2 ) { document . write ( " " ) ; return ; } if ( high_index <= 0 ) high_index = 1 ; let A = [ ] ; let temp = high ; for ( let i = high_index ; i >= 0 ; i -- ) { A [ i ] = temp -- ; } high -= 1 ; for ( let i = high_index + 1 ; i < N ; i ++ ) A [ i ] = high -- ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let N = 5 , low = 2 , high = 6 ; LargestArray ( N , low , high ) ;
Print matrix elements from top | Function to traverse the matrix diagonally upwards ; Stores the maximum size of vector from all row of matrix nums [ ] [ ] ; Store elements in desired order ; Store every element on the basis of sum of index ( i + j ) ; Print the stored result ; Print in reverse order ; Given vector of vectors arr ; Function Call
function printDiagonalTraversal ( nums ) { let max_size = nums [ 0 ] . length ; let v = [ ] ; for ( let i = 0 ; i < 2 * max_size - 1 ; i ++ ) { v . push ( [ ] ) ; } for ( let i = 0 ; i < nums [ 0 ] . length ; i ++ ) { for ( let j = 0 ; j < nums [ 0 ] . length ; j ++ ) { v [ i + j ] . push ( nums [ i ] [ j ] ) ; } } for ( let i = 0 ; i < v . length ; i ++ ) { for ( let j = v [ i ] . length - 1 ; j >= 0 ; j -- ) { document . write ( v [ i ] [ j ] + " " ) ; } } } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; printDiagonalTraversal ( arr ) ;
Check if given string satisfies the following conditions | Function to check if given string satisfies the given conditions ; Dimensions ; Left diagonal ; Right diagonal ; Conditions not satisfied ; Prlet Yes ; Given String ; Function call
function isValid ( s ) { let n = Math . sqrt ( s . length ) ; let check = s [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { let x = i , y = i ; while ( x >= 0 && y < n ) { if ( s [ ( n * x ) + y ] != check || s [ ( n * y ) + x ] != check ) { document . write ( " " ) ; return ; } x -- ; y ++ ; } } document . write ( " " ) ; } let str = " " ; isValid ( str ) ;
Sum of all possible strings obtained by removal of non | JavaScript program for the above approach ; Function to convert a character to its equivalent digit ; Function to precompute powers of 10 ; Function to precompute prefix sum of numerical Strings ; Function to return the i - th term of Triangular Number ; Function to return the sum of all resulting Strings ; Precompute powers of 10 ; Precompute prefix sum ; Initialize result ; Apply the above general formula for every i ; Return the answer ; Driver Code ; Function Call
var N = 10 ; var pref = new Array ( N ) . fill ( 0 ) ; var power = new Array ( N ) . fill ( 0 ) ; function toDigit ( ch ) { return ch - " " ; } function powerOf10 ( ) { power [ 0 ] = 1 ; for ( var i = 1 ; i < N ; i ++ ) power [ i ] = power [ i - 1 ] * 10 ; } function precomputePrefix ( str , n ) { pref [ 0 ] = str [ 0 ] - " " ; for ( var i = 1 ; i < n ; i ++ ) pref [ i ] = pref [ i - 1 ] + toDigit ( str [ i ] ) ; } function triangularNumber ( i ) { var res = parseInt ( ( i * ( i + 1 ) ) / 2 ) ; return res ; } function sumOfSubStrings ( str ) { var n = str . length ; powerOf10 ( ) ; precomputePrefix ( str . split ( " " ) , n ) ; var ans = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { ans += ( pref [ n - i - 2 ] * ( i + 1 ) + toDigit ( str [ n - i - 1 ] ) * triangularNumber ( n - i - 1 ) ) * power [ i ] ; } return ans ; } var str = " " ; document . write ( sumOfSubStrings ( str ) ) ;
Sum of products of all possible Subarrays | Function that finds the sum of products of all subarray of arr [ ] ; Stores sum of all subarrays ; Iterate array from behind ; Update the ans ; Update the res ; Prlet the final sum ; Given array arr [ ] ; Size of array ; Function Call
function sumOfSubarrayProd ( arr , n ) { let ans = 0 ; let res = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let incr = arr [ i ] * ( 1 + res ) ; ans += incr ; res = incr ; } document . write ( ans ) ; } let arr = [ 1 , 2 , 3 ] ; let N = arr . length ; sumOfSubarrayProd ( arr , N ) ;
Sum of all odd length subarrays | Function to calculate the sum of all odd length subarrays ; Stores the sum ; Size of array ; Traverse the array ; Generate all subarray of odd length ; Add the element to sum ; Return the final sum ; Given array arr [ ] ; Function call
function OddLengthSum ( arr ) { var sum = 0 ; var l = arr . length ; for ( var i = 0 ; i < l ; i ++ ) { for ( var j = i ; j < l ; j += 2 ) { for ( var k = i ; k <= j ; k ++ ) { sum += arr [ k ] ; } } } return sum ; } var arr = [ 1 , 5 , 3 , 1 , 2 ] document . write ( OddLengthSum ( arr ) ) ;
Sum of all odd length subarrays | Function that finds the sum of all the element of subarrays of odd length ; Stores the sum ; Size of array ; Traverse the given array arr [ ] ; Add to the sum for each contribution of the arr [ i ] ; Return the final sum ; Given array arr [ ] ; Function call
function OddLengthSum ( arr ) { let sum = 0 ; let l = arr . length ; for ( let i = 0 ; i < l ; i ++ ) { sum += Math . floor ( ( ( i + 1 ) * ( l - i ) + 1 ) / 2 ) * arr [ i ] ; } return sum ; } let arr = [ 1 , 5 , 3 , 1 , 2 ] ; document . write ( OddLengthSum ( arr ) ) ;
Check if Euler Totient Function is same for a given number and twice of that number | Function to find the Euler 's Totient Function ; Initialize result as N ; Consider all prime factors of n and subtract their multiples from result ; Return the count ; Function to check if phi ( n ) is equals phi ( 2 * n ) ; Driver Code
function phi ( n ) { let result = 1 ; for ( let p = 2 ; p < n ; p ++ ) { if ( __gcd ( p , n ) == 1 ) { result ++ ; } } return result ; } function sameEulerTotient ( n ) { return phi ( n ) == phi ( 2 * n ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let N = 13 ; if ( sameEulerTotient ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Check if Euler Totient Function is same for a given number and twice of that number | Function to check if phi ( n ) is equals phi ( 2 * n ) ; Return if N is odd ; Driver Code ; Function Call
function sameEulerTotient ( N ) { return ( N & 1 ) ; } var N = 13 ; if ( sameEulerTotient ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;
Smallest occurring element in each subsequence | Function that count the subsequence such that each element as the minimum element in the subsequence ; Store index in a map ; Sort the array ; To store count of subsequence ; Traverse the array ; Store count of subsequence ; Print the count of subsequence ; Driver code ; Function call
function solve ( arr , N ) { var M = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { M . set ( i , arr [ i ] ) ; } arr . sort ( ( a , b ) => a - b ) ; var Count = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { Count . set ( arr [ i ] , parseInt ( Math . pow ( 2 , N - i - 1 ) ) ) ; } M . forEach ( ( value , key ) => { document . write ( Count . get ( value ) + ' ' ) ; } ) ; } var arr = [ 5 , 2 , 1 ] ; var N = arr . length ; solve ( arr , N ) ;
Check if a Matrix is Reverse Bitonic or Not | Java script Program to check if a matrix is Reverse Bitonic or not ; Function to check if an array is Reverse Bitonic or not ; Check for decreasing sequence ; Check for increasing sequence ; Function to check whether given matrix is bitonic or not ; Check row - wise ; Check column wise ; Generate an array consisting of elements of the current column ; Driver Code
let N = 3 , M = 3 ; function checkReverseBitonic ( arr , n ) { let i , j , f = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { f = 1 ; break ; } } if ( i == n ) return true ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ j - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { if ( f == 1 ) return false ; } } return true ; } function check ( arr ) { let f = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! checkReverseBitonic ( arr [ i ] , M ) ) { document . write ( " " + " " ) ; return ; } } for ( let i = 0 ; i < N ; i ++ ) { let temp = [ N ] ; for ( let j = 0 ; j < N ; j ++ ) { temp [ j ] = arr [ j ] [ i ] ; } if ( ! checkReverseBitonic ( temp , N ) ) { document . write ( " " + " " ) ; return ; } } document . write ( " " ) ; } let m = [ [ 2 , 3 , 4 ] , [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ; check ( m ) ;
Find the element at the specified index of a Spirally Filled Matrix | Function to return the element at ( x , y ) ; If y is greater ; If y is odd ; If y is even ; If x is even ; If x is odd ; Driver code
function SpiralElement ( x , y ) { var r ; if ( x < y ) { if ( y % 2 == 1 ) { r = y * y ; return ( r - x + 1 ) ; } else { r = ( y - 1 ) * ( y - 1 ) ; return ( r + x ) ; } } else { if ( x % 2 == 0 ) { r = x * x ; return ( r - y + 1 ) ; } else { r = ( x - 1 ) * ( x - 1 ) ; return ( r + y ) ; } } } var x = 2 , y = 3 ; document . write ( SpiralElement ( x , y ) ) ;
Make the string in AP by changing a character | Function to modify the given string and find the index where modification is needed ; Array to store the ASCII values of alphabets ; loop to compute the ASCII values of characters a - z ; Set to store all the possible differences between consecutive elements ; Loop to find out the differences between consecutive elements and storing them in the set ; Checks if any character of the string disobeys the pattern ; Constructing the strings with all possible values of consecutive difference and comparing them with staring string S . ; Driver Code
function string_modify ( s ) { var alphabets = Array ( 26 ) . fill ( 0 ) ; var flag = 0 , hold_i ; var hold_l ; var i ; for ( i = 0 ; i < 26 ; i ++ ) { alphabets [ i ] = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; } var difference = new Set ( ) ; var reconstruct = " " ; for ( var i = 1 ; i < s . length ; i ++ ) { difference . add ( s [ i ] . charCodeAt ( 0 ) - s [ i - 1 ] . charCodeAt ( 0 ) ) ; } if ( difference . size == 1 ) { document . write ( " " ) ; return ; } [ ... difference ] . sort ( ( a , b ) => a - b ) . forEach ( it => { if ( flag != 1 ) { var index = s [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; reconstruct = " " ; flag = 0 ; for ( var i = 0 ; i < s . length && flag <= 1 ; i ++ ) { reconstruct += alphabets [ index ] ; index += it ; if ( index < 0 ) { index += 26 ; } index %= 26 ; if ( reconstruct [ i ] != s [ i ] ) { flag ++ ; hold_i = i ; hold_l = s [ i ] ; } } if ( flag == 1 ) { s [ hold_i ] = reconstruct [ hold_i ] ; } } } ) ; if ( flag > 1 ) { hold_i = 0 ; hold_l = s [ 0 ] ; var temp = ( s [ 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) - ( s [ 2 ] . charCodeAt ( 0 ) - s [ 1 ] . charCodeAt ( 0 ) ) ) % 26 ; if ( temp < 0 ) { temp += 26 ; } s [ 0 ] = alphabets [ temp ] ; } document . write ( hold_i + " " + hold_l + " " + s . join ( ' ' ) + " " ) ; } var s = " " ; string_modify ( s . split ( ' ' ) ) ;
Create matrix whose sum of diagonals in each sub matrix is even | Function to print N * N order matrix with all sub - matrix of even order is sum of its diagonal also even ; Even index ; Odd index ; Iterate two nested loop ; For even index the element should be consecutive odd ; For odd index the element should be consecutive even ; Given order of matrix ; Function call
function evenSubMatrix ( N ) { let even = 1 ; let odd = 2 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( ( i + j ) % 2 == 0 ) { document . write ( even + " " ) ; even += 2 ; } else { document . write ( odd + " " ) ; odd += 2 ; } } document . write ( " " ) ; } } let N = 4 ; evenSubMatrix ( N ) ;
Remove leading zeros from a Number given as a string | Function to remove all leading zeros from a a given string ; Regex to remove leading zeros from a string ; Replaces the matched value with given string ; Driver Code
function removeLeadingZeros ( str ) { const regex = new RegExp ( " " , ' ' ) ; str = str . replaceAll ( regex , " " ) ; document . write ( str ) ; } let str = " " ; removeLeadingZeros ( str ) ;
Maximum inversions in a sequence of 1 to N after performing given operations at most K times | Function which computes the maximum number of inversions ; ' answer ' will store the required number of inversions ; We do this because we will never require more than floor ( n / 2 ) operations ; left pointer in the array ; right pointer in the array ; Doing k operations ; Incrementing ans by number of inversions increase due to this swapping ; Input 1 ; Input 2
function maximum_inversion ( n , k ) { var answer = 0 ; k = Math . min ( k , parseInt ( n / 2 ) ) ; var left = 1 ; var right = n ; while ( k > 0 ) { k -- ; answer += 2 * ( right - left ) - 1 ; left ++ ; right -- ; } document . write ( answer + " " ) ; } var N = 5 ; var K = 3 ; maximum_inversion ( N , K ) ; N = 4 ; K = 1 ; maximum_inversion ( N , K ) ;
First number to leave an odd remainder after repetitive division by 2 | Function to return the position least significant set bit ; Function return the first number to be converted to an odd integer ; Stores the positions of the first set bit ; If both are same ; If A has the least significant set bit ; Otherwise ; Driver Code
function getFirstSetBitPos ( n ) { return ( Math . log ( n & - n ) / Math . log ( 2 ) ) ; } function oddFirst ( a , b ) { let steps_a = getFirstSetBitPos ( a ) ; let steps_b = getFirstSetBitPos ( b ) ; if ( steps_a == steps_b ) { return - 1 ; } else if ( steps_a > steps_b ) { return b ; } else { return a ; } } let a = 10 ; let b = 8 ; document . write ( oddFirst ( a , b ) ) ;
Represent K as sum of N | Array to store the N - Bonacci series ; Function to express K as sum of several N_bonacci numbers ; Driver code
let N_bonacci = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { N_bonacci [ i ] = 0 ; } function N_bonacci_nums ( n , k ) { N_bonacci [ 0 ] = 1 ; for ( let i = 1 ; i <= 50 ; ++ i ) { for ( let j = i - 1 ; j >= i - k && j >= 0 ; -- j ) N_bonacci [ i ] += N_bonacci [ j ] ; } let ans = [ ] ; for ( let i = 50 ; i >= 0 ; -- i ) if ( n - N_bonacci [ i ] >= 0 ) { ans . push ( N_bonacci [ i ] ) ; n -= N_bonacci [ i ] ; } if ( ans . length == 1 ) ans . push ( 0 ) ; document . write ( ans . length + " " ) ; for ( let i = 0 ; i < ans . length ; ++ i ) document . write ( ans [ i ] + " " ) ; } let n = 21 , k = 5 ; N_bonacci_nums ( n , k ) ;
Bitonic string | Function to check if the given string is bitonic ; Check for increasing sequence ; If end of string has been reached ; Check for decreasing sequence ; If the end of string hasn 't  been reached ; Return true if bitonic ; Given string ; Function Call
function checkBitonic ( s ) { var i , j ; for ( i = 1 ; i < s . length ; i ++ ) { if ( s [ i ] > s [ i - 1 ] ) continue ; if ( s [ i ] <= s [ i - 1 ] ) break ; } if ( i == s . length - 1 ) return 1 ; for ( j = i + 1 ; j < s . length ; j ++ ) { if ( s [ j ] < s [ j - 1 ] ) continue ; if ( s [ j ] >= s [ j - 1 ] ) break ; } i = j ; if ( i != s . length ) return 0 ; return 1 ; } var s = " " ; ( checkBitonic ( s ) == 1 ) ? document . write ( " " ) : document . write ( " " ) ;
Find pair with maximum GCD for integers in range 2 to N | Function to find the required pair whose GCD is maximum ; If N is even ; If N is odd ; Driver Code
function solve ( N ) { if ( N % 2 == 0 ) { document . write ( N / 2 + " " + N + " " ) ; } else { document . write ( ( N - 1 ) / 2 + " " + ( N - 1 ) + " " ) ; } } var N = 10 ; solve ( N ) ;
Find initial sequence that produces a given Array by cyclic increments upto index P | Function to generate and return the required initial arrangement ; Store the minimum element in the array ; Store the number of increments ; Subtract mi - 1 from every index ; Start from the last index which had been incremented ; Stores the index chosen to distribute its element ; Traverse the array cyclically and find the index whose element was distributed ; If any index has its value reduced to 0 ; Index whose element was distributed ; Store the number of increments at the starting index ; Print the original array ; Driver Code
function findArray ( a , n , P ) { let mi = Math . min ( ... a ) ; let ctr = 0 ; mi = Math . max ( 0 , mi - 1 ) ; for ( let i = 0 ; i < n ; i ++ ) { a [ i ] -= mi ; ctr += mi ; } let i = P - 1 ; let start = - 1 ; while ( true ) { if ( a [ i ] == 0 ) { start = i ; break ; } a [ i ] -= 1 ; ctr += 1 ; i = ( i - 1 + n ) % n ; } a [ start ] = ctr ; for ( i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } } let N = 5 ; let P = 2 ; let arr = [ 3 , 2 , 0 , 2 , 7 ] ; findArray ( arr , N , P ) ;
Generate a unique Array of length N with sum of all subarrays divisible by N | Function to print the required array ; Print the array ; Driver code
function makeArray ( n ) { for ( var i = 1 ; i <= n ; i ++ ) document . write ( i * n + " " ) ; } var N = 6 ; makeArray ( N ) ;
Find elements in a given range having at least one odd divisor | Function to prints all numbers with at least one odd divisor ; Check if the number is not a power of two ; Driver code
function printOddFactorNumber ( n , m ) { for ( let i = n ; i <= m ; i ++ ) { if ( ( i > 0 ) && ( ( i & ( i - 1 ) ) != 0 ) ) document . write ( i + " " ) ; } return 0 ; } let N = 2 , M = 10 ; printOddFactorNumber ( N , M ) ;
Print the first N terms of the series 6 , 28 , 66 , 120 , 190 , 276 , ... | Function to print the series ; Initialise the value of k with 2 ; Iterate from 1 to n ; Print each number ; Increment the value of K by 2 for next number ; Given number N ; Function Call
function printSeries ( n ) { let k = 2 ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( ( k * ( 2 * k - 1 ) ) + " " ) ; k += 2 ; } document . writeln ( " " ) ; } let N = 12 ; printSeries ( N ) ;
Build a DFA to accept Binary strings that starts or ends with "01" | Function for transition state A ; State transition to B if the character is 0 ; State transition to D if the character is 1 ; Function for transition state B ; Check if the string has ended ; State transition to C if the character is 1 ; State transition to D if the character is 0 ; Function for transition state C ; Function for transition state D ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Function for transition state E ; State transition to E if the character is 0 ; State transition to F if the character is 1 ; Function for transition state F ; State transition to D if the character is 1 ; State transition to E if the character is 0 ; Driver Code
function checkstateA ( n ) { if ( n [ 0 ] == ' ' ) stateB ( n . substr ( 1 ) ) ; else stateD ( n . substr ( 1 ) ) ; } function stateB ( n ) { if ( n . length == 0 ) { document . write ( " " ) ; } else { if ( n [ 0 ] == ' ' ) stateC ( n . substr ( 1 ) ) ; else stateD ( n . substr ( 1 ) ) ; } } function stateC ( n ) { document . write ( " " ) ; } function stateD ( n ) { if ( n . length == 0 ) Console . Write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateD ( n . substr ( 1 ) ) ; else stateE ( n . substr ( 1 ) ) ; } } function stateE ( n ) { if ( n . length == 0 ) document . write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateE ( n . substr ( 1 ) ) ; else stateF ( n . substr ( 1 ) ) ; } } function stateF ( n ) { if ( n . length == 0 ) document . write ( " " ) ; else { if ( n [ 0 ] == ' ' ) stateD ( n . substr ( 1 ) ) ; else stateE ( n . substr ( 1 ) ) ; } } let n = " " ; checkstateA ( n ) ;
Find the Nth Hogben Numbers | Function returns N - th Hogben Number ; Driver Code
function HogbenNumber ( a ) { let p = ( Math . pow ( a , 2 ) - a + 1 ) ; return p ; } let N = 10 ; document . write ( HogbenNumber ( N ) ) ;
Check if left and right shift of any string results into given string | Function to check string exist or not as per above approach ; Check if any character at position i and i + 2 are not equal then string doesnot exist ; Driver code
function check_string_exist ( S ) { var size = S . length ; var check = true ; for ( var i = 0 ; i < size ; i ++ ) { if ( S [ i ] != S [ ( i + 2 ) % size ] ) { check = false ; break ; } } if ( check ) document . write ( " " ) ; else document . write ( " " ) ; } var S = " " ; check_string_exist ( S ) ;
Cumulative product of digits of all numbers in the given range | Function to get product of digits ; Function to find the product of digits of all natural numbers in range L to R ; Iterate between L to R ; Driver Code
function getProduct ( n ) { var product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = parseInt ( n / 10 ) ; } return product ; } function productinRange ( l , r ) { if ( r - l > 9 ) return 0 ; else { var p = 1 ; for ( var i = l ; i <= r ; i ++ ) p *= getProduct ( i ) ; return p ; } } var l = 11 , r = 15 ; document . write ( productinRange ( l , r ) + " " ) ; l = 1 , r = 15 ; document . write ( productinRange ( l , r ) ) ;
Check whether the string can be printed using same row of qwerty keypad | Function to find the row of the character in the qwerty keypad ; Sets to include the characters from the same row of the qwerty keypad ; Condition to check the row of the current character of the string ; Function to check the characters are from the same row of the qwerty keypad ; Driver code
function checkQwertyRow ( x ) { var first_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var second_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var third_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var fourth_row = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; if ( first_row . includes ( x ) ) { return 1 ; } else if ( second_row . includes ( x ) ) { return 2 ; } else if ( third_row . includes ( x ) ) { return 3 ; } else if ( fourth_row . includes ( x ) ) { return 4 ; } return 0 ; } function checkValidity ( str ) { var x = str [ 0 ] ; var row = checkQwertyRow ( x ) ; for ( var i = 0 ; i < str . length ; i ++ ) { x = str [ i ] ; if ( row !== checkQwertyRow ( x ) ) { return false ; } } return true ; } var str = " " ; if ( checkValidity ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;
Last digit of sum of numbers in the given range in the Fibonacci series | Calculate the sum of the first N Fibonacci numbers using Pisano period ; The first two Fibonacci numbers ; Base case ; Pisano period for % 10 is 60 ; Checking the remainder ; The loop will range from 2 to two terms after the remainder ; Driver Code
function fib ( n ) { var f0 = 0 ; var f1 = 1 ; if ( n == 0 ) return 0 ; if ( n == 1 ) return 1 ; else { var rem = parseInt ( ( n % 60 ) ) ; if ( rem == 0 ) return 0 ; for ( i = 2 ; i < rem + 3 ; i ++ ) { var f = ( f0 + f1 ) % 60 ; f0 = f1 ; f1 = f ; } var s = f1 - 1 ; return s ; } } var m = 10087887 ; var n = 2983097899 ; var Final = parseInt ( Math . abs ( fib ( n ) - fib ( m - 1 ) ) ) ; document . write ( Final % 10 ) ;
Find N values of X1 , X2 , ... Xn such that X1 < X2 < ... < XN and sin ( X1 ) < sin ( X2 ) < ... < sin ( XN ) | Function to print all such Xi s . t . all Xi and sin ( Xi ) are strictly increasing ; Till N becomes zero ; Find the value of sin ( ) using inbuilt function ; Increment by 710 ; Driver Code ; Function Call
function printSinX ( N ) { let Xi = 0 ; let num = 1 ; while ( N -- > 0 ) { document . write ( " " + num + " " + Xi ) ; document . write ( " " + num + " " ) ; document . write ( Math . sin ( Xi ) . toFixed ( 6 ) ) ; document . write ( " " ) ; num += 1 ; Xi += 710 ; } } let N = 5 ; printSinX ( N ) ;