Commit 4b56ef53 authored by Tim McNamara's avatar Tim McNamara

Add Euclid's algorithm

parent e3e818f4
From [Leslie Lamport: Thinking Above the Code](https://www.youtube.com/watch?v=-4Yp3j_jk8Q&list=PLRGbXv3cTkkB8IeOpeAKUj2XOhBWWd8nP&index=3)
> Computes GCD
>
> - initalize `x` to `M` and `y` to `N`
> - keep subtracting the smaller of `x` and `y` from the larger
> - stop when `x == y`
```python
def gcd(m, n):
"""
>>> gcd(12, 18)
6
"""
x, y = m, n
while x != y:
if x > y:
x = x - y
else:
y = y - x
return x
```
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment