diff --git a/.vscode/settings.json b/.vscode/settings.json index f1dc380..e69de29 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +0,0 @@ -{ - "files.associations": { - "iosfwd": "cpp", - "__node_handle": "cpp" - } - "python.pythonPath": "C:\\Users\\9dayl\\AppData\\Local\\Programs\\Python\\Python37\\python.exe" -} \ No newline at end of file diff --git a/week-4/Python/main.py b/week-4/Python/main.py index e69de29..2bb850a 100644 --- a/week-4/Python/main.py +++ b/week-4/Python/main.py @@ -0,0 +1,45 @@ +from collections import deque + + +def sum_lists(): + #I dont know how we were supposed to input the #'s but + # I'd just use a standard iterative input loop until None + ll1=deque([5,6,3]) + ll2=deque([8,4,2]) + + #used to represent the tens place + multi=1 + total=0 + #this makes multiplying easy since I can start at the + #ones place + ll1.reverse() + for num in ll1: + total+=num*multi + multi*=10 + + #Repeats the same process + multi=1 + ll2.reverse() + + for num in ll2: + total+=num*multi + multi*=10 + print(total) + +def words_reverse(): + s=deque(["I"," ","l","o","v","e"," ","g","e","e","k","s"," ","f","o","r"," ","g","e","e","k","s"]) + templist="" + #check to see if it's one word + if " " not in s: + print(s) + else: + #copy deque using a string, then split by spaces + for i in s: + templist+=i + templist=templist.split(" ") + + #return split version to s, then reverse it + s=deque(templist) + s.reverse() + print(s) + diff --git a/week-6/Python/daylen-robertson.py b/week-6/Python/daylen-robertson.py new file mode 100644 index 0000000..2849a37 --- /dev/null +++ b/week-6/Python/daylen-robertson.py @@ -0,0 +1,91 @@ +import binarytree +from binarytree import Node, build + + +#Creates a mirror of the tree +def mirror(): + #Pass in any values to create a tree + values = [7, 3, 2, 6, 9, 1, 5, 8] + if len(values)==1: + print(values) + elif len(values)==0: + print("None") + else: + tree1=build(values) + + for i in range(len(tree1)): + try: + temp=tree1[i].left + tree1[i].left=tree1[i].right + tree1[i].right=temp + except: + print("no index") + + print(tree1) + + + + + +#By alternating, we're able to go down the path where the leaf is +def make_branches(leaf,branches,branchess): + + for num in range(len(tree1)): + if leaves[leaf] in tree1[num].left: + #adds to branch + branches.append(tree1[num].left) + #checks if we're done with this branch + if tree1[num].left==leaves[leaf]: + branchess.append(branches) + branches=[] + break + elif leaves[leaf] in tree1[num].right: + branches.append(tree1[num].right) + if tree1[num].right==leaves[leaf]: + branchess.append(branches) + branches=[] + break + +#This runs the code that recursively creates root to leaf branches +#Pass in any values you'd like +values = [7, 3, 2, 6, 9, 1, 5, 8] +if len(values)==1: + print(values) +elif len(values)==0: + print("None") +else: + tree1=build(values) + branchess=[] + branch=list(tree1) + leaves=tree1.leaves + for leaf in range(len(leaves)): + branches=[tree1[0]] + make_branches(leaf,branches,branchess) + print(branchess) + + +#MUST RUN BRANCH CREATION FUNCTION FIRST +#finds max difference between node and differences +def max_diff(branchess): + branchess.extend((list(tree1),list(tree1.left),list(tree1.right))) + + newBranch=[] + newBranches=[] + #This is to get rid of the new lines and help us retrieve the numeric representation of the nodes + for branch in branchess: + branch=str(branch).strip('\n') + for i in list(branch): + if i.isnumeric(): + newBranch.append(int(i)) + newBranches.append(newBranch) + newBranch=[] + + print(newBranches) + maxDiff=0 + + #this is to compare the differences between each node and it's decendants + for branchDiff in newBranches: + + if maxDiff<(max(branchDiff)-min(branchDiff)): + maxDiff=(max(branchDiff)-min(branchDiff)) + print(maxDiff) \ No newline at end of file diff --git a/week-8/Python/daylen-robertson.py b/week-8/Python/daylen-robertson.py new file mode 100644 index 0000000..c7b8184 --- /dev/null +++ b/week-8/Python/daylen-robertson.py @@ -0,0 +1,46 @@ + +def stone_love(): + from bisect import bisect_left + #On hacker earth the first test case is incorrect bc their output doesn't make sense with the input. + #I could be wrong though, if so, I have code that will run for that too, just a simple nested for loop + #The loop uses a dictionary with # stone keys and day values and checks if the value is >= Q + #That was time inefficient though + num=input().split() + n=int(num[0]) + qq=int(num[1]) + numStone=input().split() + qStones=input().split() + + + + total=0 + array=[] + for j in numStone: + total+=int(j) + array.append(total) + + for q in qStones: + print(bisect_left(array,int(q))+1) + + +def repeated_k_times(): + n=int(input()) + array=input().split() + array.sort() + arrayset=set(array) + arrayset=sorted(arrayset) + dic=dict.fromkeys(arrayset) + + + k=int(input()) + + #sets values to 0 + for i in dic: + dic[i]=0 + + #When it equals k, print # + for i in array: + dic[i]+=1 + if int(dic[i])==k: + print (i) + break \ No newline at end of file diff --git a/week-8/Python/main.py b/week-8/Python/main.py deleted file mode 100644 index e69de29..0000000