aboutsummaryrefslogtreecommitdiff
path: root/challenge-041/paulo-custodio/python
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2022-04-28 14:02:48 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2022-04-28 14:02:48 +0100
commitf1210b445c4b4124ee1247820be36550fe89517c (patch)
treed3f3979e8ab961e1b8837ef6e0b9d5515ab603e9 /challenge-041/paulo-custodio/python
parent1f6e4c616cb20508f0c372289027f611adebdb22 (diff)
downloadperlweeklychallenge-club-f1210b445c4b4124ee1247820be36550fe89517c.tar.gz
perlweeklychallenge-club-f1210b445c4b4124ee1247820be36550fe89517c.tar.bz2
perlweeklychallenge-club-f1210b445c4b4124ee1247820be36550fe89517c.zip
Add Python solution to challenge 041
Diffstat (limited to 'challenge-041/paulo-custodio/python')
-rw-r--r--challenge-041/paulo-custodio/python/ch-1.py24
-rw-r--r--challenge-041/paulo-custodio/python/ch-2.py25
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-041/paulo-custodio/python/ch-1.py b/challenge-041/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..8eb700c727
--- /dev/null
+++ b/challenge-041/paulo-custodio/python/ch-1.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+# Challenge 041
+#
+# TASK #1
+# Write a script to display attractive number between 1 and 50.
+# A number is an attractive number if the number of its prime factors is also
+# prime number.
+#
+# The number 20 is an attractive number, whose prime factors are 2, 2 and 5.
+# The total prime factors is 3 which is also a prime number.
+
+from primePy import primes
+
+def is_attractive(n):
+ factors = primes.factors(n)
+ num_factors = len(factors)
+ return num_factors != 1 and primes.check(num_factors)
+
+out = []
+for n in range(1, 50+1):
+ if is_attractive(n):
+ out.append(n)
+print(", ".join([str(x) for x in out]))
diff --git a/challenge-041/paulo-custodio/python/ch-2.py b/challenge-041/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..cc11c93b79
--- /dev/null
+++ b/challenge-041/paulo-custodio/python/ch-2.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+# Challenge 041
+#
+# TASK #2
+# Write a script to display first 20 Leonardo Numbers. Please checkout wiki
+# page for more information.
+# For example:
+#
+# L(0) = 1
+# L(1) = 1
+# L(2) = L(0) + L(1) + 1 = 3
+# L(3) = L(1) + L(2) + 1 = 5
+# and so on.
+
+def leonardo(n):
+ if n < 2:
+ return 1
+ else:
+ return leonardo(n-1)+leonardo(n-2)+1
+
+out = []
+for n in range(20):
+ out.append(leonardo(n))
+print(", ".join([str(x) for x in out]))