aboutsummaryrefslogtreecommitdiff
path: root/challenge-142/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2021-12-07 17:08:53 -0500
committerDave Jacoby <jacoby.david@gmail.com>2021-12-07 17:08:53 -0500
commitf0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4 (patch)
treea7162c0c01b282684f159edc35a2f940a8a77e38 /challenge-142/paulo-custodio/python/ch-1.py
parent038f05c9243b83b2b654559b5005506bc6a3fc2b (diff)
parent59dd7ccf422a3b10f31e3ad2cc9a2704ce6b40e0 (diff)
downloadperlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.tar.gz
perlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.tar.bz2
perlweeklychallenge-club-f0230b0a58c8d2a63ba172c0c04ac75e5c80e0d4.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-142/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-142/paulo-custodio/python/ch-1.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-142/paulo-custodio/python/ch-1.py b/challenge-142/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..d142b7d24f
--- /dev/null
+++ b/challenge-142/paulo-custodio/python/ch-1.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+# TASK #1 > Divisor Last Digit
+# Submitted by: Mohammad S Anwar
+# You are given positive integers, $m and $n.
+#
+# Write a script to find total count of divisors of $m having last digit $n.
+#
+#
+# Example 1:
+# Input: $m = 24, $n = 2
+# Output: 2
+#
+# The divisors of 24 are 1, 2, 3, 4, 6, 8 and 12.
+# There are only 2 divisors having last digit 2 are 2 and 12.
+#
+# Example 2:
+# Input: $m = 30, $n = 5
+# Output: 2
+#
+# The divisors of 30 are 1, 2, 3, 5, 6, 10 and 15.
+# There are only 2 divisors having last digit 5 are 5 and 15.
+
+import sys
+import math
+import re
+
+def divisors(n):
+ div_low = []
+ div_high = []
+ for i in range(1, int(math.sqrt(n)+1)):
+ if n%i==0:
+ div_low.append(i)
+ if n/i!=i:
+ div_high.append(int(n/i))
+ div_high = div_high[::-1]
+ return [*div_low, *div_high]
+
+m = int(sys.argv[1])
+n = int(sys.argv[2])
+count = len(list(filter(lambda x: re.search(str(n)+"$", str(x)), divisors(m))))
+print(count)