diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-09-21 10:32:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-21 10:32:50 +0100 |
| commit | f42de160dafb4e65e649f4e4867d847681c16166 (patch) | |
| tree | 6cdd93d33dc08c94c870268c0d04782291e9a1ae | |
| parent | 91d089d0119dcc0afe06c6fe43bfe941ba8a5bd5 (diff) | |
| parent | a95d24a5c0b38a5ef5ceb74c5e497145f18cbdf7 (diff) | |
| download | perlweeklychallenge-club-f42de160dafb4e65e649f4e4867d847681c16166.tar.gz perlweeklychallenge-club-f42de160dafb4e65e649f4e4867d847681c16166.tar.bz2 perlweeklychallenge-club-f42de160dafb4e65e649f4e4867d847681c16166.zip | |
Merge pull request #648 from jmaslak/joelle-26-2-1
Joelle's solutions to 26.2
| -rwxr-xr-x | challenge-026/joelle-maslak/perl5/ch-2.pl | 35 | ||||
| -rwxr-xr-x | challenge-026/joelle-maslak/perl6/ch-2.p6 | 35 |
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-026/joelle-maslak/perl5/ch-2.pl b/challenge-026/joelle-maslak/perl5/ch-2.pl new file mode 100755 index 0000000000..e34707fff4 --- /dev/null +++ b/challenge-026/joelle-maslak/perl5/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use v5.16; +use strict; +use warnings; + +my $x = my $y = 0; + +for my $angle (@ARGV) { + my $rad = ($angle % 360.0) * 3.14159 / 180.0; + $x += cos($rad); + $y += sin($rad); +} + +if (abs($x) < .00001 and abs($y) < .00001) { + say "No average"; +} else { + my $deg = atan2($y,$x) * 180 / 3.14159; + if ($x > 0 and $y > 0) { + printf("%.2f\n", $deg); + } elsif ($x < 0 and $y > 0) { + printf("%.2f\n", $deg); + } elsif ($x < 0 and $y < 0) { + printf("%.2f\n", $deg + 360); + } else { + my $out = sprintf("%.2f", ($deg + 360)); + if ($out eq '360.00') { + say "0.00"; + } else { + say $out; + } + } +} + + diff --git a/challenge-026/joelle-maslak/perl6/ch-2.p6 b/challenge-026/joelle-maslak/perl6/ch-2.p6 new file mode 100755 index 0000000000..dfc415d072 --- /dev/null +++ b/challenge-026/joelle-maslak/perl6/ch-2.p6 @@ -0,0 +1,35 @@ +#!/usr/bin/env perl6 +use v6; + +sub MAIN(+@angles) { + my $x = 0; + my $y = 0; + + for @angles -> $angle { + my $rad = ($angle % 360) * π / 180; + $x += cos($rad); + $y += sin($rad); + } + + kif $x ≅ 0 { + say "No average"; + } else { + my $deg = atan($y/$x) * 180 / π; + if $x > 0 and $y > 0 { + say $deg.fmt("%.2f"); + } elsif $x < 0 and $y > 0 { + say ($deg + 180).fmt("%.2f"); + } elsif $x < 0 and $y < 0 { + say ($deg + 180).fmt("%.2f"); + } else { + my $out = ($deg + 360).fmt("%.2f"); + if $out eq '360.00' { + say "0.00"; + } else { + say $out; + } + } + } +} + + |
