Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint Challenge #419

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +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.
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.
40 changes: 40 additions & 0 deletions names/name_tree.py
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions names/names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from name_tree import BSTNode

start_time = time.time()

Expand All @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 28 additions & 4 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
class RingBuffer:
def __init__(self, capacity):
pass

self.q = list()
self.capacity = capacity
self.head = 0
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
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
return self.q