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

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



# reverse
def reverse(text):
if len(text) < 1:
return ""

if len(text) == 1:
return text[0]

return reverse(text[1:]) + text[0]



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

return recurs



# is_nested_parens
def check_val(first, last):
if first == "(":
if last == ")":
return True
return False

def is_nested_parens(parens):
if len(parens) < 1:
return True

if len(parens) % 2 == 1:
return False

if len(parens) == 2:
return check_val(parens[0], parens[-1])

check = check_val(parens[0], parens[-1])
parens = parens[1:-1]

return is_nested_parens(parens)


35 changes: 33 additions & 2 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 len(array) < 1:
return False
if query == array[0]:
return True
array = array[1:]
return search(array, query)


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

if len(text) == 2:
return text[0] == text[-1]

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


# digit_match

def recursive_count(apples, oranges, count):
if len(apples) == 0 or len(oranges) == 0:
return count
if apples[-1] == oranges [-1]:
count += 1
return recursive_count(apples[0:-1], oranges[0:-1], count)

def digit_match(apples, oranges):
apples = str(apples)
oranges = str(oranges)
match_count = recursive_count(apples, oranges, 0)
return match_count


x = digit_match(1072503891, 62530841)
print('ans', x)