aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2022-05-30 23:29:24 +0000
committerMark <53903062+andemark@users.noreply.github.com>2022-05-30 23:29:24 +0000
commit1dba828ad4c745fb8c2cd5c06711a89bbd0e43f1 (patch)
treebe35ef29108ec4d881f509f9e0860e79cbdc45cb
parent95b68ec3530b952a89d3317f05b7da7cb6fd4145 (diff)
downloadperlweeklychallenge-club-1dba828ad4c745fb8c2cd5c06711a89bbd0e43f1.tar.gz
perlweeklychallenge-club-1dba828ad4c745fb8c2cd5c06711a89bbd0e43f1.tar.bz2
perlweeklychallenge-club-1dba828ad4c745fb8c2cd5c06711a89bbd0e43f1.zip
Challenge 167 Solutions (Raku)
-rw-r--r--challenge-167/mark-anderson/raku/ch-1.raku26
-rw-r--r--challenge-167/mark-anderson/raku/ch-2.raku47
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-167/mark-anderson/raku/ch-1.raku b/challenge-167/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..f3e9e28ddc
--- /dev/null
+++ b/challenge-167/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+my %seen;
+
+say (101, 103, 105 ... *).grep(&is-prime)
+ .grep(&circular)
+ .head(10);
+
+sub circular($n is copy)
+{
+ return True if $n < 10;
+ return False if $n ~~ /<[024568]>/;
+ return False if %seen{$n};
+
+ my @n = $n.comb;
+
+ for ^@n.end
+ {
+ @n .= rotate;
+ %seen{@n.join} = True;
+
+ return False unless @n.join.is-prime;
+ }
+
+ return True;
+}
diff --git a/challenge-167/mark-anderson/raku/ch-2.raku b/challenge-167/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..6652f0ef01
--- /dev/null
+++ b/challenge-167/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,47 @@
+#!/usr/bin/env raku
+
+use Test;
+
+is-approx Γ(3), 2;
+is-approx Γ(5), 24;
+is-approx Γ(7), 720;
+
+sub Γ($z is copy)
+{
+ my \ϵ = 1e-7;
+
+ my @p = [ 676.5203681218851,
+ -1259.1392167224028,
+ 771.32342877765313,
+ -176.61502916214059,
+ 12.507343278686905,
+ -0.13857109526572012,
+ 9.9843695780195716e-6,
+ 1.5056327351493116e-7 ];
+
+ my $y;
+
+ $z .= Complex;
+
+ if $z.re < ½
+ {
+ $y = π / (sin(π * $z) * Γ(1 - $z))
+ }
+
+ else
+ {
+ $z--;
+
+ my $x = 0.99999999999980993;
+
+ $x += $_ / ($z + $++ + 1) for @p;
+
+ my $t = $z + @p - ½;
+
+ $y = sqrt(2 * π) * $t ** ($z + ½) * exp(-$t) * $x;
+ }
+
+ $y = $y.re if abs($y.im) <= ϵ;
+
+ return $y;
+}