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
25 changes: 20 additions & 5 deletions part-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
# the appropriate comment.

# 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
return reverse(text[1:]) + text[0]


# bunny

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


# is_nested_parens


def is_nested_parens(parens):
if not parens:
return True
if parens[0] + parens[-1] != "()":
return False
return is_nested_parens(parens[1:-1])
26 changes: 23 additions & 3 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@
# the appropriate comment.

# search

def search(array, query):
if not array:
return False
elif 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(n1, n2):
if n1 == 0 and n2 == 0:
return 1
def helper(a, b):
if a == 0 or b == 0:
return 0
if a % 10 == b % 10:
return 1 + helper(a // 10, b // 10)
else:
return helper(a // 10, b // 10)
return helper(n1, n2)