Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amethyst - Elaine W. #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions part-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,42 @@

# factorial


def factorial(n):
if n < 0:
raise ValueError

if n == 0:
return 1
else:
sum = n * factorial(n-1)
return sum


# reverse


def reverse(text):
if len(text) == 0:
return text
else:
reverse_text = reverse(text[1:]) + text[0]
return reverse_text

# bunny


def bunny(count):
if count == 0:
return count
else:
return bunny(count - 1) + 2

# is_nested_parens


def is_nested_parens(parens):
if not len(parens):
return True
else:
if parens[0] == "(" and parens[-1] == ")":
parens = is_nested_parens(parens[1:-1])
return parens
else:
return False
27 changes: 25 additions & 2 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,35 @@

# search


def search(array, query):
if not array:
return False
if array[0] == query:
return True
return search(array[1:], query)


# is_palindrome

def is_palindrome(text):
if text == "":
return True
if len(text) == 1:
return True
if text[0] == text[-1]:
return is_palindrome(text[1:-1])
else:
return False


# digit_match


def digit_match(n1, n2):
n1 = str(n1)
n2 = str(n2)

if n1 == "" or n2 == "":
return 0
if n1[-1] == n2[-1]:
return 1 + digit_match(n1[:-1], n2[:-1])
return 0 + digit_match(n1[:-1], n2[:-1])