From fd67b18d6be14b2cd55d2b9704e070373c0cf0e2 Mon Sep 17 00:00:00 2001 From: Jessie Date: Sat, 1 Aug 2020 12:14:53 -0400 Subject: [PATCH 1/5] Sprint Challenge initial commit --- .idea/Sprint-Challenge--Data-Structures-Python.iml | 8 ++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 32 insertions(+) create mode 100644 .idea/Sprint-Challenge--Data-Structures-Python.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/Sprint-Challenge--Data-Structures-Python.iml b/.idea/Sprint-Challenge--Data-Structures-Python.iml new file mode 100644 index 000000000..d0876a78d --- /dev/null +++ b/.idea/Sprint-Challenge--Data-Structures-Python.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..a2e120dcc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..e549fe287 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 636606ca86deb2c8911e998c53cc95fb5d49a0fb Mon Sep 17 00:00:00 2001 From: Jessie Date: Sat, 1 Aug 2020 12:48:01 -0400 Subject: [PATCH 2/5] Ring Buffer passes all tests --- ring_buffer/ring_buffer.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 37e9fb0dd..8d8b6b709 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -1,9 +1,33 @@ class RingBuffer: def __init__(self, capacity): - pass + self.capacity = capacity + self.items = [] + self.counter = 0 def append(self, item): - pass + if len(self.items) == self.capacity: + # for i in range(0, self.capacity): + del self.items[self.counter] + self.items.insert(self.counter, item) + if self.counter == 4: + self.counter = 0 + else: + self.counter += 1 + else: + self.items.append(item) def get(self): - pass \ No newline at end of file + return self.items + +x=RingBuffer(5) +x.append(1); x.append(2); x.append(3); x.append(4) +print(x.get()) +x.append(5) +print(x.get()) +x.append(6) +print(x.get()) +x.append(7); x.append(8); x.append(9); x.append(10) +print(x.get()) +x.append(8); x.append(9); x.append(10); x.append(11); x.append(12) +print(x.get()) + From 515e49ff36b49071484233db5ed775b35f649f22 Mon Sep 17 00:00:00 2001 From: Jessie Date: Sat, 1 Aug 2020 12:48:55 -0400 Subject: [PATCH 3/5] Deleted unnecessary comment in ring buffer --- ring_buffer/ring_buffer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 8d8b6b709..643b1ba34 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -6,7 +6,6 @@ def __init__(self, capacity): def append(self, item): if len(self.items) == self.capacity: - # for i in range(0, self.capacity): del self.items[self.counter] self.items.insert(self.counter, item) if self.counter == 4: From 31883736d74dc8722c668d6be52ab572183e2dad Mon Sep 17 00:00:00 2001 From: Jessie Date: Sat, 1 Aug 2020 13:12:02 -0400 Subject: [PATCH 4/5] Names: optimized runtime from 7.47 seconds to 1.74 seconds --- names/names.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/names/names.py b/names/names.py index ea158997f..2fa4e9f64 100644 --- a/names/names.py +++ b/names/names.py @@ -13,16 +13,21 @@ duplicates = [] # Return the list of duplicates in this data structure # Replace the nested for loops below with your improvements +#def findDuplicates(new_list, list1, list2): +for name in names_1: + if name in names_2: + duplicates.append(name) +""" for name_1 in names_1: for name_2 in names_2: if name_1 == name_2: duplicates.append(name_1) - +""" end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") print (f"runtime: {end_time - start_time} seconds") # ---------- Stretch Goal ----------- # Python has built-in tools that allow for a very efficient approach to this problem -# What's the best time you can accomplish? Thare are no restrictions on techniques or data +# What's the best time you can accomplish? There are no restrictions on techniques or data # structures, but you may not import any additional libraries that you did not write yourself. From 5ff778c4486f4289d6244bfc78b0af76f7b4f3c2 Mon Sep 17 00:00:00 2001 From: Jessie Date: Sat, 1 Aug 2020 13:33:33 -0400 Subject: [PATCH 5/5] Reverse passes all tests --- reverse/reverse.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/reverse/reverse.py b/reverse/reverse.py index 6116252d1..5583a3a56 100644 --- a/reverse/reverse.py +++ b/reverse/reverse.py @@ -39,4 +39,16 @@ def contains(self, value): return False def reverse_list(self, node, prev): - pass + if not self.head and not prev: + return None + else: + next = node.next_node + + while node: + node.next_node = prev + prev = node + node = next + if next: + next = next.next_node + + self.head = prev