Check whether a number has consecutive 0 's in the given base or not | Function to convert N into base K ; Weight of each digit ; Function to check for consecutive 0 ; Flag to check if there are consecutive zero or not ; If there are two consecutive zero then returning False ; We first convert to given base , then check if the converted number has two consecutive 0 s or not ; Driver code
function toK ( N , K ) { let w = 1 ; let s = 0 ; while ( N != 0 ) { let r = N % K ; N = parseInt ( N / K ) ; s = r * w + s ; w *= 10 ; } return s ; } function check ( N ) { let fl = false ; while ( N != 0 ) { let r = N % 10 ; N = parseInt ( N / 10 ) ; if ( fl == true && r == 0 ) return false ; if ( r > 0 ) { fl = false ; continue ; } fl = true ; } return true ; } function hasConsecutiveZeroes ( N , K ) { let z = toK ( N , K ) ; if ( check ( z ) ) document . write ( " " ) ; else document . write ( " " ) ; } let N = 15 ; let K = 8 ; hasConsecutiveZeroes ( N , K ) ;