Skip to content

Instantly share code, notes, and snippets.

@arsho
Last active August 30, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsho/b97bbddeadb923f07ea2b27e48a43a37 to your computer and use it in GitHub Desktop.
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)
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
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