diff --git a/README.md b/README.md index 1b02ff1d3..578a592bd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # Sprint Challenge: Algorithms + +/////////////////////////////////////////////////////////////////////////////////////////// +////////// https://github.com/LambdaSchool/Sprint-Challenge--Algorithms/pull/443 ///////// +/////////////////////////////////////////////////////////////////////////////////////////// + + + 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 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. 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 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__":