From 9deabe475c28a7547522be62bc263143db9bf721 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Sat, 9 May 2020 14:09:47 -0500 Subject: rearrange homework folders --- OLD/csci4041/hw2prob2.py | 18 ++++++++++++++++++ OLD/csci4041/hw2prob3.py | 34 ++++++++++++++++++++++++++++++++++ OLD/csci4041/hw3prob2.py | 21 +++++++++++++++++++++ OLD/csci4041/mergeSort_py.py | 30 ++++++++++++++++++++++++++++++ OLD/ee2361/Quiz2B.c | 16 ++++++++++++++++ OLD/ee2361/TEST.cpp | 11 +++++++++++ 6 files changed, 130 insertions(+) create mode 100644 OLD/csci4041/hw2prob2.py create mode 100644 OLD/csci4041/hw2prob3.py create mode 100644 OLD/csci4041/hw3prob2.py create mode 100644 OLD/csci4041/mergeSort_py.py create mode 100644 OLD/ee2361/Quiz2B.c create mode 100644 OLD/ee2361/TEST.cpp (limited to 'OLD') diff --git a/OLD/csci4041/hw2prob2.py b/OLD/csci4041/hw2prob2.py new file mode 100644 index 0000000..39e533a --- /dev/null +++ b/OLD/csci4041/hw2prob2.py @@ -0,0 +1,18 @@ + +# Watch the value of K!!! +# - Jeremiah +def making_sets(n, k, e, s): + if k == 0: + print(s) + else: + for e_i in range(e, n + 1): + s = set.union(s, {e_i}) + making_sets(n, k - 1, e_i + 1, s) + s = set.difference(s, {e_i}) + +def make_sets(n, k): + making_sets(n, k, 1, set()) + +make_sets(4,3) +print() +make_sets(6,1) diff --git a/OLD/csci4041/hw2prob3.py b/OLD/csci4041/hw2prob3.py new file mode 100644 index 0000000..cc53704 --- /dev/null +++ b/OLD/csci4041/hw2prob3.py @@ -0,0 +1,34 @@ +def CHILD(i,j): + return 2*i + (j+1) + +def IS_IN_MIN_HEAP(A,e): + return FIND_ELEMENT(A,0,e) +def FIND_ELEMENT(A,i,e): + if A[i] is e: + return True + else: + bool = False + lChild = CHILD(i, 0) + rChild = CHILD(i, 1) + if lChild < len(A) and A[lChild] <= e: + bool = FIND_ELEMENT(A, lChild, e) + if bool is not True and rChild < len(A) and A[rChild] <= e: + bool = FIND_ELEMENT(A, rChild, e) + return bool + +#TEST MIN-HEAP +#Feel free to redefine as much as you want +l = [0, 2, 3, 5, 6, 8, 9] + +#TESTS +print(IS_IN_MIN_HEAP(l, 0)) +print(IS_IN_MIN_HEAP(l, 1)) +print(IS_IN_MIN_HEAP(l, 2)) +print(IS_IN_MIN_HEAP(l, 3)) +print(IS_IN_MIN_HEAP(l, 4)) +print(IS_IN_MIN_HEAP(l, 5)) +print(IS_IN_MIN_HEAP(l, 6)) +print(IS_IN_MIN_HEAP(l, 7)) +print(IS_IN_MIN_HEAP(l, 8)) +print(IS_IN_MIN_HEAP(l, 9)) +print(IS_IN_MIN_HEAP(l, 200)) \ No newline at end of file diff --git a/OLD/csci4041/hw3prob2.py b/OLD/csci4041/hw3prob2.py new file mode 100644 index 0000000..33f36f6 --- /dev/null +++ b/OLD/csci4041/hw3prob2.py @@ -0,0 +1,21 @@ +def ADDYHASHSEARCH(T,k): + i=0 + j=0 + s=1 + m=len(T) + while T[j]!=None and i<=m: + j=(h(k)+i)%m + if T[j] is k: + return j + else: + i=i+s + s=s+2 + return -1 + +def h(k): + return k*2 + +T = [0,None,1,None,2,None,3,None,4] +print(ADDYHASHSEARCH(T,1)) +print(ADDYHASHSEARCH(T,3)) +print(ADDYHASHSEARCH(T,5)) \ No newline at end of file diff --git a/OLD/csci4041/mergeSort_py.py b/OLD/csci4041/mergeSort_py.py new file mode 100644 index 0000000..bc9ae7d --- /dev/null +++ b/OLD/csci4041/mergeSort_py.py @@ -0,0 +1,30 @@ +def head(Q): + return Q[0] +def tail(Q): + return Q[1:] +def mergesort(U): + if U == [] or tail(U) == []: + return U + else: + L = [] + R = [] + while U != [] and tail(U) != []: + L = L+[head(U)] + U = tail(U) + R = R+[head(U)] + U = tail(U) + L = L + U + L = mergesort(L) + R = mergesort(R) + s = [] + while L != [] and R != []: + if head(L) <= head(R): + s = s + [head(L)] + L = tail(L) + else: + s = s + [head(R)] + R = tail(R) + s = s + L + R + return s + +print(mergesort([9,3,7,5,6,4,8,2])) \ No newline at end of file diff --git a/OLD/ee2361/Quiz2B.c b/OLD/ee2361/Quiz2B.c new file mode 100644 index 0000000..9cdcd3c --- /dev/null +++ b/OLD/ee2361/Quiz2B.c @@ -0,0 +1,16 @@ +#include + +int is_odd(int x); //Definition +int main() { + printf("%d", (1 << 4) | (1 << 7)); + printf("\n"); + printf("%d", (10 & 7)); + printf("\n"); + printf("%d", is_odd(512)); + printf("\n"); + printf("%d", is_odd(1023)); + printf("\n"); +} +int is_odd(int x){ //Actual Function + return x & 1; +} \ No newline at end of file diff --git a/OLD/ee2361/TEST.cpp b/OLD/ee2361/TEST.cpp new file mode 100644 index 0000000..b59631c --- /dev/null +++ b/OLD/ee2361/TEST.cpp @@ -0,0 +1,11 @@ +#include +int xorMask(int Byte) { + Byte = Byte ^ 8; + return Byte; +} + +int main() { + int a = xorMask(15); + std::cout << a << std::endl; + return 0; +} \ No newline at end of file -- cgit v1.2.3