aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Vieira <nunovieira220@gmail.com>2020-09-29 20:33:03 +0100
committerNuno Vieira <nunovieira220@gmail.com>2020-09-29 20:33:03 +0100
commitb295e8752d2d6a242ed88274a44a125e722683ce (patch)
tree4e9ab04f3b31112d84375620dfe965731431a170
parent63baf5c0693405f5e3bc3d87a0f523ee712b964c (diff)
downloadperlweeklychallenge-club-b295e8752d2d6a242ed88274a44a125e722683ce.tar.gz
perlweeklychallenge-club-b295e8752d2d6a242ed88274a44a125e722683ce.tar.bz2
perlweeklychallenge-club-b295e8752d2d6a242ed88274a44a125e722683ce.zip
Add nunovieira220 perl solution to challenge 080
-rw-r--r--challenge-080/nunovieira220/perl/ch-1.pl20
-rw-r--r--challenge-080/nunovieira220/perl/ch-2.pl20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-080/nunovieira220/perl/ch-1.pl b/challenge-080/nunovieira220/perl/ch-1.pl
new file mode 100644
index 0000000000..5757a5dd88
--- /dev/null
+++ b/challenge-080/nunovieira220/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use List::Util qw(first);
+
+# Input
+my @A = @ARGV || (5, 2, -2, 0);
+
+# Smallest positive number bits
+my @flags = ();
+
+for (@A) {
+ $flags[$_] = 1 if($_ >= 0);
+}
+
+my $res = first { !defined($flags[$_]) } 1..$#flags;
+
+# Output
+print $res."\n"; \ No newline at end of file
diff --git a/challenge-080/nunovieira220/perl/ch-2.pl b/challenge-080/nunovieira220/perl/ch-2.pl
new file mode 100644
index 0000000000..c5314d8d54
--- /dev/null
+++ b/challenge-080/nunovieira220/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Input
+my @A = @ARGV || (1, 4, 3, 2);
+
+# Count candies
+my $len = scalar @A;
+my $counter = $len;
+
+push @A, ~0;
+
+for (my $i = $len - 1; $i >= 0; $i--) {
+ $counter += ($A[$i] > $A[$i-1]) + ($A[$i] > $A[$i+1]);
+}
+
+# Output
+print $counter."\n"; \ No newline at end of file