Count of N | Function to find count of N - digit numbers with single digit XOR ; Range of numbers ; Calculate XOR of digits ; If XOR <= 9 , then increment count ; Print the count ; Given number ; Function call
function countNums ( N ) { let l = Math . floor ( Math . pow ( 10 , N - 1 ) ) ; let r = Math . floor ( Math . pow ( 10 , N ) ) - 1 ; let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { let xorr = 0 , temp = i ; while ( temp > 0 ) { xorr = xorr ^ ( temp % 10 ) ; temp = Math . floor ( temp / 10 ) ; } if ( xorr <= 9 ) count ++ ; } document . write ( count ) ; } let N = 2 ; countNums ( N ) ;