From e6773616a67adcdb3c3d818f0a9be5d0239fdd86 Mon Sep 17 00:00:00 2001 From: Amir Naghibi Date: Wed, 14 Mar 2018 21:25:03 -0700 Subject: [PATCH 1/6] fixed spelling error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d20244c2a..9b394e001 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ __Properties__ ###### View the algorithm in [action][shell-toptal] -### Time-Compexity Graphs +### Time-Complexity Graphs Comparing the complexity of sorting algorithms (Bubble Sort, Insertion Sort, Selection Sort) From 00a2b903568bfa03fa293e6e178e82fd710ca68a Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Mar 2018 02:48:09 +0100 Subject: [PATCH 2/6] Fix Python 2 syntax error in matrix_chain_order.py --- dynamic_programming/matrix_chain_order.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dynamic_programming/matrix_chain_order.py b/dynamic_programming/matrix_chain_order.py index 839db03d8..011e85755 100644 --- a/dynamic_programming/matrix_chain_order.py +++ b/dynamic_programming/matrix_chain_order.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import sys ''' Dynamic Programming From 705f43ad5b2995071ff370beb9b67b047524b552 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Mar 2018 03:18:18 +0100 Subject: [PATCH 3/6] xrange() was removed in Python 3 in favor of range() @daniel-s-ingram Similar changes needed on Problems 25 and 28 so they can run on Python 3. flake8 testing of https://github.com/TheAlgorithms/Python on Python 3.6.3 $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ ``` ./Project Euler/Problem 10/sol1.py:5:11: F821 undefined name 'xrange' for i in xrange(2, int(sqrt(n))+1): ^ ./Project Euler/Problem 10/sol1.py:17:11: F821 undefined name 'xrange' for i in xrange(3, n, 2): ^ ./Project Euler/Problem 25/sol1.py:10:12: F821 undefined name 'xrange' for i in xrange(2, n+1): ^ ./Project Euler/Problem 28/sol1.py:7:11: F821 undefined name 'xrange' for i in xrange(1, int(ceil(n/2.0))): ^ 4 F821 undefined name 'xrange' ``` --- Project Euler/Problem 10/sol1.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Project Euler/Problem 10/sol1.py b/Project Euler/Problem 10/sol1.py index ca9593afa..eace01a46 100644 --- a/Project Euler/Problem 10/sol1.py +++ b/Project Euler/Problem 10/sol1.py @@ -1,6 +1,12 @@ from __future__ import print_function from math import sqrt +try: + xrange # Python 2 +except NameError: + xrange = range # Python 3 + + def is_prime(n): for i in xrange(2, int(sqrt(n))+1): if n%i == 0: @@ -30,4 +36,4 @@ if __name__ == '__main__': n = int(sys.argv[1]) print(sum_of_primes(n)) except ValueError: - print('Invalid entry - please enter a number.') \ No newline at end of file + print('Invalid entry - please enter a number.') From 0516bde45f15755a4d0014c21e14ef52b894ec98 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Mar 2018 03:25:29 +0100 Subject: [PATCH 4/6] from __future__ import print_function For Python 3 @ltdouthit __print()__ is a function in Python 3 --- Maths/TrapezoidalRule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Maths/TrapezoidalRule.py b/Maths/TrapezoidalRule.py index 2ad857390..52310c1ed 100644 --- a/Maths/TrapezoidalRule.py +++ b/Maths/TrapezoidalRule.py @@ -7,6 +7,7 @@ method 1: "extended trapezoidal rule" ''' +from __future__ import print_function def method_1(boundary, steps): # "extended trapezoidal rule" @@ -39,7 +40,7 @@ def main(): steps = 10.0 #define number of steps or resolution boundary = [a, b] #define boundary of integration y = method_1(boundary, steps) - print 'y = {0}'.format(y) + print('y = {0}'.format(y)) if __name__ == '__main__': main() From 361532279052619e8fb705c7351ae22f8b76c11e Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Mar 2018 03:27:22 +0100 Subject: [PATCH 5/6] from __future__ import print_function for Python 3 @ltdouthit __print()__ is a function in Python 3 --- Maths/SimpsonRule.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Maths/SimpsonRule.py b/Maths/SimpsonRule.py index 51b5ed1e4..ef9da5e55 100644 --- a/Maths/SimpsonRule.py +++ b/Maths/SimpsonRule.py @@ -8,6 +8,8 @@ method 2: "Simpson Rule" ''' +from __future__ import print_function + def method_2(boundary, steps): # "Simpson Rule" From 4fd777e3b42d8c775497f55851b209077a34872e Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Mar 2018 03:28:00 +0100 Subject: [PATCH 6/6] Update SimpsonRule.py --- Maths/SimpsonRule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/SimpsonRule.py b/Maths/SimpsonRule.py index ef9da5e55..091c86c17 100644 --- a/Maths/SimpsonRule.py +++ b/Maths/SimpsonRule.py @@ -43,7 +43,7 @@ def main(): steps = 10.0 #define number of steps or resolution boundary = [a, b] #define boundary of integration y = method_2(boundary, steps) - print 'y = {0}'.format(y) + print('y = {0}'.format(y)) if __name__ == '__main__': main()