aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-026/joelle-maslak/perl5/ch-2.pl35
-rwxr-xr-xchallenge-026/joelle-maslak/perl6/ch-2.p635
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;
+ }
+ }
+ }
+}
+
+