Skip to content

Instantly share code, notes, and snippets.

@OEUG99
Created October 21, 2021 01:07
Show Gist options
  • Save OEUG99/b6ec044996e0ce68af316f98eb9cb02a to your computer and use it in GitHub Desktop.
Save OEUG99/b6ec044996e0ce68af316f98eb9cb02a to your computer and use it in GitHub Desktop.
Using recursion to implement mathematical inductive proofs.
def sum(array):
# Base Case:
if len(array) == 1:
return array[0]
# Inductive Step:
return array[0] + sum(array[1:])
print(sum([1,2,3,4,5]))
def reverse(string):
# Base Case:
if len(string) == 1:
return string[0]
# Inductive Step:
return string[len(string) -1] + reverse(string[:len(string) - 1])
print(reverse('hello world'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment