Created
September 25, 2023 12:46
-
-
Save RobertTalbert/97f2e7f1a46a2567f54ec98d517e1b9e to your computer and use it in GitHub Desktop.
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
# Recursive functions for MTH 225 9/25/2023 | |
# Input is a positive integer | |
def A(n): | |
if n == 1: | |
return n | |
else: | |
return n + A(n-1) | |
# Input is a positive integer | |
def B(n): | |
if n == 0: | |
return 1 | |
else: | |
return 2*B(n-1) | |
# Input is a list of integers | |
def C(my_list): | |
if my_list == [ ]: | |
return 0 | |
else: | |
return min(my_list[-1], C(my_list.pop())) | |
# min(a,b) returns the smaller of a and b | |
# my_list[-1] is the last element of my_list | |
# my_list.pop() removes the last element of my_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment