diff options
| author | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-09-16 13:40:10 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zpg.co.uk> | 2019-09-16 13:40:10 +0100 |
| commit | c95990faa9b34dacc195bb3ea9281a7c08d032e5 (patch) | |
| tree | 43242479db09751006c36d84f084306057a26e62 | |
| parent | 1c687a28d119b667f8e46ff419b8ea09583014d3 (diff) | |
| download | perlweeklychallenge-club-c95990faa9b34dacc195bb3ea9281a7c08d032e5.tar.gz perlweeklychallenge-club-c95990faa9b34dacc195bb3ea9281a7c08d032e5.tar.bz2 perlweeklychallenge-club-c95990faa9b34dacc195bb3ea9281a7c08d032e5.zip | |
Think this does the job.
| -rw-r--r-- | challenge-026/simon-proctor/perl6/ch-2.p6 | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-026/simon-proctor/perl6/ch-2.p6 b/challenge-026/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..7cecefa708 --- /dev/null +++ b/challenge-026/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,33 @@ +#!/usr/bin/env perl6 + +use v6; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +#| Document script +multi sub MAIN( Bool :h(:$help) where ?* ) { say $*USAGE } + +#| Take a list of angles in Radians and return the Mean of them in Radians +multi sub MAIN( + *@rad-angles where *.elems > 1 #= List of at least 2 angles in Radians +) { + say find-mean( @rad-angles ); +} + + +#| Take a list of angles in Degress and return the Mean of them in Degrees +multi sub MAIN ( + Bool :deg(:$degrees) where ?*, #= Degrees flag + *@deg-angles where *.elems > 1 #= List of at least 2 angles in Degrees +) { + my @rad-angles = @deg-angles.map( * * π / 180 ); + + say ( find-mean(@rad-angles) * (180 / π) ).round(0.01); +} + +sub find-mean( @angles is copy ) { + my $sin = (1/@angles.elems) * ( [+] @angles.map( { sin($_) } ) ); + my $cos = (1/@angles.elems) * ( [+] @angles.map( { cos($_) } ) ); + + $sin.atan2( $cos ); +} |
