aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Vieira <nunovieira220@gmail.com>2020-09-23 00:51:07 +0100
committerNuno Vieira <nunovieira220@gmail.com>2020-09-23 00:51:07 +0100
commit127e524981e50269bf600100aaa0300a33951256 (patch)
treef0e9e34544325bde73361e154e979de69bf2f606
parentc579d650f514f00599f4926994887addcd01a780 (diff)
downloadperlweeklychallenge-club-127e524981e50269bf600100aaa0300a33951256.tar.gz
perlweeklychallenge-club-127e524981e50269bf600100aaa0300a33951256.tar.bz2
perlweeklychallenge-club-127e524981e50269bf600100aaa0300a33951256.zip
Add nunovieira220 perl solution to challenge 079
-rw-r--r--challenge-079/nunovieira220/perl/ch-1.pl19
-rw-r--r--challenge-079/nunovieira220/perl/ch-2.pl22
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-079/nunovieira220/perl/ch-1.pl b/challenge-079/nunovieira220/perl/ch-1.pl
new file mode 100644
index 0000000000..239e31f27c
--- /dev/null
+++ b/challenge-079/nunovieira220/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Input
+my $N = $ARGV[0] || 7;
+
+# Count set bits
+my $counter = 0;
+
+for ((1..$N)) {
+ my $bin = sprintf ("%b", $_);
+ $counter += () = $bin =~ /1/g;
+}
+
+# Output
+my $res = $counter % 1000000007;
+print $res."\n"; \ No newline at end of file
diff --git a/challenge-079/nunovieira220/perl/ch-2.pl b/challenge-079/nunovieira220/perl/ch-2.pl
new file mode 100644
index 0000000000..2b6fff5c3b
--- /dev/null
+++ b/challenge-079/nunovieira220/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Input
+my @list = scalar @ARGV ? @ARGV : (3, 1, 3, 1, 1, 5);
+
+# Trapped rain water counter
+my $counter = 0;
+my $max = 0;
+
+for my $item (@list) {
+ if($item >= $max) {
+ $max = $item;
+ } else {
+ $counter += $max - $item;
+ }
+}
+
+# Output
+print $counter."\n"; \ No newline at end of file