From e63c05e65d2e4c55719186df30ab24cdb9754239 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 7 Nov 2022 16:58:28 +0200 Subject: Update Python --- gcd.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gcd.py b/gcd.py index 3690ef5..df3baf6 100755 --- a/gcd.py +++ b/gcd.py @@ -5,16 +5,14 @@ import functools def gcd2(a, b): - if b == 0: - return a - else: - return gcd2(b, a % b) + while b != 0: + a, b = b, a % b + return a -def gcdn(ns): - return functools.reduce(gcd2, ns) +def gcdn(nums): + return functools.reduce(gcd2, nums) -ints = map(int, sys.argv[1:]) -gcd = gcdn(ints) -print(gcd) +if len(sys.argv) > 1: + print(gcdn(map(int, sys.argv[1:]))) -- cgit v1.2.3