aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-06-09 22:11:02 +0100
committerGitHub <noreply@github.com>2022-06-09 22:11:02 +0100
commit0146b3708226e02dc3a292c1e7d5b5b8009a5d5d (patch)
treee8de30a192b17c27ace8661e7d10c36f1411b929
parentf9354fbedfef5cf99fc327071fb81b194f83b56d (diff)
parent26d2ce2e72a752e3e622f9e0717c6b95fe205115 (diff)
downloadperlweeklychallenge-club-0146b3708226e02dc3a292c1e7d5b5b8009a5d5d.tar.gz
perlweeklychallenge-club-0146b3708226e02dc3a292c1e7d5b5b8009a5d5d.tar.bz2
perlweeklychallenge-club-0146b3708226e02dc3a292c1e7d5b5b8009a5d5d.zip
Merge pull request #6231 from massa/massa/challenge168
Answer to challenge 168 by Massa, Humberto
-rw-r--r--challenge-168/massa/raku/ch-1.raku2
-rw-r--r--challenge-168/massa/raku/ch-2.raku28
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-168/massa/raku/ch-1.raku b/challenge-168/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..2fbde00b8c
--- /dev/null
+++ b/challenge-168/massa/raku/ch-1.raku
@@ -0,0 +1,2 @@
+use v6;
+(3, 0, 2, * + * + 0 * * ... *).grep(*.is-prime).unique.head(13).sort.say
diff --git a/challenge-168/massa/raku/ch-2.raku b/challenge-168/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..535eaa16fa
--- /dev/null
+++ b/challenge-168/massa/raku/ch-2.raku
@@ -0,0 +1,28 @@
+use v6;
+
+my sub factors(int \x is copy) {
+ my int $possible-factor = 2;
+ gather {
+ while x > 1 {
+ if $possible-factor.is-prime && x %% $possible-factor {
+ take $possible-factor;
+ x div= $possible-factor
+ } else {
+ Nil until is-prime ++$possible-factor
+ }
+ }
+ }
+}
+
+my sub hp(int \x is copy) {
+ loop {
+ given +[~] factors x {
+ .return if .is-prime;
+ x = $_
+ }
+ }
+}
+
+sub MAIN(Int() \n where * > 1) {
+ say hp n
+}