From 84b40406d5ee1087d31ce49cac6cf18ff29cf135 Mon Sep 17 00:00:00 2001 From: wmboyles <40878829+wmboyles@users.noreply.github.com> Date: Thu, 5 Jul 2018 23:52:04 -0400 Subject: [PATCH 01/11] Create jarvits.py Added python3 example for Jarvits March. --- .../jarvis_march/code/py/jarvits.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py new file mode 100644 index 000000000..d7f34ed10 --- /dev/null +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py @@ -0,0 +1,41 @@ +# Is the turn counter clockwise? +def CCW(p1, p2, p3): + return (p3[1]-p1[1])*(p2[0]-p1[0]) >= (p2[1]-p1[1])*(p3[0]-p1[0]) + + +#Find the leftmost point in the list +def leftmost(S): + leftmost = S[0] + for s in S[1:]: + if s[0] Date: Thu, 5 Jul 2018 23:55:45 -0400 Subject: [PATCH 02/11] Create Python --- .../gift_wrapping/jarvis_march/code/Python | 1 + 1 file changed, 1 insertion(+) create mode 100644 chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python @@ -0,0 +1 @@ + From 1ce66fac7aa0b2a67bc532527e826afe9fcfba67 Mon Sep 17 00:00:00 2001 From: wmboyles <40878829+wmboyles@users.noreply.github.com> Date: Thu, 5 Jul 2018 23:56:18 -0400 Subject: [PATCH 03/11] Delete Python --- .../gift_wrapping/jarvis_march/code/Python | 1 - 1 file changed, 1 deletion(-) delete mode 100644 chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python deleted file mode 100644 index 8b1378917..000000000 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/Python +++ /dev/null @@ -1 +0,0 @@ - From 78db02c041d26f2f5055a2643c3546d4cf955acd Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Fri, 6 Jul 2018 01:04:23 -0400 Subject: [PATCH 04/11] Updates jarvis.py with better variable name --- .../jarvis_march/code/py/jarvits.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py index d7f34ed10..13789f7a6 100644 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py @@ -4,10 +4,10 @@ def CCW(p1, p2, p3): #Find the leftmost point in the list -def leftmost(S): - leftmost = S[0] - for s in S[1:]: - if s[0] Date: Fri, 6 Jul 2018 23:33:19 -0400 Subject: [PATCH 05/11] Update jarvits.py --- .../jarvis_march/code/py/jarvits.py | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py index 13789f7a6..9c0b329ac 100644 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py @@ -3,39 +3,41 @@ def CCW(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0]) >= (p2[1]-p1[1])*(p3[0]-p1[0]) -#Find the leftmost point in the list -def leftmost(gift): - leftmost = gift[0] - for point in gift[1:]: - if point[0] Date: Fri, 6 Jul 2018 23:33:51 -0400 Subject: [PATCH 06/11] Update jarvits.py --- .../gift_wrapping/jarvis_march/code/py/jarvits.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py index 9c0b329ac..68fb929ca 100644 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py @@ -24,7 +24,6 @@ def jarvisMarch(gift): else: hull.append(pointOnHull) - return hull From 8522fe8885bcb3beb17510b570836e48acba1ad6 Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Fri, 6 Jul 2018 23:53:32 -0400 Subject: [PATCH 07/11] Added recursive Euclidean Algorithm --- chapters/euclidean_algorithm/code/python/euclidean_example.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chapters/euclidean_algorithm/code/python/euclidean_example.py b/chapters/euclidean_algorithm/code/python/euclidean_example.py index 3e6d22851..09fb56663 100644 --- a/chapters/euclidean_algorithm/code/python/euclidean_example.py +++ b/chapters/euclidean_algorithm/code/python/euclidean_example.py @@ -21,8 +21,12 @@ def euclid_sub(a, b): return a +def eulid_recur(a,b): + return gcd(b,a%b) if b else a + def main(): print(euclid_mod(64 * 67, 64 * 81)) + print(euclid_recur(58 * 23, 58*19)) print(euclid_sub(128 * 12, 128 * 77)) main() From 1339f92bff0ee3cba2d99fbf615d2c386f253f3f Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Sat, 7 Jul 2018 11:29:24 -0400 Subject: [PATCH 08/11] Update and rename jarvits.py to jarvisMarch.py --- .../code/py/{jarvits.py => jarvisMarch.py} | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) rename chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/{jarvits.py => jarvisMarch.py} (79%) diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvisMarch.py similarity index 79% rename from chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py rename to chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvisMarch.py index 68fb929ca..781f598a1 100644 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvits.py +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/code/py/jarvisMarch.py @@ -6,16 +6,14 @@ def CCW(p1, p2, p3): def jarvisMarch(gift): n = len(gift) #Number of points in list pointOnHull = min(gift) #leftmost point in gift - hull = [pointOnHull] #leftmost point guranteed to be in hull + hull = [pointOnHull] #leftmost point guaranteed to be in hull - i = 0 while True: - endpoint = gift[0] + endpoint = gift[0] #Candidate for next point in hull for j in range(1,n): - if endpoint==pointOnHull or not CCW(gift[j],hull[i],endpoint): + if endpoint==pointOnHull or not CCW(gift[j],hull[-1],endpoint): endpoint = gift[j] - i+=1 pointOnHull = endpoint #Check if we have completely wrapped gift @@ -37,6 +35,4 @@ def main(): for point in hull: print(point) - -if __name__=="__main__": - main() +main() From a3c946386a6710b684092b12f7876173ba88b230 Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Sat, 7 Jul 2018 20:54:07 -0400 Subject: [PATCH 09/11] euclidean_example.py now matches master branch --- .../euclidean_algorithm/code/python/euclidean_example.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/chapters/euclidean_algorithm/code/python/euclidean_example.py b/chapters/euclidean_algorithm/code/python/euclidean_example.py index d2d385b5d..367aed512 100644 --- a/chapters/euclidean_algorithm/code/python/euclidean_example.py +++ b/chapters/euclidean_algorithm/code/python/euclidean_example.py @@ -21,8 +21,6 @@ def euclid_sub(a, b): return a -def main(): - print(euclid_mod(64 * 67, 64 * 81)) - print(euclid_sub(128 * 12, 128 * 77)) - -main() \ No newline at end of file +if __name__=="__main__": + print('Euclidean mod: ', euclid_mod(64 * 67, 64 * 81)) + print('Euclidean sub: ', euclid_sub(128 * 12, 128 * 77)) From 929c0f757a926fc44e31a281955bb8f58e4ee48a Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Sat, 7 Jul 2018 20:55:18 -0400 Subject: [PATCH 10/11] Added my name --- CONTRIBUTORS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e513e8a8d..50199d0d4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -38,3 +38,5 @@ lulucca12
GuyPozner
+William Boyles +
From eed06c637fa34da08f10af8be51c11460f32d62b Mon Sep 17 00:00:00 2001 From: William Boyles <40878829+wmboyles@users.noreply.github.com> Date: Sat, 7 Jul 2018 20:59:12 -0400 Subject: [PATCH 11/11] Added python to .md --- .../gift_wrapping/jarvis_march/jarvis_march.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md b/chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md index dae06205c..62cf086db 100644 --- a/chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md +++ b/chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md @@ -41,6 +41,9 @@ Program.cs {% sample lang="js" %} ### JavaScript [import, lang:"javascript"](code/javascript/jarvis-march.js) +{% sample lang="py" %} +### Python +[import, lang:"python"](code/py/jarvisMarch.py) {% endmethod %}