diff options
| -rw-r--r-- | challenge-079/nunovieira220/perl/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-079/nunovieira220/perl/ch-2.pl | 22 |
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 |
