Last active
August 30, 2016 13:57
-
-
Save arsho/b97bbddeadb923f07ea2b27e48a43a37 to your computer and use it in GitHub Desktop.
Function to return the number of matched position of two same length number using recursion. Bonus: Digit Sum Using recursion. (Used Python 3.5)
This file contains 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 digit_checking(a,b): | |
x = a%10 | |
y = b%10 | |
check_match = 0 | |
if x == y: | |
check_match=1 | |
a = a//10 | |
b = b//10 | |
if (a == 0) or (b == 0): | |
return check_match | |
return check_match+digit_checking(a,b) | |
print(digit_checking(123458,125478)) | |
#output: 4 |
This file contains 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 dig_sum(n): | |
if (n//10 == 0): | |
return n%10 | |
return n%10+dig_sum(n//10) | |
print(dig_sum(12345)) | |
#output: 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment