aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2019-09-22 23:44:46 +0200
committerE. Choroba <choroba@matfyz.cz>2019-09-22 23:44:46 +0200
commit932da7a615da96e865a8a2e16da84eeb91fd74e2 (patch)
tree041388435f04090c638fa1221200be098fb6dc14
parentc684b95aa611e84df42d4b8659b81dc3e19c049a (diff)
downloadperlweeklychallenge-club-932da7a615da96e865a8a2e16da84eeb91fd74e2.tar.gz
perlweeklychallenge-club-932da7a615da96e865a8a2e16da84eeb91fd74e2.tar.bz2
perlweeklychallenge-club-932da7a615da96e865a8a2e16da84eeb91fd74e2.zip
Add E. Choroba's solution to 026/2
-rwxr-xr-xchallenge-026/e-choroba/perl5/ch-2.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-026/e-choroba/perl5/ch-2.pl b/challenge-026/e-choroba/perl5/ch-2.pl
new file mode 100755
index 0000000000..caaa8e8244
--- /dev/null
+++ b/challenge-026/e-choroba/perl5/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use List::Util qw{ sum };
+
+use constant PI => 4 * atan2(1, 1);
+
+sub mean {
+ my @radians = map $_ * 2 * PI / 360, @_;
+ atan2(1 / @_ * sum(map sin, @radians),
+ 1 / @_ * sum(map cos, @radians))
+ / 2 / PI * 360
+}
+
+use Test::More;
+is sprintf('%.3f', mean(0, 0, 90)), 26.565;
+