aboutsummaryrefslogtreecommitdiff
path: root/challenge-141
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-04 15:56:01 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-04 15:56:01 +0000
commitfd95c790e4b5d2590b0feaeb8f15eeb48104d7dc (patch)
tree12e72ac49189953f625afae0c5c30fe42125e8f1 /challenge-141
parent4cab95d9015381b769503e4fe81ff492243b85fc (diff)
downloadperlweeklychallenge-club-fd95c790e4b5d2590b0feaeb8f15eeb48104d7dc.tar.gz
perlweeklychallenge-club-fd95c790e4b5d2590b0feaeb8f15eeb48104d7dc.tar.bz2
perlweeklychallenge-club-fd95c790e4b5d2590b0feaeb8f15eeb48104d7dc.zip
- Added Python solutions to week 141.
Diffstat (limited to 'challenge-141')
-rw-r--r--challenge-141/mohammad-anwar/python/ch-1.py46
-rw-r--r--challenge-141/mohammad-anwar/python/ch-2.py51
2 files changed, 97 insertions, 0 deletions
diff --git a/challenge-141/mohammad-anwar/python/ch-1.py b/challenge-141/mohammad-anwar/python/ch-1.py
new file mode 100644
index 0000000000..b07284649b
--- /dev/null
+++ b/challenge-141/mohammad-anwar/python/ch-1.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python3
+
+'''
+
+Week 141:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-141
+
+Task #1: Number Divisors
+
+ Write a script to find lowest 10 positive integers having exactly 8 divisors.
+
+'''
+
+import unittest
+
+def number_divisors(count, number):
+ numbers = []
+ i = 1
+
+ while len(numbers) < count:
+ divisors = []
+ for j in range(1, i+1):
+ if i % j == 0:
+ divisors.append(j)
+
+ if len(divisors) == number:
+ numbers.append(i)
+
+ i += 1
+
+ return numbers
+
+#
+#
+# Unit test class
+
+class TestJortSort(unittest.TestCase):
+
+ def test_example_1(self):
+ self.assertEqual(
+ number_divisors(10, 8),
+ [24, 30, 40, 42, 54, 56, 66, 70, 78, 88],
+ 'Example 1')
+
+unittest.main()
diff --git a/challenge-141/mohammad-anwar/python/ch-2.py b/challenge-141/mohammad-anwar/python/ch-2.py
new file mode 100644
index 0000000000..96b013c73c
--- /dev/null
+++ b/challenge-141/mohammad-anwar/python/ch-2.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python3
+
+'''
+
+Week 141:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-141
+
+Task #1: Like Numbers
+
+ 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.
+
+'''
+
+from itertools import combinations
+import unittest
+
+def like_numbers(m, n):
+ numbers = []
+ m_digits = [int(a) for a in str(m)]
+
+ for i in range(1, len(m_digits)):
+ divisors = []
+ for j in combinations(m_digits, i):
+ num = int(''.join(str(x) for x in (j)))
+ if num % n == 0:
+ numbers.append(num)
+
+ return numbers
+
+#
+#
+# Unit test class
+
+class TestJortSort(unittest.TestCase):
+
+ def test_example_1(self):
+ self.assertEqual(
+ like_numbers(1234, 2),
+ [2, 4, 12, 14, 24, 34, 124, 134, 234],
+ 'Example 1')
+
+ def test_example_2(self):
+ self.assertEqual(
+ like_numbers(768, 4),
+ [8, 76, 68],
+ 'Example 2')
+
+unittest.main()