Skip to content

Commit 3621c8e

Browse files
authored
Merge pull request #6 from KingFredrickVI/master
Added Python Example for Euclidean
2 parents 766c1a5 + aaeb3d7 commit 3621c8e

File tree

1 file changed

+31
-0
lines changed
  • chapters/fundamental_algorithms/euclidean_algorithm

1 file changed

+31
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,34 @@ document.write(euclid_sub(128*12, 128*77) + "<br>");
196196
</body>
197197
</html>
198198
```
199+
200+
### Python
201+
202+
```python
203+
204+
# euclidean.py
205+
206+
def euclid_mod(a, b):
207+
208+
temp = 0
209+
210+
while b > 0:
211+
temp = b
212+
b = a % b
213+
a = temp
214+
215+
return a
216+
217+
def euclid_sub(a, b):
218+
219+
while a != b:
220+
if a > b:
221+
a = a - b
222+
else:
223+
b = b - a
224+
225+
return a
226+
227+
print euclid_mod(64 * 67, 64 * 81)
228+
print euclid_sub(128 * 12, 128 * 77)
229+
```

0 commit comments

Comments
 (0)