From 32679d710b1d0c80cf9fd9708d30e5d5bf1f5efe Mon Sep 17 00:00:00 2001 From: VINCENT ADENIJI <54925113+TOSINNIJIS1@users.noreply.github.com> Date: Sat, 10 Oct 2020 02:17:41 -0400 Subject: [PATCH] mvp --- Short-Answer/Algorithms_Answers.md | 7 +++---- Short-Answer/Algorithms_Questions.md | 4 ++++ recursive_count_th/count_th.py | 9 ++++++++- robot_sort/robot_sort.py | 17 ++++++++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index b276aca1b..d5eee0051 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -2,13 +2,12 @@ ## Exercise I -a) +a) Linear -b) +b) The iteration increase the time - -c) +c) no looping since it's only called once ## Exercise II diff --git a/Short-Answer/Algorithms_Questions.md b/Short-Answer/Algorithms_Questions.md index 46f444535..a1e13468d 100644 --- a/Short-Answer/Algorithms_Questions.md +++ b/Short-Answer/Algorithms_Questions.md @@ -11,6 +11,8 @@ a) a = 0 a = a + n * n ``` +it's a single while loop so it 0(n) + ``` b) sum = 0 @@ -20,6 +22,7 @@ b) sum = 0 j *= 2 sum += 1 ``` +This is a nested loop 0(n^2) ``` c) def bunnyEars(bunnies): @@ -28,6 +31,7 @@ c) def bunnyEars(bunnies): return 2 + bunnyEars(bunnies-1) ``` +0(n) it's a recursion. ## Exercise II diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..775669afe 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -4,7 +4,14 @@ Your function must utilize recursion. It cannot contain any loops. ''' def count_th(word): + if not word: + return 0 + elif word[:2] == 'th': + return 1 + count_th(word[2:]) + else: + return count_th(word[1:]) + # TBC - pass + # pass diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..8e779b04b 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -97,7 +97,22 @@ def sort(self): Sort the robot's list. """ # Fill this out - pass + if self.can_move_right() == False: + return + + self.swap_item() + + while self.can_move_right(): + self.move_right() + if self.compare_item() == 1: + self.swap_item() + + while self.compare_item() is not None: + self.move_left() + + self.swap_item() + self.move_right() + self.sort() if __name__ == "__main__":