diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-17 22:55:58 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:43 +0100 |
| commit | 299e6a225b1bc1fbdfa0f2593d01404794c44baa (patch) | |
| tree | 36c63486ab2e383a13056511d3626c9449673f9a | |
| parent | 39788799057dc2c8a7aaf3821c9d84b1383a1e63 (diff) | |
| download | perlweeklychallenge-club-299e6a225b1bc1fbdfa0f2593d01404794c44baa.tar.gz perlweeklychallenge-club-299e6a225b1bc1fbdfa0f2593d01404794c44baa.tar.bz2 perlweeklychallenge-club-299e6a225b1bc1fbdfa0f2593d01404794c44baa.zip | |
Challenge 026 task 2
| -rwxr-xr-x | challenge-026/jo-37/perl/ch-2.pl | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-026/jo-37/perl/ch-2.pl b/challenge-026/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..599d137b68 --- /dev/null +++ b/challenge-026/jo-37/perl/ch-2.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0 '!float'; +use warnings; +use PDL; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [--] [D...] + +-examples + run the examples from the challenge + +-tests + run some tests + +D... + angles (in degrees) + +EOS + + +### Input and Output + +say angle_mean(@ARGV); + + +### Implementation + +use constant DEG2RAD => atan2(1,1) / 45; + +sub angle_mean { + my $r = DEG2RAD * pdl @_; + atan2($r->sin->average, $r->cos->average) / DEG2RAD; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is angle_mean(355, 5, 15), 5, 'example from Wiki'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
