aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn <shawnw.mobile@gmail.com>2020-09-27 22:47:58 -0700
committerShawn <shawnw.mobile@gmail.com>2020-09-28 23:14:03 -0700
commit3aee6b4c16f1b4bdfefc5d32f3ee535bf4ed3412 (patch)
tree75cfd7d7da9ec03e3ac77493834f66b0046eda1e
parent4e1b4cac8568d80f0a20b729a87d55a3bfe86a3b (diff)
downloadperlweeklychallenge-club-3aee6b4c16f1b4bdfefc5d32f3ee535bf4ed3412.tar.gz
perlweeklychallenge-club-3aee6b4c16f1b4bdfefc5d32f3ee535bf4ed3412.tar.bz2
perlweeklychallenge-club-3aee6b4c16f1b4bdfefc5d32f3ee535bf4ed3412.zip
Solutions to challenge 080, both parts, in perl
-rwxr-xr-xchallenge-080/shawn-wagner/perl/ch1.pl18
-rwxr-xr-xchallenge-080/shawn-wagner/perl/ch2.pl18
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-080/shawn-wagner/perl/ch1.pl b/challenge-080/shawn-wagner/perl/ch1.pl
new file mode 100755
index 0000000000..73e21f0063
--- /dev/null
+++ b/challenge-080/shawn-wagner/perl/ch1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use feature qw/say/;
+
+sub task1 {
+ my %nums = map { $_ => 1 } @_;
+ for (my $n = 1; ; $n += 1) {
+ if (!exists $nums{$n}) {
+ say $n;
+ return;
+ }
+ }
+}
+
+task1 5, 2, -2, 0;
+task1 1, 8, -1;
+task1 2, 0, -1;
diff --git a/challenge-080/shawn-wagner/perl/ch2.pl b/challenge-080/shawn-wagner/perl/ch2.pl
new file mode 100755
index 0000000000..446fc708cb
--- /dev/null
+++ b/challenge-080/shawn-wagner/perl/ch2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use feature qw/say/;
+
+sub task2 {
+ my $candies = @_;
+ for (my $n = 0; $n <= $#_; $n += 1) {
+ if (($n > 0 && $_[$n] > $_[$n - 1]) ||
+ ($n < $#_ && $_[$n] > $_[$n + 1])) {
+ $candies += 1;
+ }
+ }
+ say $candies;
+}
+
+task2 1, 2, 2;
+task2 1, 4, 3, 2;