Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Python 3 euclidean example #138

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions chapters/euclidean_algorithm/code/python3/euclidean_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# submitted by KerimovEmil
def euclid_mod(a, b):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's very usual to start a function with an empty line (at least not according to pep8). Other than that the implemrntation looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do fix this (which I think you should), make sure to change it in the python2-implementation as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make this change in both files.

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))