aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-05-31 21:20:23 +0100
committerGitHub <noreply@github.com>2022-05-31 21:20:23 +0100
commit23e117bffd0eda3524c1b0dc16f1eaa854ad3bbf (patch)
tree84431e4d32b0ce60d50cf9a103ca88ff0e9a1bb5
parentf1d6fc266a414b9bfc81072bee48688feada61b8 (diff)
parent0053fbb175e509a2f383703d179e1d3123f3cd47 (diff)
downloadperlweeklychallenge-club-23e117bffd0eda3524c1b0dc16f1eaa854ad3bbf.tar.gz
perlweeklychallenge-club-23e117bffd0eda3524c1b0dc16f1eaa854ad3bbf.tar.bz2
perlweeklychallenge-club-23e117bffd0eda3524c1b0dc16f1eaa854ad3bbf.zip
Merge pull request #6185 from andemark/branch-for-challenge-167
Branch for challenge 167
-rw-r--r--challenge-167/mark-anderson/raku/ch-1.raku26
-rw-r--r--challenge-167/mark-anderson/raku/ch-2.raku45
2 files changed, 71 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..bac4a5ee03
--- /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 ... *).hyper
+ .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..ddfd905443
--- /dev/null
+++ b/challenge-167/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,45 @@
+#!/usr/bin/env raku
+
+# A translation of the Python code at https://en.wikipedia.org/wiki/Lanczos_approximation
+
+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;
+}