aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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