aboutsummaryrefslogtreecommitdiff
path: root/challenge-141
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-141')
-rw-r--r--challenge-141/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-141/paulo-custodio/python/ch-1.py40
-rw-r--r--challenge-141/paulo-custodio/python/ch-2.py64
3 files changed, 105 insertions, 1 deletions
diff --git a/challenge-141/paulo-custodio/perl/ch-2.pl b/challenge-141/paulo-custodio/perl/ch-2.pl
index fb86077c0c..3350785871 100644
--- a/challenge-141/paulo-custodio/perl/ch-2.pl
+++ b/challenge-141/paulo-custodio/perl/ch-2.pl
@@ -9,7 +9,7 @@
# Write a script to find total count of integers created using the digits
# of $m which is also divisible by $n.
#
-# Repeating of digits are not allowed. Order/Sequence of digits can’t be
+# Repeating of digits are not allowed. Order/Sequence of digits can't be
# altered. You are only allowed to use (n-1) digits at the most. For example,
# 432 is not acceptable integer created using the digits of 1234. Also for
# 1234, you can only have integers having no more than three digits.
diff --git a/challenge-141/paulo-custodio/python/ch-1.py b/challenge-141/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..fe912ccca5
--- /dev/null
+++ b/challenge-141/paulo-custodio/python/ch-1.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python3
+
+# Challenge 141
+#
+# TASK #1 > Number Divisors
+# Submitted by: Mohammad S Anwar
+# Write a script to find lowest 10 positive integers having exactly 8 divisors.
+#
+# Example
+# 24 is the first such number having exactly 8 divisors.
+# 1, 2, 3, 4, 6, 8, 12 and 24.
+
+import sys
+import math
+
+NUM_DIVISORS = 8
+
+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]
+
+def next_number(n):
+ while True:
+ n += 1
+ divs = divisors(n)
+ if len(divs)==NUM_DIVISORS:
+ return n
+
+num = int(sys.argv[1])
+n = 0
+for i in range(num):
+ n = next_number(n)
+ print(n)
diff --git a/challenge-141/paulo-custodio/python/ch-2.py b/challenge-141/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..f1eb159af7
--- /dev/null
+++ b/challenge-141/paulo-custodio/python/ch-2.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python3
+
+# Challenge 141
+#
+# TASK #2 > Like Numbers
+# Submitted by: Mohammad S Anwar
+# You are given positive integers, $m and $n.
+#
+# Write a script to find total count of integers created using the digits
+# of $m which is also divisible by $n.
+#
+# Repeating of digits are not allowed. Order/Sequence of digits can't be
+# altered. You are only allowed to use (n-1) digits at the most. For example,
+# 432 is not acceptable integer created using the digits of 1234. Also for
+# 1234, you can only have integers having no more than three digits.
+#
+# Example 1:
+# Input: $m = 1234, $n = 2
+# Output: 9
+#
+# Possible integers created using the digits of 1234 are:
+# 1, 2, 3, 4, 12, 13, 14, 23, 24, 34, 123, 124, 134 and 234.
+#
+# There are 9 integers divisible by 2 such as:
+# 2, 4, 12, 14, 24, 34, 124, 134 and 234.
+# Example 2:
+# Input: $m = 768, $n = 4
+# Output: 3
+#
+# Possible integers created using the digits of 768 are:
+# 7, 6, 8, 76, 78 and 68.
+#
+# There are 3 integers divisible by 4 such as:
+# 8, 76 and 68.
+
+import sys
+
+def numbers(num):
+ ret = []
+ mask_n = 0
+ while True:
+ mask = ("{:0"+str(len(str(num)))+"b}").format(mask_n)
+ if len(mask) > len(str(num)):
+ break
+
+ # combine num with mask
+ res = 0
+ for i in range(len(str(num))):
+ if mask[i] == "1":
+ res = 10*res + int(str(num)[i])
+
+ ret.append(res)
+ mask_n += 1
+
+ return ret
+
+m = int(sys.argv[1])
+n = int(sys.argv[2])
+count = 0
+for num in numbers(m):
+ if num != 0 and num != m:
+ if num % n == 0:
+ count += 1
+print(count)