aboutsummaryrefslogtreecommitdiff
path: root/challenge-026/yet-ebreo/perl5/ch-2.pl
blob: 8203324e9fdb7bdbdccc3a1e6b18bfb80f5e6d20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Create a script that prints mean angles of the given list of angles in degrees. 
# Please read wiki(https://en.wikipedia.org/wiki/Mean_of_circular_quantities) page 
# that explains the formula in details with an example.

use strict;
use warnings;
use v5.10;

use Math::Trig;

die "Usage:\n\tch-2.pl <angle1> .. <anglen>\n\n" if !@ARGV;
die "Only numbers are allowed as input\n" if grep  !/^[-+]?\d+$/,  @ARGV;

my ($y_comp,$x_comp) = 0;
$y_comp+=sin deg2rad($_),$x_comp+=cos deg2rad($_)  for @ARGV;
say rad2deg(atan2($y_comp,$x_comp));