Two Balls Reachability Game | Recursive function to return gcd of a and b ; Function returns if it 's possible to have X white and Y black balls or not. ; Finding gcd of ( x , y ) and ( a , b ) ; If gcd is same , it 's always  possible to reach (x, y) ; Here it 's never possible  if gcd is not same ; Driver Code
def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT return gcd ( b , a % b ) ; NEW_LINE DEDENT def IsPossible ( a , b , x , y ) : NEW_LINE INDENT final = gcd ( x , y ) ; NEW_LINE initial = gcd ( a , b ) ; NEW_LINE if ( initial == final ) : NEW_LINE INDENT print ( " POSSIBLE " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NOT ▁ POSSIBLE " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = 1 ; B = 2 ; X = 4 ; Y = 11 ; NEW_LINE IsPossible ( A , B , X , Y ) ; NEW_LINE A = 2 ; B = 2 ; X = 3 ; Y = 6 ; NEW_LINE IsPossible ( A , B , X , Y ) ; NEW_LINE DEDENT