-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgcd.py
More file actions
24 lines (17 loc) · 689 Bytes
/
gcd.py
File metadata and controls
24 lines (17 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
author: Jacob Egner
date: 2015-07-31
island: ice base
for latest versions of my solutions, see my checkio solution github repo:
https://github.com/jmegner/CheckioPuzzles
'''
import fractions
import functools
def greatest_common_divisor(*args):
return functools.reduce(fractions.gcd, args)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert greatest_common_divisor(6, 4) == 2, "Simple"
assert greatest_common_divisor(2, 4, 8) == 2, "Three arguments"
assert greatest_common_divisor(2, 3, 5, 7, 11) == 1, "Prime numbers"
assert greatest_common_divisor(3, 9, 3, 9) == 3, "Repeating arguments"