aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Raspass <jraspass@gmail.com>2021-10-05 02:43:23 +0100
committerJames Raspass <jraspass@gmail.com>2021-10-05 02:43:43 +0100
commitefc2a3cfabe2050fb9251ecbce949a2a50a643d0 (patch)
tree4f4032ea72c2f000985716c3df9070a7477a5245
parent23b1c0c5072b04625971f51aec2ff02d6ab672fe (diff)
downloadperlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.tar.gz
perlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.tar.bz2
perlweeklychallenge-club-efc2a3cfabe2050fb9251ecbce949a2a50a643d0.zip
133 JRaspass
$large² and ^∞ are fun uses of unicode imo.
-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;