Skip to content
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

Added all solutions #232

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

# factorial

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


# reverse

def reverse(text):
print("Text:",text)
if len(text) == 1 or not text:
return text

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


# bunny

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


# is_nested_parens


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

return is_nested_parens(parens[1:-1])
33 changes: 30 additions & 3 deletions part-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@
# the appropriate comment.

# search

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

return is_nested_parens(parens[1:-1])


# is_palindrome

def is_palindrome(text):
if len(text) <= 1:
return True
if text[0] == text[-1]:
return is_palindrome(text[1:-1])
return False


# digit_match

def digit_match(x,y):
x=str(x)
y=str(y)
count=0
if len(x) == 0 or len(y) == 0:
return count
if x[-1] == y[-1]:
count += 1
count += digit_match(x[:-1], y[:-1])
elif x[-1] != y[-1]:
count += digit_match(x[:-1], y[:-1])
return count