diff options
| author | boblied <boblied@gmail.com> | 2020-09-10 22:15:14 -0500 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2020-09-10 22:15:14 -0500 |
| commit | 26b2ab6eb3c0c8d31386c79a3e3b5bed6ac7e2e9 (patch) | |
| tree | 268c33a218c31f97f835a9e20daa398e7fa81536 | |
| parent | 95dc33ff238e2ba288a765870ce72002352b598b (diff) | |
| download | perlweeklychallenge-club-26b2ab6eb3c0c8d31386c79a3e3b5bed6ac7e2e9.tar.gz perlweeklychallenge-club-26b2ab6eb3c0c8d31386c79a3e3b5bed6ac7e2e9.tar.bz2 perlweeklychallenge-club-26b2ab6eb3c0c8d31386c79a3e3b5bed6ac7e2e9.zip | |
Set up files for challenge 077
| -rw-r--r-- | challenge-077/bob-lied/README | 54 | ||||
| -rwxr-xr-x | challenge-077/bob-lied/perl/ch-1.pl | 35 | ||||
| -rwxr-xr-x | challenge-077/bob-lied/perl/ch-2.pl | 40 | ||||
| -rw-r--r-- | challenge-077/bob-lied/perl/lib/FibSum.pm | 38 | ||||
| -rw-r--r-- | challenge-077/bob-lied/perl/lib/LonelyX.pm | 38 | ||||
| -rw-r--r-- | challenge-077/bob-lied/perl/t/FibSum.t | 19 | ||||
| -rw-r--r-- | challenge-077/bob-lied/perl/t/LonelyX.t | 19 |
7 files changed, 191 insertions, 52 deletions
diff --git a/challenge-077/bob-lied/README b/challenge-077/bob-lied/README index e3712fbb10..9deeb88045 100644 --- a/challenge-077/bob-lied/README +++ b/challenge-077/bob-lied/README @@ -1,53 +1,3 @@ -Solutions to weekly challenge 74 by Bob Lied. +Solutions to weekly challenge 77 by Bob Lied. -https://perlweeklychallenge.org/blog/perl-weekly-challenge-074/ - -* TASK #1 > Majority Element - -** Initial thoughts - -This is going to be an exercise in hashes and grep. - -** Post Solution Thoughts - -Use a hash to count to count elements, then use grep with a code block to select the match. - -** Problem Statement - -You are given an array of integers of size $N. -Write a script to find the majority element. If none found then print -1. -Majority element in the list is the one that appears more than floor(size_of_list/2). - - - -* TASK #2 > FNR Character - -** Initial Thoughts - -The specification is a little odd and doesn't match the example. But, OK, whatever. -Similar to the first task, another hash to count occurrences and grep to find the answers. - -** Post Solution Thoughts - -Going through the string could be either done with substr one character at a time, -or splitting the string into an array of characters. Finding the first char could be -a search through the character positions, or a sort and picking off the first element. -Sort is the easy answer, but I'm always wary of scaling. Like in many of these -problems, it's not an issue for "reasonable" strings, but could become a performance -question if the strings were a thousand or a million times bigger. - - -** Problem Statement - -You are given a string $S. - -Write a script to print the series of first non-repeating character -(left -> right) for the given string. Print # if none found. -Example 1 -Input: $S = ‘ababc’ -Output: ‘abb#c’ -Pass 1: “a”, the FNR character is ‘a’ -Pass 2: “ab”, the FNR character is ‘b’ -Pass 3: “aba”, the FNR character is ‘b’ -Pass 4: “abab”, no FNR found, hence ‘#’ -Pass 5: “ababc” the FNR character is ‘c’ +https://perlweeklychallenge.org/blog/perl-weekly-challenge-077/ diff --git a/challenge-077/bob-lied/perl/ch-1.pl b/challenge-077/bob-lied/perl/ch-1.pl new file mode 100755 index 0000000000..faf73a1f34 --- /dev/null +++ b/challenge-077/bob-lied/perl/ch-1.pl @@ -0,0 +1,35 @@ +#!/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 077 Task #1 > Fibonacci Sum +#============================================================================= +# You are given a positive integer $N. +# Write a script to find out all possible combination of Fibonacci Numbers +# required to get $N on addition. +# You are NOT allowed to repeat a number. Print 0 if none found. + +use strict; +use warnings; +use v5.30; + +use feature qw/ signatures /; +no warnings qw/ experimental::signatures /; + +use lib "lib"; +use FibSum; + +sub Usage { "Usage: $0 args" }; + +my $arg = shift; +my @list = @ARGV; + +die Usage() unless $arg; +die Usage() unless @list; + +my $task = FibSum->new(); +my $result = $task->run(); +say $result; diff --git a/challenge-077/bob-lied/perl/ch-2.pl b/challenge-077/bob-lied/perl/ch-2.pl new file mode 100755 index 0000000000..5b945a61b7 --- /dev/null +++ b/challenge-077/bob-lied/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/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 077 Task #2 > Lonely X +#============================================================================= +# You are given m x n character matrix consists of O and X only. +# Write a script to count the total number of X surrounded by O only. +# Print 0 if none found. +# Example 1: +# Input: [ O O X ] +# [ X O O ] +# [ X O O ] +# +# Output: 1 as there is only one X at the first row last column surrounded by only O. + +use strict; +use warnings; +use v5.30; + +use feature qw/ signatures /; +no warnings qw/ experimental::signatures /; + +use lib "lib"; +use LonelyX; + +sub Usage { "Usage: $0 args" }; + +my $arg = shift; +my @list = @ARGV; + +die Usage() unless $arg; +die Usage() unless @list; + +my $task = LonelyX->new(); +my $result = $task->run(); +say $result; diff --git a/challenge-077/bob-lied/perl/lib/FibSum.pm b/challenge-077/bob-lied/perl/lib/FibSum.pm new file mode 100644 index 0000000000..06c02d150e --- /dev/null +++ b/challenge-077/bob-lied/perl/lib/FibSum.pm @@ -0,0 +1,38 @@ +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# FibSum.pm +#============================================================================= +# Copyright (c) 2020, Bob Lied +#============================================================================= +# Description: +#============================================================================= + +package FibSum; + +use strict; +use warnings; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(); +our @EXPORT_OK = qw(); + +sub new +{ + my $class = shift; + $class = ref($class) || $class; + my $self = { + _name1 => $_[0], + }; + bless $self, $class; + return $self; +} + +sub run +{ + my $self = shift; + return undef; +} + +1; + diff --git a/challenge-077/bob-lied/perl/lib/LonelyX.pm b/challenge-077/bob-lied/perl/lib/LonelyX.pm new file mode 100644 index 0000000000..c93169b342 --- /dev/null +++ b/challenge-077/bob-lied/perl/lib/LonelyX.pm @@ -0,0 +1,38 @@ +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# LonelyX.pm +#============================================================================= +# Copyright (c) 2020, Bob Lied +#============================================================================= +# Description: +#============================================================================= + +package LonelyX; + +use strict; +use warnings; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(); +our @EXPORT_OK = qw(); + +sub new +{ + my $class = shift; + $class = ref($class) || $class; + my $self = { + _name1 => $_[0], + }; + bless $self, $class; + return $self; +} + +sub run +{ + my $self = shift; + return undef; +} + +1; + diff --git a/challenge-077/bob-lied/perl/t/FibSum.t b/challenge-077/bob-lied/perl/t/FibSum.t new file mode 100644 index 0000000000..26fff3b59e --- /dev/null +++ b/challenge-077/bob-lied/perl/t/FibSum.t @@ -0,0 +1,19 @@ +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +# +#=============================================================================== +# FILE: FibSum.t +# DESCRIPTION: Unit test for FibSum +#=============================================================================== + +use strict; +use warnings; +use v5.30; + +use Test2::V0; + +use FibSum; + +my $fsum = FibSum->new(); +isa_ok($fsum, "FibSum", "Constructor"); + +done_testing(); diff --git a/challenge-077/bob-lied/perl/t/LonelyX.t b/challenge-077/bob-lied/perl/t/LonelyX.t new file mode 100644 index 0000000000..e0cc63b4a9 --- /dev/null +++ b/challenge-077/bob-lied/perl/t/LonelyX.t @@ -0,0 +1,19 @@ +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +# +#=============================================================================== +# FILE: LonelyX.t +# DESCRIPTION: Unit test for LonelyX +#=============================================================================== + +use strict; +use warnings; +use v5.30; + +use Test2::V0; + +use LonelyX; + +my $lx = LonelyX->new(); +isa_ok($ls, "LonelyX", "Constructor"); + +done_testing(); |
