aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-04-01 21:46:19 +0100
committerGitHub <noreply@github.com>2022-04-01 21:46:19 +0100
commit380348eb9e23792bfa446f05d85229dbab7dbe1f (patch)
tree344b73ee249955263aea88027040300085a3b8a2
parentbf795928f9a22f268aecd7ff736c659fe698fca0 (diff)
parentec2ba23f4b8a618f077f7310c77832631e57dd36 (diff)
downloadperlweeklychallenge-club-380348eb9e23792bfa446f05d85229dbab7dbe1f.tar.gz
perlweeklychallenge-club-380348eb9e23792bfa446f05d85229dbab7dbe1f.tar.bz2
perlweeklychallenge-club-380348eb9e23792bfa446f05d85229dbab7dbe1f.zip
Merge pull request #5869 from LubosKolouch/master
feat(challenge-158/lubos-kolouch/[perl,python]/ch-1.p[ly]): Challenge 158 Task 1 LK Perl Python
-rw-r--r--challenge-158/lubos-kolouch/perl/ch-1.pl29
-rw-r--r--challenge-158/lubos-kolouch/python/ch-1.py21
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-158/lubos-kolouch/perl/ch-1.pl b/challenge-158/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..bb4d6a431b
--- /dev/null
+++ b/challenge-158/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,29 @@
+package main;
+use strict;
+use warnings;
+use Math::Prime::Util qw/is_prime next_prime/;
+use List::Util qw/sum/;
+
+sub get_additive_primes {
+ my $limit = shift;
+
+ my $pos = 1;
+ my @primes;
+ while ( $pos <= $limit ) {
+
+ push @primes, $pos
+ if is_prime($pos)
+ and is_prime( sum( split //, $pos ) );
+ $pos = next_prime($pos);
+ }
+
+ return \@primes;
+}
+
+use Test::More;
+
+is_deeply( get_additive_primes(100),
+ [ 2, 3, 5, 7, 11, 23, 29, 41, 43, 47, 61, 67, 83, 89 ] );
+
+done_testing;
+1;
diff --git a/challenge-158/lubos-kolouch/python/ch-1.py b/challenge-158/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..5e32ad5748
--- /dev/null
+++ b/challenge-158/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,21 @@
+# Challenge 158 Task 1
+from sympy import isprime, nextprime
+
+
+def get_additive_primes(limit: int) -> list:
+ """Get the list of primes"""
+
+ pos = 1
+ primes = []
+
+ while pos <= limit:
+
+ if isprime(pos) and isprime(sum(list(map(int, str(pos))))):
+ primes.append(pos)
+
+ pos = nextprime(pos)
+
+ return primes
+
+
+assert get_additive_primes(100) == [2, 3, 5, 7, 11, 23, 29, 41, 43, 47, 61, 67, 83, 89]