aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-10-03 13:41:49 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-10-03 13:41:49 +0100
commit6fc1c623577ffe0e1a0ef89d8c2a6c7d87f0a6ca (patch)
tree5ec49f61c89a4da68dac9fbed829ddb753a6f528
parent6b8392b8c6d5dab4313565a45ee731645629fb3a (diff)
downloadperlweeklychallenge-club-6fc1c623577ffe0e1a0ef89d8c2a6c7d87f0a6ca.tar.gz
perlweeklychallenge-club-6fc1c623577ffe0e1a0ef89d8c2a6c7d87f0a6ca.tar.bz2
perlweeklychallenge-club-6fc1c623577ffe0e1a0ef89d8c2a6c7d87f0a6ca.zip
Add Python solution to challenge 170-task 1
-rw-r--r--challenge-170/paulo-custodio/perl/ch-1.pl8
-rw-r--r--challenge-170/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-170/paulo-custodio/python/ch-1.py52
3 files changed, 57 insertions, 5 deletions
diff --git a/challenge-170/paulo-custodio/perl/ch-1.pl b/challenge-170/paulo-custodio/perl/ch-1.pl
index 4d36966785..3d07569f3b 100644
--- a/challenge-170/paulo-custodio/perl/ch-1.pl
+++ b/challenge-170/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 170
#
@@ -14,9 +14,9 @@
#
# P(0) = 1 (1)
# P(1) = 2 (1x2)
-# P(2) = 6 (1x2×3)
-# P(3) = 30 (1x2×3×5)
-# P(4) = 210 (1x2×3×5×7)
+# P(2) = 6 (1x2x3)
+# P(3) = 30 (1x2x3x5)
+# P(4) = 210 (1x2x3x5x7)
use Modern::Perl;
diff --git a/challenge-170/paulo-custodio/perl/ch-2.pl b/challenge-170/paulo-custodio/perl/ch-2.pl
index dfff30bef8..aa101be3a9 100644
--- a/challenge-170/paulo-custodio/perl/ch-2.pl
+++ b/challenge-170/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 170
#
diff --git a/challenge-170/paulo-custodio/python/ch-1.py b/challenge-170/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..1b2a973b87
--- /dev/null
+++ b/challenge-170/paulo-custodio/python/ch-1.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+# Challenge 170
+#
+# Task 1: Primorial Numbers
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to generate first 10 Primorial Numbers.
+#
+# Primorial numbers are those formed by multiplying successive prime numbers.
+#
+#
+# For example,
+#
+# P(0) = 1 (1)
+# P(1) = 2 (1x2)
+# P(2) = 6 (1x2x3)
+# P(3) = 30 (1x2x3x5)
+# P(4) = 210 (1x2x3x5x7)
+
+import sys
+
+def is_prime(n):
+ if n == 2 or n == 3:
+ return True
+ if n <= 1 or n % 2 == 0 or n % 3 == 0:
+ return False
+ i = 5
+ while i * i <= n:
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ i += 6
+ return True
+
+def next_prime(p):
+ p += 1
+ while not is_prime(p):
+ p += 1
+ return p
+
+def primorial_numbers(n):
+ primorial = [1]
+ p = 1
+ while len(primorial) < n:
+ p = next_prime(p)
+ primorial.append(primorial[-1] * p)
+ return primorial
+
+if len(sys.argv) != 2:
+ raise ValueError("usage: ch-1.py n")
+n = int(sys.argv[1])
+print(", ".join(map(str, primorial_numbers(n))))