2021-04-12 22:57:40 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding: utf8
|
|
|
|
|
|
|
|
"""
|
|
|
|
Author: freezed <2160318-free_zed@users.noreply.gitlab.com> 2021-04-13
|
|
|
|
Version: 0.1
|
|
|
|
Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
This is a script following
|
|
|
|
https://gitlab.com/forga/process/fr/embarquement/-/issues/6
|
|
|
|
|
|
|
|
The goal is to build durable python script using standard library
|
2021-04-14 22:15:18 +00:00
|
|
|
|
|
|
|
:Tests:
|
|
|
|
>>> pgcd(561, 357)
|
|
|
|
51
|
2021-04-12 22:57:40 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2021-04-15 22:06:25 +00:00
|
|
|
def pgcd(input_a, input_b):
|
2021-04-12 22:57:40 +00:00
|
|
|
"""
|
|
|
|
This function find the Greatest Common Divisor (PGCD in French)
|
2021-04-15 22:06:25 +00:00
|
|
|
between input_a & input_b
|
2021-04-14 22:15:18 +00:00
|
|
|
|
|
|
|
:Tests:
|
|
|
|
>>> pgcd(561, 357)
|
|
|
|
51
|
|
|
|
>>> pgcd(63, 42)
|
|
|
|
21
|
|
|
|
>>> pgcd(21, 15)
|
|
|
|
3
|
|
|
|
>>> pgcd(910, 42)
|
|
|
|
14
|
2021-04-12 22:57:40 +00:00
|
|
|
"""
|
2021-04-15 22:06:25 +00:00
|
|
|
rest = input_a - input_b
|
|
|
|
check = input_b - rest
|
2021-04-13 21:51:07 +00:00
|
|
|
|
|
|
|
while check != 0:
|
2021-04-15 22:06:25 +00:00
|
|
|
input_a = max(input_b, rest)
|
|
|
|
input_b = min(input_b, rest)
|
|
|
|
rest = input_a - input_b
|
|
|
|
check = max(input_b, rest) - min(input_b, rest)
|
2021-04-13 21:51:07 +00:00
|
|
|
|
|
|
|
print(rest)
|
|
|
|
|
|
|
|
|
2021-04-15 22:06:25 +00:00
|
|
|
if __name__ == "__main__":
|
2021-04-14 22:15:18 +00:00
|
|
|
import doctest
|
2021-04-15 22:06:25 +00:00
|
|
|
|
2021-04-14 22:15:18 +00:00
|
|
|
doctest.testmod()
|