From 127e524981e50269bf600100aaa0300a33951256 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 23 Sep 2020 00:51:07 +0100 Subject: Add nunovieira220 perl solution to challenge 079 --- challenge-079/nunovieira220/perl/ch-1.pl | 19 +++++++++++++++++++ challenge-079/nunovieira220/perl/ch-2.pl | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 challenge-079/nunovieira220/perl/ch-1.pl create mode 100644 challenge-079/nunovieira220/perl/ch-2.pl 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 -- cgit