Convert X into Y by repeatedly multiplying X with 2 or appending 1 at the end | Function to check if X can be converted to Y by multiplying X by 2 or appending 1 at the end ; Iterate until Y is at least X ; If Y is even ; If the last digit of Y is 1 ; Otherwise ; Check if X is equal to Y ; Driver Code
function convertXintoY ( X , Y ) { while ( Y > X ) { if ( Y % 2 == 0 ) Y = parseInt ( Y / 2 ) ; else if ( Y % 10 == 1 ) Y = parseInt ( Y /= 10 ) ; else break ; } if ( X == Y ) document . write ( " " ) ; else document . write ( " " ) ; } let X = 100 , Y = 40021 ; convertXintoY ( X , Y ) ;