From a3d2220f002049a239aa51f7f6e17a91a5db353f Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 13:53:09 -0500 Subject: [PATCH 1/7] Initial Commit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7468701de..4f4d14b83 100644 --- a/README.md +++ b/README.md @@ -96,3 +96,4 @@ While credit will be given for a functional solution, only optimal solutions wil #### 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 **at least 2** for all items on the rubric. + \ No newline at end of file From 474c91d5ce1daabd566cb2000701bd2a00a1bcb7 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 14:14:35 -0500 Subject: [PATCH 2/7] Ring buffer initilizer --- README.md | 3 +-- ring_buffer/ring_buffer.py | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4f4d14b83..004ebcffa 100644 --- a/README.md +++ b/README.md @@ -95,5 +95,4 @@ While credit will be given for a functional solution, only optimal solutions wil #### 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 **at least 2** for all items on the rubric. - \ No newline at end of file +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 **at least 2** for all items on the rubric. \ No newline at end of file diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 37e9fb0dd..ab47af8a2 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -1,7 +1,11 @@ class RingBuffer: def __init__(self, capacity): - pass - + self.q = list() + self.capacity = capacity + self.head = 0 + self.tail = 0 + self.index = 0 + def append(self, item): pass From 991e714a55d9e7b171fc5b777852584d086e5c17 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 14:16:10 -0500 Subject: [PATCH 3/7] Ring buffer Methods --- ring_buffer/ring_buffer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index ab47af8a2..6e6557324 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -6,6 +6,21 @@ def __init__(self, capacity): self.tail = 0 self.index = 0 + def iterate_head(self): + if self.head >= self.capacity -1: + self.head = 0 + else: + self.head += 1 + + def iterate_tail(self): + if self.tail >= self.capacity -1: + self.tail = 0 + else: + self.tail += 1 + + def size(self): + return len(self.q) + def append(self, item): pass From ebc1e8e59211aa05411ac8550c88f286edf2f2b4 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 14:20:00 -0500 Subject: [PATCH 4/7] Finished the ammend and get methods Seem to pass test with 0 errors --- ring_buffer/ring_buffer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 6e6557324..40f687465 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -22,7 +22,12 @@ def size(self): return len(self.q) def append(self, item): - pass + if self.size() == self.capacity: + self.q[self.tail] = item + self.iterate_tail() + else: + self.q.append(item) + self.iterate_tail() def get(self): - pass \ No newline at end of file + return self.q \ No newline at end of file From 4bc56e9d9a9f1a4c150b2dd20f23a89ada48b282 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 16:44:37 -0500 Subject: [PATCH 5/7] Names Created name tree file and implemented a bstnode classs along with needed methods. In the names file i replaced the nested loop with my improvement. Runs in under a second --- names/name_tree.py | 40 ++++++++++++++++++++++++++++++++++++++++ names/names.py | 12 ++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 names/name_tree.py diff --git a/names/name_tree.py b/names/name_tree.py new file mode 100644 index 000000000..c43e62715 --- /dev/null +++ b/names/name_tree.py @@ -0,0 +1,40 @@ +class BSTNode: + def __init__(self, value): + self.value = value + self.left = None + self.right = None + + def __str__(self): + if self.left and self.right: + return(f"Node: {self.value}, Left: {Self.right}, Right: {self.right}") + elif self.left is not None and self.right is None: + return(f"Node: {self.value}, Left: {self.left}, Right: None") + elif self.left is None and self.right is not None: + return(f"Node: {self.value}, Left: None, Right: {self.right}") + + def insert(self, value): + if value >= self.value: + if self.right: + self.right.insert(value) + else: + self.right = BSTNode(value) + else: + if self.left: + self.left.insert(value) + else: + self.left = BSTNode(value) + + def contains(self, target): + if target == self.value: + return True + elif target > self.value: + if self.right: + return self.right.contains(target) + else: + return False + else: + if self.left: + return self.left.contains(target) + else: + return False + \ No newline at end of file diff --git a/names/names.py b/names/names.py index ea158997f..b4c8d3853 100644 --- a/names/names.py +++ b/names/names.py @@ -1,4 +1,5 @@ import time +from name_tree import BSTNode start_time = time.time() @@ -13,10 +14,21 @@ duplicates = [] # Return the list of duplicates in this data structure # Replace the nested for loops below with your improvements +""" for name_1 in names_1: for name_2 in names_2: if name_1 == name_2: duplicates.append(name_1) +""" + +root = BSTNode(names_1[0]) +for i in range(1, (len(names_1) - 1)): + root.insert(names_1[i]) + +for name in names_2: + if root.contains(name): + duplicates.append(name) + end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") From 86717d201380f526b0cc7662ce7fc73ebbbb5a69 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Sat, 26 Sep 2020 16:51:14 -0500 Subject: [PATCH 6/7] Completed reverse method Test ran with zero failures --- reverse/reverse.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/reverse/reverse.py b/reverse/reverse.py index 6116252d1..415e5efc2 100644 --- a/reverse/reverse.py +++ b/reverse/reverse.py @@ -39,4 +39,13 @@ def contains(self, value): return False def reverse_list(self, node, prev): - pass + if self.head is None or self.head.next_node is None: + return + prev = None + current = self.head + while current: + next_element = current.next_node + current.next_node = prev + prev = current + current = next_element + self.head = prev \ No newline at end of file From c6f8bf2753f7ba7f7822d6550dc34c61a2d4c8a4 Mon Sep 17 00:00:00 2001 From: Alex Thompson Date: Mon, 28 Sep 2020 23:14:49 -0500 Subject: [PATCH 7/7] updated mis spell --- names/name_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/names/name_tree.py b/names/name_tree.py index c43e62715..64e43e121 100644 --- a/names/name_tree.py +++ b/names/name_tree.py @@ -6,7 +6,7 @@ def __init__(self, value): def __str__(self): if self.left and self.right: - return(f"Node: {self.value}, Left: {Self.right}, Right: {self.right}") + return(f"Node: {self.value}, Left: {self.right}, Right: {self.right}") elif self.left is not None and self.right is None: return(f"Node: {self.value}, Left: {self.left}, Right: None") elif self.left is None and self.right is not None: