Skip to content
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
28 changes: 25 additions & 3 deletions part-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,39 @@
# the appropriate comment.

# factorial

def factorial(n):
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
if n == 0:
return 1
return n * factorial(n - 1)


# reverse
def reverse(text):

return text[::-1]


# bunny


def bunny(count):
if count < 0:
raise ValueError("Number of bunnies cannot be negative")
if count == 0:
return 0
return 2 + bunny(count - 1)

# is_nested_parens


def is_nested_parens(parens):
count = 0
for ch in parens:
if ch == "(":
count += 1
else:
count -= 1
if count < 0:
return False

return (count == 0)
24 changes: 22 additions & 2 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@

# 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 len(text) <= 1:
return True

if text[0] != text[-1]:
return False

return(is_palindrome(text[1:-1]))


# digit_match


def digit_match(a: int, b: int):
match = 1 if (a % 10) == (b % 10) else 0
if a < 10 or b < 10:
return match
return match + digit_match(a // 10, b // 10)