Check if it is possible to reach ( X , Y ) from origin such that in each ith move increment x or y coordinate with 3 ^ i | Function to find whether ( 0 , 0 ) can be reached from ( X , Y ) by decrementing 3 ^ i at each ith step ; Termination Condition ; Otherwise , recursively call by decrementing 3 ^ i at each step ; Driver Code
function canReach ( X , Y , steps ) { if ( X == 0 && Y == 0 ) { return true ; } if ( X < 0 Y < 0 ) { return false ; } return ( canReach ( X - Math . pow ( 3 , steps ) , Y , steps + 1 ) | canReach ( X , Y - Math . pow ( 3 , steps ) , steps + 1 ) ) ; } let X = 10 , Y = 30 ; if ( canReach ( X , Y , 0 ) ) { document . write ( " " ) ; } else document . write ( " " ) ;