aboutsummaryrefslogtreecommitdiff
path: root/challenge-142/paulo-custodio/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-142/paulo-custodio/python')
-rw-r--r--challenge-142/paulo-custodio/python/ch-1.py42
-rw-r--r--challenge-142/paulo-custodio/python/ch-2.py26
2 files changed, 68 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)
diff --git a/challenge-142/paulo-custodio/python/ch-2.py b/challenge-142/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..31f6f67abe
--- /dev/null
+++ b/challenge-142/paulo-custodio/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python3
+
+# TASK #2 > Sleep Sort
+# Submitted by: Adam Russell
+# Another joke sort similar to JortSort suggested by champion Adam Russell.
+#
+# You are given a list of numbers.
+#
+# Write a script to implement Sleep Sort. For more information, please checkout
+# this post.
+
+import sys
+import threading
+from time import sleep
+
+def sleeper(n):
+ sleep(n)
+ print(n)
+
+thrs = []
+for n in [int(x) for x in sys.argv[1:]]:
+ thr = threading.Thread(target=sleeper, args=[n])
+ thrs.append(thr)
+ thr.start()
+for thr in thrs:
+ thr.join()