aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
+