aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 16:22:35 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 16:22:35 +0000
commit519d44c0a7356bc03840549e421446656f7f2813 (patch)
treef25ec05fe369c70de3940d50a0ded903940804b3
parent0738a0e639d7b7e8f60cf0ecd60d2f5e6f8124b7 (diff)
downloadperlweeklychallenge-club-519d44c0a7356bc03840549e421446656f7f2813.tar.gz
perlweeklychallenge-club-519d44c0a7356bc03840549e421446656f7f2813.tar.bz2
perlweeklychallenge-club-519d44c0a7356bc03840549e421446656f7f2813.zip
Add Python solution to challenge 142
-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()