aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-05 08:50:59 +0100
committerGitHub <noreply@github.com>2021-10-05 08:50:59 +0100
commitd01acf6dfd833c27a11ef0c231a8dada339959b8 (patch)
tree4f4032ea72c2f000985716c3df9070a7477a5245
parent23b1c0c5072b04625971f51aec2ff02d6ab672fe (diff)
parentefc2a3cfabe2050fb9251ecbce949a2a50a643d0 (diff)
downloadperlweeklychallenge-club-d01acf6dfd833c27a11ef0c231a8dada339959b8.tar.gz
perlweeklychallenge-club-d01acf6dfd833c27a11ef0c231a8dada339959b8.tar.bz2
perlweeklychallenge-club-d01acf6dfd833c27a11ef0c231a8dada339959b8.zip
Merge pull request #4971 from JRaspass/master
133 JRaspass
-rw-r--r--challenge-133/james-raspass/raku/ch-1.raku9
-rw-r--r--challenge-133/james-raspass/raku/ch-2.raku16
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-133/james-raspass/raku/ch-1.raku b/challenge-133/james-raspass/raku/ch-1.raku
new file mode 100644
index 0000000000..769771a924
--- /dev/null
+++ b/challenge-133/james-raspass/raku/ch-1.raku
@@ -0,0 +1,9 @@
+sub MAIN(UInt $n) { say isqrt $n }
+
+multi sub isqrt(UInt:D $n where 0 | 1) { $n }
+multi sub isqrt(UInt:D $n) {
+ my $small = isqrt($n +> 2) +< 1;
+ my $large = $small + 1;
+
+ return $large² > $n ?? $small !! $large;
+}
diff --git a/challenge-133/james-raspass/raku/ch-2.raku b/challenge-133/james-raspass/raku/ch-2.raku
new file mode 100644
index 0000000000..99c9d6ea1c
--- /dev/null
+++ b/challenge-133/james-raspass/raku/ch-2.raku
@@ -0,0 +1,16 @@
+sub factors($n is copy) {
+ my constant @primes = grep &is-prime, ^∞;
+
+ my $i;
+ gather while $n > 1 {
+ next unless $n %% my $factor = @primes[$i++];
+
+ $i = 0;
+ $n /= take $factor;
+ }
+}
+
+multi is-smith (0) { False }
+multi is-smith { !$^n.is-prime && $n.comb.sum == factors($n).comb.sum }
+
+grep(&is-smith, ^∞)[^10].say;