Skip to content

Entered Solutions #251

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

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
33 changes: 30 additions & 3 deletions part-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,43 @@

# factorial


def factorial(num):
if num < 0:
raise ValueError
if num == 0:
return 1
return num * factorial(num - 1)

# reverse

def reverse(text):
if len(text) <= 1:
return text
split_text = list(text)
last_letter = split_text.pop()
return last_letter + reverse("".join(split_text))


# bunny


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

# is_nested_parens


def is_nested_parens(parens):
string_length = len(parens)
if not string_length % 2:
if not parens:
return True
elif parens[0] == "(" and parens[-1] == ")":
return is_nested_parens(parens[1:string_length - 1])
else:
return False

else:
return False
32 changes: 29 additions & 3 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,38 @@

# search


def search(array, query):
if len(array):
item = array.pop()

if item == query:
return True
else:
return search(array, query)
else:
return False

# is_palindrome


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

# digit_match


def digit_match(num_1, num_2):
if isinstance(num_1, int):
num_1 = str(num_1)
num_2 = str(num_2)

if len(num_1) == 0 or len(num_2) == 0:
return 0

if num_1[-1] == num_2[-1]:
return 1 + digit_match(num_1[:-1], num_2[:-1])
else:
return digit_match(num_1[:-1], num_2[:-1])