From fa2fd3cc8679d7044491c3c173e7ed01a49b2960 Mon Sep 17 00:00:00 2001 From: KerimovEmil Date: Wed, 27 Jun 2018 22:44:56 -0400 Subject: [PATCH 1/4] Adding Python 3 euclidean example --- .../code/python3/euclidean_example.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 chapters/euclidean_algorithm/code/python3/euclidean_example.py diff --git a/chapters/euclidean_algorithm/code/python3/euclidean_example.py b/chapters/euclidean_algorithm/code/python3/euclidean_example.py new file mode 100644 index 000000000..d4993e193 --- /dev/null +++ b/chapters/euclidean_algorithm/code/python3/euclidean_example.py @@ -0,0 +1,28 @@ +# submitted by KerimovEmil +def euclid_mod(a, b): + + a = abs(a) + b = abs(b) + + while b > 0: + a, b = b, a % b + + return a + + +def euclid_sub(a, b): + + a = abs(a) + b = abs(b) + + while a != b: + if a > b: + a = a - b + else: + b = b - a + + return a + + +print(euclid_mod(64 * 67, 64 * 81)) +print(euclid_sub(128 * 12, 128 * 77)) From 652e73592d4883662e59896a9f6f6dbd5526a6e4 Mon Sep 17 00:00:00 2001 From: KerimovEmil Date: Wed, 27 Jun 2018 22:53:15 -0400 Subject: [PATCH 2/4] Adding name to contributor list --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a1ad4161d..2f1f64218 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,3 +5,4 @@ Gathros Jeremie Gillet (- Jie -) Salim Khatib Hitesh C +Emil Kerimov From 46f647892235833c8c6fdd002664e945681facaf Mon Sep 17 00:00:00 2001 From: KerimovEmil Date: Thu, 28 Jun 2018 18:43:05 -0400 Subject: [PATCH 3/4] Addressing code review of removing the extra line after the function name. Not sure what the conclusion of https://github.com/algorithm-archivists/algorithm-archive/issues/141 will be, but it seems like python 3 will be staying. --- chapters/euclidean_algorithm/code/python2/euclidean_example.py | 2 -- chapters/euclidean_algorithm/code/python3/euclidean_example.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/chapters/euclidean_algorithm/code/python2/euclidean_example.py b/chapters/euclidean_algorithm/code/python2/euclidean_example.py index 709e59a77..d41e7d94d 100644 --- a/chapters/euclidean_algorithm/code/python2/euclidean_example.py +++ b/chapters/euclidean_algorithm/code/python2/euclidean_example.py @@ -1,5 +1,4 @@ def euclid_mod(a, b): - a = abs(a) b = abs(b) temp = 0 @@ -12,7 +11,6 @@ def euclid_mod(a, b): return a def euclid_sub(a, b): - a = abs(a) b = abs(b) diff --git a/chapters/euclidean_algorithm/code/python3/euclidean_example.py b/chapters/euclidean_algorithm/code/python3/euclidean_example.py index d4993e193..63e087d62 100644 --- a/chapters/euclidean_algorithm/code/python3/euclidean_example.py +++ b/chapters/euclidean_algorithm/code/python3/euclidean_example.py @@ -1,6 +1,5 @@ # submitted by KerimovEmil def euclid_mod(a, b): - a = abs(a) b = abs(b) @@ -11,7 +10,6 @@ def euclid_mod(a, b): def euclid_sub(a, b): - a = abs(a) b = abs(b) From 944a8f32a0d91cc1588b9b29daf52ea23eb1332a Mon Sep 17 00:00:00 2001 From: KerimovEmil Date: Mon, 2 Jul 2018 13:57:15 -0400 Subject: [PATCH 4/4] Adding python quicksort algorithm --- CONTRIBUTORS.md | 1 + .../code/python3/euclidean_example.py | 26 ----------------- .../quicksort/code/python/quicksort.py | 29 +++++++++++++++++++ .../sorting_searching/quicksort/quick_sort.md | 2 ++ 4 files changed, 32 insertions(+), 26 deletions(-) delete mode 100644 chapters/euclidean_algorithm/code/python3/euclidean_example.py create mode 100644 chapters/sorting_searching/quicksort/code/python/quicksort.py create mode 100644 chapters/sorting_searching/quicksort/quick_sort.md diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 807513539..84a5c7473 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -14,3 +14,4 @@ Unlambder Kjetil Johannessen CDsigma DominikRafacz +KerimovEmil diff --git a/chapters/euclidean_algorithm/code/python3/euclidean_example.py b/chapters/euclidean_algorithm/code/python3/euclidean_example.py deleted file mode 100644 index 63e087d62..000000000 --- a/chapters/euclidean_algorithm/code/python3/euclidean_example.py +++ /dev/null @@ -1,26 +0,0 @@ -# submitted by KerimovEmil -def euclid_mod(a, b): - a = abs(a) - b = abs(b) - - while b > 0: - a, b = b, a % b - - return a - - -def euclid_sub(a, b): - a = abs(a) - b = abs(b) - - while a != b: - if a > b: - a = a - b - else: - b = b - a - - return a - - -print(euclid_mod(64 * 67, 64 * 81)) -print(euclid_sub(128 * 12, 128 * 77)) diff --git a/chapters/sorting_searching/quicksort/code/python/quicksort.py b/chapters/sorting_searching/quicksort/code/python/quicksort.py new file mode 100644 index 000000000..cf1cba37f --- /dev/null +++ b/chapters/sorting_searching/quicksort/code/python/quicksort.py @@ -0,0 +1,29 @@ +# submitted by KerimovEmil +import random + + +def quick_sort(array): + ls_lower = [] + ls_upper = [] + ls_pivot = [] + if len(array) <= 1: + return array + else: + pivot = array[0] # pick any element from array + for i in array: # for each element in array, place in one of 3 lists + if i < pivot: + ls_lower.append(i) + elif i > pivot: + ls_upper.append(i) + else: + ls_pivot.append(i) + ls_lower = quick_sort(ls_lower) + ls_upper = quick_sort(ls_upper) + return ls_lower + ls_pivot + ls_upper + + +if __name__ == '__main__': + a = [random.randint(-100, 100) for _ in range(10)] + print("Before Sorting {}".format(a)) + a = quick_sort(a) + print("After Sorting {}".format(a)) diff --git a/chapters/sorting_searching/quicksort/quick_sort.md b/chapters/sorting_searching/quicksort/quick_sort.md new file mode 100644 index 000000000..fbcfcefb4 --- /dev/null +++ b/chapters/sorting_searching/quicksort/quick_sort.md @@ -0,0 +1,2 @@ +# Quick Sort +# TODO make this file