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

euclidean_gcd: Add recursive euclidean #1

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 0 additions & 20 deletions Euclidean GCD/Python/euclidean_gcd.py

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository contains examples of various algorithms written on different pro

| Algorithm | C | CPP | Java | Python |
|:----------------------------------------------------------------------------------------------- |:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|
| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | | | | [:octocat:](Euclidean%20GCD/Python) |
| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | | | | [:octocat:](euclidean_gcd/Python) |


## Implemented Data Structures
Expand Down
36 changes: 36 additions & 0 deletions euclidean_gcd/Python/euclidean_gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def euclidean_gcd(first, second):
"""
Calculates GCD of two numbers using the division-based Euclidean Algorithm
:param first: First number
:param second: Second number
"""
while(second):
first, second = second, first % second
return first


def euclidean_gcd_recursive(first, second):
"""
Calculates GCD of two numbers using the recursive Euclidean Algorithm
:param first: First number
:param second: Second number
"""
if not second:
return first
return euclidean_gcd_recursive(second, first % second)


def main():
first, second = map(int, input('Enter 2 integers: ').split())
print('Division-based: GCD of {} and {} is: {}'.format(first,
second,
euclidean_gcd(
first, second)))
print('Recursive: GCD of {} and {} is: {}'.format(first,
second,
euclidean_gcd_recursive(
first, second)))


if __name__ == '__main__':
main()