aboutsummaryrefslogtreecommitdiff
path: root/challenge-079
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2020-09-22 07:27:51 -0500
committerboblied <boblied@gmail.com>2020-09-22 07:27:51 -0500
commit6b075dd9c022007fd4711c2401f4f5bee6b68a6e (patch)
tree3e8ed79a545c046a83da1d333e3e3ca713ceb13b /challenge-079
parentf7ec822a30b2abe381fbd33d68e2ab3cae6c35e8 (diff)
downloadperlweeklychallenge-club-6b075dd9c022007fd4711c2401f4f5bee6b68a6e.tar.gz
perlweeklychallenge-club-6b075dd9c022007fd4711c2401f4f5bee6b68a6e.tar.bz2
perlweeklychallenge-club-6b075dd9c022007fd4711c2401f4f5bee6b68a6e.zip
PWC 079 template setup
Diffstat (limited to 'challenge-079')
-rw-r--r--challenge-079/bob-lied/README4
-rwxr-xr-xchallenge-079/bob-lied/perl/ch-1.pl46
-rwxr-xr-xchallenge-079/bob-lied/perl/ch-2.pl56
-rw-r--r--challenge-079/bob-lied/perl/lib/CountSetBit.pm39
-rw-r--r--challenge-079/bob-lied/perl/lib/TrappedRainWater.pm39
-rw-r--r--challenge-079/bob-lied/perl/t/CountSetBit.t14
-rw-r--r--challenge-079/bob-lied/perl/t/TrappedRainWater.t14
7 files changed, 210 insertions, 2 deletions
diff --git a/challenge-079/bob-lied/README b/challenge-079/bob-lied/README
index ac3ae94c19..026576bd98 100644
--- a/challenge-079/bob-lied/README
+++ b/challenge-079/bob-lied/README
@@ -1,3 +1,3 @@
-Solutions to weekly challenge 78 by Bob Lied.
+Solutions to weekly challenge 79 by Bob Lied.
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-079/
diff --git a/challenge-079/bob-lied/perl/ch-1.pl b/challenge-079/bob-lied/perl/ch-1.pl
new file mode 100755
index 0000000000..94893c07d4
--- /dev/null
+++ b/challenge-079/bob-lied/perl/ch-1.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-1.pl
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Perl Weekly Challenge 079 Task #1 > Count Set Bits
+#=============================================================================
+# You are given a positive number $N.
+# Write a script to count the total numbrer of set bits of the binary
+# representations of all numbers from 1 to $N and
+# return $total_count_set_bit % 1000000007.
+# Example 1: Input = 4
+# 1 --> 001 Count = 1
+# 2 --> 010 Count = 1
+# 3 --> 011 Count = 2
+# 4 --> 100 Count = 1
+# TOTAL: 5
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+use Getopt::Long;
+
+use lib "lib";
+use CountSetBit;
+
+sub Usage { "Usage: $0 args" };
+
+my $Verbose = 0;
+GetOptions('verbose' => \$Verbose);
+
+my $arg = shift;
+my @list = @ARGV;
+
+die Usage() unless $arg;
+die Usage() unless @list;
+
+my $task = CountSetBit->new();
+my $result = $task->run();
+say $result;
diff --git a/challenge-079/bob-lied/perl/ch-2.pl b/challenge-079/bob-lied/perl/ch-2.pl
new file mode 100755
index 0000000000..6eafe88497
--- /dev/null
+++ b/challenge-079/bob-lied/perl/ch-2.pl
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# ch-2.pl
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Perl Weekly Challenge 079 Task #2 > Trapped Rain Water
+#=============================================================================
+# You are given an array of positive numbers @N.
+# Write a script to represent it as Histogram Chart and find out how much
+# water it can trap.
+# Example 1: Input: (2, 1, 4, 1, 2, 5)
+# As historgram: 5 #
+# 4 # #
+# 3 # #
+# 2 # # # #
+# 1 # # # # # #
+# _ _ _ _ _ _ _
+# 2 1 4 1 2 5
+# Concave units that can trap water:
+# 5 |
+# 4 | O O |
+# 3 | O O |
+# 2 | O | O _ |
+# 1 | _ | _ | |
+# _ _ _ _ _ _ _
+# 2 1 4 1 2 5
+# Answer: 6
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+use Getopt::Long;
+
+use lib "lib";
+use Task2;
+
+sub Usage { "Usage: $0 args" };
+
+my $Verbose = 0;
+GetOptions('verbose' => \$Verbose);
+
+my $arg = shift;
+my @list = @ARGV;
+
+die Usage() unless $arg;
+die Usage() unless @list;
+
+my $task = Task2->new();
+my $result = $task->run();
+say $result;
diff --git a/challenge-079/bob-lied/perl/lib/CountSetBit.pm b/challenge-079/bob-lied/perl/lib/CountSetBit.pm
new file mode 100644
index 0000000000..37f74ea838
--- /dev/null
+++ b/challenge-079/bob-lied/perl/lib/CountSetBit.pm
@@ -0,0 +1,39 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# CountSetBit.pm
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Description:
+#=============================================================================
+
+package CountSetBit;
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw();
+our @EXPORT_OK = qw();
+
+sub new($class, $name1)
+{
+ $class = ref($class) || $class;
+ my $self = {
+ _name1 => $name1,
+ };
+ bless $self, $class;
+ return $self;
+}
+
+sub run($self)
+{
+ return undef;
+}
+
+1;
diff --git a/challenge-079/bob-lied/perl/lib/TrappedRainWater.pm b/challenge-079/bob-lied/perl/lib/TrappedRainWater.pm
new file mode 100644
index 0000000000..cb98286764
--- /dev/null
+++ b/challenge-079/bob-lied/perl/lib/TrappedRainWater.pm
@@ -0,0 +1,39 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#=============================================================================
+# TrappedRainWater.pm
+#=============================================================================
+# Copyright (c) 2020, Bob Lied
+#=============================================================================
+# Description:
+#=============================================================================
+
+package TrappedRainWater;
+
+use strict;
+use warnings;
+use v5.30;
+
+use feature qw/ signatures /;
+no warnings qw/ experimental::signatures /;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw();
+our @EXPORT_OK = qw();
+
+sub new($class, $name1)
+{
+ $class = ref($class) || $class;
+ my $self = {
+ _name1 => $name1,
+ };
+ bless $self, $class;
+ return $self;
+}
+
+sub run($self)
+{
+ return undef;
+}
+
+1;
diff --git a/challenge-079/bob-lied/perl/t/CountSetBit.t b/challenge-079/bob-lied/perl/t/CountSetBit.t
new file mode 100644
index 0000000000..ff4062688b
--- /dev/null
+++ b/challenge-079/bob-lied/perl/t/CountSetBit.t
@@ -0,0 +1,14 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#
+#===============================================================================
+# FILE: CountSetBit.t
+# DESCRIPTION: Unit test for CountSetBit
+#===============================================================================
+
+use strict;
+use warnings;
+use v5.30;
+
+use Test2::V0;
+
+done_testing();
diff --git a/challenge-079/bob-lied/perl/t/TrappedRainWater.t b/challenge-079/bob-lied/perl/t/TrappedRainWater.t
new file mode 100644
index 0000000000..b40e30679e
--- /dev/null
+++ b/challenge-079/bob-lied/perl/t/TrappedRainWater.t
@@ -0,0 +1,14 @@
+# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu:
+#
+#===============================================================================
+# FILE: TrappedRainWater.t
+# DESCRIPTION: Unit test for TrappedRainWater
+#===============================================================================
+
+use strict;
+use warnings;
+use v5.30;
+
+use Test2::V0;
+
+done_testing();