aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2022-06-11 19:03:46 +0200
committerLubos Kolouch <lubos@kolouch.net>2022-06-11 19:03:46 +0200
commitfbe67d4a7029265af7d2e0a7ff6bd642bc748105 (patch)
tree9af395326a6627c730d3dbea0bcdfbbffc3652a3
parent2f71dc678a2e50fe3179549ba18bc27dfd827a96 (diff)
downloadperlweeklychallenge-club-fbe67d4a7029265af7d2e0a7ff6bd642bc748105.tar.gz
perlweeklychallenge-club-fbe67d4a7029265af7d2e0a7ff6bd642bc748105.tar.bz2
perlweeklychallenge-club-fbe67d4a7029265af7d2e0a7ff6bd642bc748105.zip
feat(challenge-168/lubos-kolouch/p[erl,ython]/ch-2.p[ly]): Challenge 168 Task 2 LK Perl Python
-rw-r--r--challenge-168/lubos-kolouch/perl/ch-2.pl24
-rw-r--r--challenge-168/lubos-kolouch/python/ch-2.py19
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-168/lubos-kolouch/perl/ch-2.pl b/challenge-168/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..1390fba896
--- /dev/null
+++ b/challenge-168/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use Math::Prime::Util qw/is_prime factor/;
+
+sub home_prime {
+ my $n = shift;
+
+ while ( !is_prime($n) ) {
+ my @factors = factor($n);
+ my $sum = '';
+ foreach my $factor (@factors) {
+ $sum .= $factor;
+ }
+ $n = $sum;
+ }
+
+ return $n;
+}
+
+use Test::More;
+
+is( home_prime(2), 2 );
+is( home_prime(10), 773 );
+done_testing;
diff --git a/challenge-168/lubos-kolouch/python/ch-2.py b/challenge-168/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..16094e836d
--- /dev/null
+++ b/challenge-168/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,19 @@
+from sympy import factorint, isprime
+
+
+def home_prime(n):
+
+ while not isprime(n):
+ factors = factorint(n)
+
+ my_sum = ""
+ for (my_factor, repetition) in factors.items():
+ my_sum += str(my_factor) * repetition
+
+ n = int(my_sum)
+
+ return n
+
+
+assert home_prime(2) == 2
+assert home_prime(10) == 773