Find Nth even length palindromic number formed using digits X and Y | Utility function to compute n 'th palindrome number ; Calculate the length from above formula as discussed above ; Calculate rank for length L ; Mask to check if i 't bit  is set or not ; If bit is set append '5' else append '4' ; Driver Code
function solve ( n , x , y ) { var length = Math . ceil ( Math . log2 ( n + 2 ) ) - 1 ; var rank = n - ( 1 << length ) + 1 ; var left = " " , right = " " ; for ( var i = length - 1 ; i >= 0 ; i -- ) { var mask = 1 << i ; var bit = mask & rank ; if ( bit ) { left += y ; right += y ; } else { left += x ; right += x ; } } right = right . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; return left + right ; } var n = 23 ; var x = ' ' , y = ' ' ; var ans = solve ( n , x , y ) ; document . write ( ans + " " ) ;