Created
October 21, 2021 01:07
-
-
Save OEUG99/b6ec044996e0ce68af316f98eb9cb02a to your computer and use it in GitHub Desktop.
Using recursion to implement mathematical inductive proofs.
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 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])) |
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 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