aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-03-19 12:18:32 +0000
committerGitHub <noreply@github.com>2022-03-19 12:18:32 +0000
commitcb656c351b80d28d0b06d1d192084380c02000a3 (patch)
treed9f38c29efeed3a7b0d52289d304eaea88d13a8b
parentc836622025e68085ef72ce67cbf0aa5cc7f0b47f (diff)
parentb9ec2195aa1d4d05416d73c4c4dcdfa6b54f0262 (diff)
downloadperlweeklychallenge-club-cb656c351b80d28d0b06d1d192084380c02000a3.tar.gz
perlweeklychallenge-club-cb656c351b80d28d0b06d1d192084380c02000a3.tar.bz2
perlweeklychallenge-club-cb656c351b80d28d0b06d1d192084380c02000a3.zip
Merge pull request #5795 from LubosKolouch/master
Challenge 156 LK Python
-rw-r--r--challenge-156/lubos-kolouch/python/ch-1.py22
-rw-r--r--challenge-156/lubos-kolouch/python/ch-2.py27
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-156/lubos-kolouch/python/ch-1.py b/challenge-156/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..66576b2f52
--- /dev/null
+++ b/challenge-156/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,22 @@
+""" Challenge 156 Task 1 LK """
+import re
+
+from sympy import isprime
+
+
+def get_pernicious(what: int) -> list:
+ """Get the pernicious numbers"""
+
+ nums: list[int] = []
+
+ num = 0
+ while len(nums) < what:
+ num += 1
+ bin_num = f"{num:b}"
+ bin_num = re.sub("0", "", bin_num)
+ if isprime(len(bin_num)):
+ nums.append(num)
+ return nums
+
+
+assert get_pernicious(10) == [3, 5, 6, 7, 9, 10, 11, 12, 13, 14]
diff --git a/challenge-156/lubos-kolouch/python/ch-2.py b/challenge-156/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..aa62e4cbe1
--- /dev/null
+++ b/challenge-156/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,27 @@
+""" Challenge 156 Task 2 LK """
+from itertools import combinations
+
+from sympy import divisors
+
+
+def is_weird(what: int) -> bool:
+ """Check if the number is weird"""
+
+ all_divisors = divisors(what)
+
+ # remove the number itself from the list
+ del all_divisors[-1]
+
+ if sum(all_divisors) <= what:
+ return False
+
+ for i in range(1, len(all_divisors) + 1):
+ all_combs = combinations(all_divisors, i)
+ for comb in all_combs:
+ if sum(comb) == what:
+ return False
+ return True
+
+
+assert is_weird(12) == 0
+assert is_weird(70) == 1