Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Created September 25, 2023 12:46
Show Gist options
  • Save RobertTalbert/97f2e7f1a46a2567f54ec98d517e1b9e to your computer and use it in GitHub Desktop.
Save RobertTalbert/97f2e7f1a46a2567f54ec98d517e1b9e to your computer and use it in GitHub Desktop.
# 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