aboutsummaryrefslogtreecommitdiff
path: root/challenge-157
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-03-26 14:09:19 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-03-26 14:09:19 +0000
commitcbd11122265a47230fd6c5eead8bd3d817ccea2f (patch)
tree413c7021c30d0e836b24ae50be07b6864fbdcc0f /challenge-157
parent9d6673d55515cd130a89628549f8e443b0931ed7 (diff)
downloadperlweeklychallenge-club-cbd11122265a47230fd6c5eead8bd3d817ccea2f.tar.gz
perlweeklychallenge-club-cbd11122265a47230fd6c5eead8bd3d817ccea2f.tar.bz2
perlweeklychallenge-club-cbd11122265a47230fd6c5eead8bd3d817ccea2f.zip
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-157')
-rw-r--r--challenge-157/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-157/laurent-rosenfeld/perl/ch-1.pl21
-rw-r--r--challenge-157/laurent-rosenfeld/raku/ch-1.raku7
3 files changed, 29 insertions, 0 deletions
diff --git a/challenge-157/laurent-rosenfeld/blog.txt b/challenge-157/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..8157c7fd04
--- /dev/null
+++ b/challenge-157/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/laurent_r/2022/03/perl-weekly-challenge-157-pythagorean-means-and-brazilian-number.html
diff --git a/challenge-157/laurent-rosenfeld/perl/ch-1.pl b/challenge-157/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..1ef0ec21b7
--- /dev/null
+++ b/challenge-157/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use feature "say";
+
+for my $test ([1,3,5,6,9], [2,4,6,8,10], [1,2,3,4,5]) {
+ my @in = @$test;
+ my $n = scalar @in;
+
+ my $sum = 0;
+ $sum += $_ for @in;
+ my $am = $sum / $n;
+
+ my $prod = 1;
+ $prod *= $_ for @in;
+ my $gm = $prod ** (1/$n);
+
+ my $invsum = 0;
+ $invsum += 1/$_ for @in;
+ my $hm = $n / $invsum;
+ printf "%-10s -> AM: %0.1f, GM: %0.1f, HM: %0.1f\n", "@in", $am, $gm, $hm;
+}
diff --git a/challenge-157/laurent-rosenfeld/raku/ch-1.raku b/challenge-157/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..5a12aad192
--- /dev/null
+++ b/challenge-157/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,7 @@
+for (1,3,5,6,9), (2,4,6,8,10), (1,2,3,4,5) -> @in {
+ my $n = @in.elems;
+ my $am = ([+] @in)/ $n;
+ my $gm = ([*] @in)** (1/$n);
+ my $hm = $n / ([+] map { 1/$_}, @in);
+ printf "%-10s -> AM: %0.1f, GM: %0.1f, HM: %0.1f\n", "@in[]", $am, $gm, $hm;
+}