From ac1fbd0403a13da0f0a72bf3de74ad4066a6c1db Mon Sep 17 00:00:00 2001 From: OliverAbreu Date: Sat, 10 Oct 2020 14:09:19 -0400 Subject: [PATCH 1/6] feat(README.md): Initilizes repo --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1b02ff1d3..27569a9d0 100644 --- a/README.md +++ b/README.md @@ -112,3 +112,4 @@ Uncomment the `test_stretch_times()` test in `test_robot.py`. Can you optimize y ### Passing the Sprint Score ranges for a 1, 2, and 3 are shown in the rubric above. For a student to have _passed_ a sprint challenge, they need to earn an **average of at least 2** for all items on the rubric. + \ No newline at end of file From a00b4936e819d948f6d27bebdab55dd042d661b9 Mon Sep 17 00:00:00 2001 From: AbreuOliver Date: Sat, 10 Oct 2020 14:35:11 -0400 Subject: [PATCH 2/6] feat(Algorithms_Answers.md): Answers questions --- Short-Answer/Algorithms_Answers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index b276aca1b..d25b3ddbb 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -2,13 +2,13 @@ ## Exercise I -a) +a) O(n) - Constant time -b) +b) O(n log n) - Linearithmic time -c) +c) O(n) - Constant time ## Exercise II From 4c43c11d91d3ca358f9e54131b5729c6de3af238 Mon Sep 17 00:00:00 2001 From: AbreuOliver Date: Sat, 10 Oct 2020 15:11:32 -0400 Subject: [PATCH 3/6] feat(Algorithms_Answers.md): Completes --- Short-Answer/Algorithms_Answers.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index d25b3ddbb..6c4584072 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -12,4 +12,17 @@ c) O(n) - Constant time ## Exercise II - +Go to the middle floor of the building by dividing `n` by two: + drop the egg from current floor: + if the egg does not break + go halfway up the building (by adding current floor to total floors (n) and dividing sum by two) + repeat step 2 + if the egg does break + go up one floor + drop the egg from current floor + if the egg breaks + return current floor minus one as `f` + if the egg does not break + go to step 3 + +O(log n) - Logarithmic time From 47b4b9c8e53deb4c7b5e16f005a1a92f8c9280fb Mon Sep 17 00:00:00 2001 From: AbreuOliver Date: Mon, 12 Oct 2020 22:20:02 -0400 Subject: [PATCH 4/6] feat(Algorithms_Answers.md): Completes answers for Exercises I & II --- Short-Answer/Algorithms_Answers.md | 78 +++++++++++++++++++++++++--- Short-Answer/Algorithms_Questions.md | 2 +- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index 6c4584072..826170a2d 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -2,16 +2,82 @@ ## Exercise I -a) O(n) - Constant time +a) O(n) - Linear runtime, in the worst case +
+
+

Original Code

+
+a = 0
+  while (a < n * n * n):    
+    a = a + n * n 
+
+
+
+

Justification

+
+O(1) 
+O(n) 
+O(n) 
+
+
+
-b) O(n log n) - Linearithmic time +b) O(n^2) - Quadratic runtime, in the worst case +
+
+

Original Code

+
+sum = 0
+  for i in range(n):
+    j = 1
+    while j < n:
+      j *= 2
+      sum += 1  
+
+
+
+

Justification

+
+O(1) 
+O(n) 
+O(1) 
+O(n^2) 
+O(2n) 
+O(1) 
+
+
+
-c) O(n) - Constant time +c) O(n) - Linear runtime, in the worst case -## Exercise II +
+
+

Original Code

+
+def bunnyEars(bunnies):
+  if bunnies == 0:
+    return 0
+
+  return 2 + bunnyEars(bunnies-1)
+
+
+
+

Justification

+
+ 
+  
+O(1) 
+O(2 + n) 
+
+
+
+## Exercise II +``` Go to the middle floor of the building by dividing `n` by two: drop the egg from current floor: if the egg does not break @@ -24,5 +90,5 @@ Go to the middle floor of the building by dividing `n` by two: return current floor minus one as `f` if the egg does not break go to step 3 - -O(log n) - Logarithmic time +``` +O(log n) - Logarithmic runtime, in the worst case, because the problem is halved on each pass, making the solution relatively quick to obtain. diff --git a/Short-Answer/Algorithms_Questions.md b/Short-Answer/Algorithms_Questions.md index 46f444535..86885a648 100644 --- a/Short-Answer/Algorithms_Questions.md +++ b/Short-Answer/Algorithms_Questions.md @@ -33,4 +33,4 @@ c) def bunnyEars(bunnies): Suppose that you have an n-story building and plenty of eggs. Suppose also that an egg gets broken if it is thrown off floor f or higher, and doesn't get broken if dropped off a floor less than floor f. Devise a strategy to determine the value of f such that the number of dropped + broken eggs is minimized. -Write out your proposed algorithm in plain English or pseudocode AND give the runtime complexity of your solution. +Write out your proposed algorithm in plain English or pseudocode AND give the runtime complexity of your solution. \ No newline at end of file From c8af6eac89452bd3c75e1e16c7e356c809c722ae Mon Sep 17 00:00:00 2001 From: AbreuOliver Date: Mon, 12 Oct 2020 22:39:23 -0400 Subject: [PATCH 5/6] feat(count_th.py): Completes recursive substring count function --- recursive_count_th/count_th.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..667f5c838 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -4,7 +4,19 @@ Your function must utilize recursion. It cannot contain any loops. ''' def count_th(word): - - # TBC - - pass + + # If the overall length of the input word is less than 2, + # the word can contain no occurences of our substring + if len(word) < 2: + return 0 + + + # If the input word starts with input, add 1 to count, + # and continue to count remaining occurences of substring + elif word[:2] == "th": + return 1 + count_th(word[1:]) + + # Count all occurences of the substring + # starting from the second index + else: + return count_th(word[1:]) \ No newline at end of file From fc09c685295d3b373f2855ffeed34e79b84eb22e Mon Sep 17 00:00:00 2001 From: AbreuOliver Date: Mon, 12 Oct 2020 23:13:34 -0400 Subject: [PATCH 6/6] feat(robot_sort.py): Completes sort function in pseudocode --- robot_sort/robot_sort.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..3023d7b68 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -96,8 +96,23 @@ def sort(self): """ Sort the robot's list. """ - # Fill this out - pass + # if the robot cannot move left or right, + # there is no `list` (there are no items to compare) - make no swap, + # and return 0 + # else if the robot cannot move left, but can move right, begin comparing items and moving right + # [compare next item] if held item's value is `None` compared to item in front of robot ( == `None`), + # swap currently held item with the list item in front + # and move right + # if held item's value is equal to item in front of robot (== 0), + # make no swap, + # and move right + # else if held item's value is less than the item in front of robot (== -1), + # swap currently held item with the list item in front + # and move right + # else, the held item's value must be greater than item in front of robot (== 1) + # make no swap, + # and move right + # or else the robot can move left, but cannot move right, `list` must be already sorted if __name__ == "__main__":