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

# factorial

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


# reverse

def reverse(text):
if not text:
return ""
if len(text) ==1:
return text
return text[-1]+reverse(text[:-1])


# bunny
def bunny(count):
if count == 1:
return 2
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] == "(" and parens[-1] == ")":
return is_nested_parens(parens[1:-1])
return False


37 changes: 34 additions & 3 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,44 @@
# the appropriate comment.

# search

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


# is_palindrome
def is_palindrome(text):
if not text:
return False
if len(text) ==1:
return True

if text[0] == text[-1]:
return is_palindrome(text[1:-1])
return False



# digit_match


def digit_match(num1, num2):
if num1 == 0 and num2 == 0:
return 1

if num1 == 0 or num2 == 0:
return 0

if (num1 % 10) == (num2 % 10):
match = 1
else:
match = 0

next1 = num1 // 10
next2 = num2 // 10

if next1 == 0 or next2 == 0:
return match

return match + digit_match(next1, next2)