diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-17 23:12:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-17 23:12:47 +0100 |
| commit | 83c3f1d20a727680b6263e4529ad496934bdcfc5 (patch) | |
| tree | b9f8c62f53fd006dc00feef112302e05cf3d875c | |
| parent | 8282732f9a1003fc54c012c601d85b3451a9f8fc (diff) | |
| parent | 334b8f46cfbe5f0f6687c443cc8ce86ca0cc0c30 (diff) | |
| download | perlweeklychallenge-club-83c3f1d20a727680b6263e4529ad496934bdcfc5.tar.gz perlweeklychallenge-club-83c3f1d20a727680b6263e4529ad496934bdcfc5.tar.bz2 perlweeklychallenge-club-83c3f1d20a727680b6263e4529ad496934bdcfc5.zip | |
Merge pull request #4285 from PerlBoy1967/branch-for-challenge-117
Small optimizations and clean up
| -rwxr-xr-x | challenge-117/perlboy1967/perl/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-117/perlboy1967/perl/ch-2.pl | 10 |
2 files changed, 13 insertions, 8 deletions
diff --git a/challenge-117/perlboy1967/perl/ch-1.pl b/challenge-117/perlboy1967/perl/ch-1.pl index 0252ba108a..109b8e42e7 100755 --- a/challenge-117/perlboy1967/perl/ch-1.pl +++ b/challenge-117/perlboy1967/perl/ch-1.pl @@ -11,14 +11,19 @@ use v5.16; use strict; use warnings; -use File::Slurp; +use File::Basename qw(dirname); use List::MoreUtils qw(slide); -printf "Missing row number(s) of file '%s' is/are '%s'\n", $ARGV[0], join(',',missingRows($ARGV[0])); +my $input = $ARGV[0] // sprintf('%s/input.txt',dirname($0)); + +printf "Missing row number(s) of file '%s' is/are '%s'\n", + $input, join(',',missingRows($input)); sub missingRows { my ($f) = @_; + + open(my $fh,'<',$f) || die; - return grep /\d/,slide{($a+1..$b-1)if($b-$a>1)}sort{$a<=>$b}map{chomp;s/^(\d+).*/$1/;$_}read_file($f); + return grep /\d/,slide{($a+1..$b-1)if($b-$a>1)}sort{$a<=>$b}map{/^(\d+)/;$_=$1}<$fh>; } diff --git a/challenge-117/perlboy1967/perl/ch-2.pl b/challenge-117/perlboy1967/perl/ch-2.pl index 19a3b62f61..a6b0a6f00f 100755 --- a/challenge-117/perlboy1967/perl/ch-2.pl +++ b/challenge-117/perlboy1967/perl/ch-2.pl @@ -11,11 +11,8 @@ use v5.16; use strict; use warnings; -use List::Util qw(sum); - use Test::More; use Test::Deep; -use Data::Printer; # Prototype(s) sub findPossiblePaths($); @@ -29,14 +26,17 @@ my %tests = ( ); foreach my $test (sort keys %tests) { - cmp_deeply (findPossiblePaths($test),$tests{$test},"findPossiblePaths($test)"); + cmp_deeply(findPossiblePaths($test), + $tests{$test}, + "findPossiblePaths($test)"); } done_testing; print "Now some bigger challenges...\n"; for my $size (4 .. 10) { - printf "findPossiblePaths($size) = %d paths\n", scalar @{findPossiblePaths($size)}; + printf "findPossiblePaths($size) = %d paths\n", + scalar @{findPossiblePaths($size)}; } |
