Created
April 22, 2020 16:07
-
-
Save chand1012/61d6e09ea391aa1beb51a3263ac83271 to your computer and use it in GitHub Desktop.
Random recursive equal function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool equal(int x, int y) | |
{ | |
if (x == 0 && y == 0) | |
{ | |
return true; | |
} | |
x--; | |
y--; | |
if (x<0 || y<0) | |
{ | |
return false; | |
} | |
return equal(x, y); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def equal(x, y): | |
if x is 0 and y is 0: | |
return True | |
x-=1 | |
y-=1 | |
if x<0 or y<0: | |
return False | |
return equal(x, y) | |
print(f"1 == 1: {equal(1, 1)}") | |
print(f"2 == 2: {equal(2, 2)}") | |
print(f"100 == 99: {equal(100, 99)}") | |
print(f"0 == 0: {equal(0, 0)}") | |
print(f"0 == 1: {equal(0, 1)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment