Skip to content

Commit ce57216

Browse files
Euclidean algorithm moved for general python (version 2/3)
1 parent 15535cb commit ce57216

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

chapters/euclidean_algorithm/code/python2/euclidean_example.py renamed to chapters/euclidean_algorithm/code/python/euclidean_example.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import print_function
2+
3+
14
def euclid_mod(a, b):
25

36
a = abs(a)
@@ -24,6 +27,8 @@ def euclid_sub(a, b):
2427

2528
return a
2629

27-
print euclid_mod(64 * 67, 64 * 81)
28-
print euclid_sub(128 * 12, 128 * 77)
30+
def main():
31+
print(euclid_mod(64 * 67, 64 * 81))
32+
print(euclid_sub(128 * 12, 128 * 77))
2933

34+
main()

chapters/euclidean_algorithm/euclidean.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
1515
[import:20-33, lang="c_cpp"](code/c++/euclidean.cpp)
1616
{% sample lang="js" %}
1717
[import:15-29, lang="javascript"](code/javascript/euclidean_example.js)
18-
{% sample lang="py2" %}
19-
[import:14-25, lang="python"](code/python2/euclidean_example.py)
18+
{% sample lang="py" %}
19+
[import:17-28, lang="python"](code/python/euclidean_example.py)
2020
{% sample lang="haskell" %}
2121
[import:3-11, lang="haskell"](code/haskell/euclidean_example.hs)
2222
{% sample lang="rs" %}
@@ -46,8 +46,8 @@ Modern implementations, though, often use the modulus operator (%) like so
4646
[import:7-17, lang="c_cpp"](code/c++/euclidean.cpp)
4747
{% sample lang="js" %}
4848
[import:1-13, lang="javascript"](code/javascript/euclidean_example.js)
49-
{% sample lang="py2" %}
50-
[import:1-12, lang="python"](code/python2/euclidean_example.py)
49+
{% sample lang="py" %}
50+
[import:4-15, lang="python"](code/python/euclidean_example.py)
5151
{% sample lang="haskell" %}
5252
[import:13-24, lang="haskell"](code/haskell/euclidean_example.hs)
5353
{% sample lang="rs" %}
@@ -89,7 +89,7 @@ Program.cs
8989
[import, lang="javascript"](code/javascript/euclidean_example.js)
9090
{% sample lang="py2" %}
9191
### Python
92-
[import, lang="python"](code/python2/euclidean_example.py)
92+
[import, lang="python"](code/python/euclidean_example.py)
9393
{% sample lang="haskell" %}
9494
### Haskell
9595
[import, lang="haskell"](code/haskell/euclidean_example.hs)

0 commit comments

Comments
 (0)