diff options
Diffstat (limited to 'challenge-082/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-082/paulo-custodio/python/ch-1.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/challenge-082/paulo-custodio/python/ch-1.py b/challenge-082/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..c1eb31d194 --- /dev/null +++ b/challenge-082/paulo-custodio/python/ch-1.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +# Challenge 082 +# +# TASK #1 > Common Factors +# Submitted by: Niels van Dijke +# You are given 2 positive numbers $M and $N. +# +# Write a script to list all common factors of the given numbers. +# +# Example 1: +# Input: +# $M = 12 +# $N = 18 +# +# Output: +# (1, 2, 3, 6) +# +# Explanation: +# Factors of 12: 1, 2, 3, 4, 6 +# Factors of 18: 1, 2, 3, 6, 9 +# Example 2: +# Input: +# $M = 18 +# $N = 23 +# +# Output: +# (1) +# +# Explanation: +# Factors of 18: 1, 2, 3, 6, 9 +# Factors of 23: 1 + +import sys + +def get_common_factors(a, b): + factors = [] + i = 1 + while i <= a or i <= b: + if a%i==0 and b%i==0: + factors.append(i) + i += 1 + return factors + +factors = get_common_factors(int(sys.argv[1]), int(sys.argv[2])) +print("("+ ", ".join([str(x) for x in factors]) +" )") |
