From 1764c9d70425dd08bb27c3328f0c2814c0049084 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 11 Oct 2020 20:05:51 -0500 Subject: [PATCH 1/4] initial commit --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1b02ff1d3..b8bc7eeae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Sprint Challenge: Algorithms + +//////////////////////////////////////////////////////////////// + + + + In this week's Sprint you explored and implemented some classic algorithmic approaches and used them to solve novel problems. You also implemented some classic and fundamental sorting algorithms and learned how to go about evaluating their respective runtimes and performance. This Sprint Challenge aims to assess your comfort with these topics through exercises that build on the algorithmic intuition you've started to build up. ## Instructions From d283214f1272ce2f9607e2a95a7997ef2c0794a0 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 11 Oct 2020 20:56:02 -0500 Subject: [PATCH 2/4] I have answered all questions, moving onto the code --- README.md | 5 +++-- Short-Answer/Algorithms_Answers.md | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8bc7eeae..578a592bd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Sprint Challenge: Algorithms -//////////////////////////////////////////////////////////////// - +/////////////////////////////////////////////////////////////////////////////////////////// +////////// https://github.com/LambdaSchool/Sprint-Challenge--Algorithms/pull/443 ///////// +/////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index b276aca1b..0ef841620 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -4,12 +4,24 @@ a) +This is a clear example of 0(n), we are utilizing the while loop to add an iterator that executes a sequence of statements this also executes the N times, we understand that it is being multiplied by each iteration. + b) +Clearly another while loop 0(n^2) that is nested , you will notice a curve in runtime as the numbers increase, in order for this to work we need to consider the iteration of inner and outer loops, we can also understand that each loop will produce a new number each time. + + c) +This is clearly and example of BigO 0(n) again, as this is a recursive function it will call itself (N) times. + + ## Exercise II +This is interesting, when thinking on the amount of eggs I would break so I would start on F floor, however, we can use 0(n) and this will allow us to iterate through each floor until an egg breaks. + +We can also assume that we can use a BST if we are looking to limit the numbers of eggs we lose. +I can not think of any quicker way then to use a complexity of 0(log n), this is the way to go to solve this problem. From 5273767e76a4806161b64de101e943f7c763fd58 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 11 Oct 2020 21:30:31 -0500 Subject: [PATCH 3/4] I have finished recursive_count_th all test passed --- recursive_count_th/count_th.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..af903611a 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -3,8 +3,17 @@ Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters. Your function must utilize recursion. It cannot contain any loops. ''' + + def count_th(word): - - # TBC - - pass + count = 0 + + if len(word) < 2: + return 0 + + if word[0] == 't' and word[1] == 'h': + count += 1 + + count += count_th(word[1:]) + + return count From 4beff8fccb916fb23e5a07e02e43a42fcef277cb Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 11 Oct 2020 22:22:41 -0500 Subject: [PATCH 4/4] Finished Meet MVP whew --- robot_sort/robot_sort.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..61b35db7f 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -96,8 +96,27 @@ def sort(self): """ Sort the robot's list. """ - # Fill this out - pass + ## MY SOLUTION STARTS HERE + + self.set_light_on() + while self.light_is_on(): + self.set_light_off() + while self.can_move_right(): + self.swap_item() + self.move_right() + if self.compare_item() == 1: + self.swap_item() + self.move_left() + self.swap_item() + self.move_right() + self.set_light_on() + else: + self.move_left() + self.swap_item() + self.move_right() + while self.can_move_left(): + self.move_left() + if __name__ == "__main__":