diff options
| author | Simon Green <mail@simon.green> | 2021-12-12 14:45:17 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2021-12-12 14:45:17 +1100 |
| commit | 277a6b908be328067cc11fb8353d5a88f91db2d8 (patch) | |
| tree | 6e4e5c0cb588b005bccb5ad0b99bb41e7967fa04 /challenge-142/sgreen/python/ch-1.py | |
| parent | a64c96703f1714a1598fe7fb90450a2763122643 (diff) | |
| download | perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.tar.gz perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.tar.bz2 perlweeklychallenge-club-277a6b908be328067cc11fb8353d5a88f91db2d8.zip | |
sgreen solutions to challenge 142
Diffstat (limited to 'challenge-142/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-142/sgreen/python/ch-1.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-142/sgreen/python/ch-1.py b/challenge-142/sgreen/python/ch-1.py new file mode 100755 index 0000000000..7f45ee1156 --- /dev/null +++ b/challenge-142/sgreen/python/ch-1.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import sys + + +def _get_divisors(number): + # Every number is divisible by 1 + divisors = [1] + + # One only has one divisor + if number == 1: + return divisors + + # Find other divisors + for i in range(2, int(number / 2) + 1): + if number % i == 0: + divisors.append(i) + + # ... including the number itself + divisors.append(number) + + return divisors + + +def main(inputs): + m = int(inputs[0]) + n = int(inputs[1]) + + if m < 1: + raise ValueError('The first number must be a positive integer') + if n < 1 or n > 9: + raise ValueError('The second number must be between 1 and 9') + + # Get a list of divisors and find those that end with n. + solution = [x for x in _get_divisors(m) if x % 10 == n] + print(len(solution)) + + +if __name__ == '__main__': + main(sys.argv[1:]) |
