aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-26 23:31:20 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-26 23:32:22 +0000
commit022a9f62eda3b5e188b9f6719a63566d9d7efc8b (patch)
tree7f141de93b08d38f0e5fc5930ec93fc4ef311638
parent8902910406fe11ec55932be70d1df508f61c083d (diff)
downloadperlweeklychallenge-club-022a9f62eda3b5e188b9f6719a63566d9d7efc8b.tar.gz
perlweeklychallenge-club-022a9f62eda3b5e188b9f6719a63566d9d7efc8b.tar.bz2
perlweeklychallenge-club-022a9f62eda3b5e188b9f6719a63566d9d7efc8b.zip
Remove List::Util and Data::Dump dependencies
-rw-r--r--challenge-007/paulo-custodio/perl/ch-1.pl8
-rw-r--r--challenge-008/paulo-custodio/perl/ch-2.pl10
-rw-r--r--challenge-010/paulo-custodio/perl/ch-2.pl21
-rw-r--r--challenge-012/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-014/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-016/paulo-custodio/perl/ch-2.pl1
-rw-r--r--challenge-018/paulo-custodio/perl/ch-1.pl9
-rw-r--r--challenge-021/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-024/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-026/paulo-custodio/perl/ch-2.pl7
-rw-r--r--challenge-076/paulo-custodio/perl/ch-1.pl7
-rw-r--r--challenge-077/paulo-custodio/perl/ch-1.pl7
-rw-r--r--challenge-079/paulo-custodio/perl/ch-1.pl7
-rw-r--r--challenge-079/paulo-custodio/perl/ch-2.pl15
-rw-r--r--challenge-080/paulo-custodio/perl/ch-2.pl7
-rw-r--r--challenge-095/paulo-custodio/perl/ch-2.pl11
-rw-r--r--challenge-096/paulo-custodio/perl/ch-2.pl11
-rw-r--r--challenge-096/paulo-custodio/perl/ch-2a.pl9
18 files changed, 109 insertions, 29 deletions
diff --git a/challenge-007/paulo-custodio/perl/ch-1.pl b/challenge-007/paulo-custodio/perl/ch-1.pl
index ad7c00ff22..d60477d7fa 100644
--- a/challenge-007/paulo-custodio/perl/ch-1.pl
+++ b/challenge-007/paulo-custodio/perl/ch-1.pl
@@ -9,7 +9,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'sum';
sub solve {
my($max) = @_;
@@ -19,5 +18,12 @@ sub solve {
}
}
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
+
+
my $max = shift || 50;
solve($max);
diff --git a/challenge-008/paulo-custodio/perl/ch-2.pl b/challenge-008/paulo-custodio/perl/ch-2.pl
index afea2cc1f9..39d44bd75a 100644
--- a/challenge-008/paulo-custodio/perl/ch-2.pl
+++ b/challenge-008/paulo-custodio/perl/ch-2.pl
@@ -11,7 +11,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'max';
sub center {
my(@lines) = @_;
@@ -20,5 +19,14 @@ sub center {
return @lines;
}
+sub max {
+ my($max, @a) = @_;
+ for (@a) {
+ $max = $_ if $max < $_;
+ }
+ return $max;
+}
+
+
my @lines = center(@ARGV);
say join "\n", @lines;
diff --git a/challenge-010/paulo-custodio/perl/ch-2.pl b/challenge-010/paulo-custodio/perl/ch-2.pl
index 165abd8481..85ea6e9281 100644
--- a/challenge-010/paulo-custodio/perl/ch-2.pl
+++ b/challenge-010/paulo-custodio/perl/ch-2.pl
@@ -9,10 +9,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'max', 'min';
-
-
-use Data::Dump 'dump';
sub jaro_similarity {
my($s1, $s2) = @_;
@@ -88,4 +84,21 @@ sub jaro_winkler_distance {
return 1-jaro_winkler_similarity($s1,$s2);
}
+sub min {
+ my($min, @a) = @_;
+ for (@a) {
+ $min = $_ if $min > $_;
+ }
+ return $min;
+}
+
+sub max {
+ my($max, @a) = @_;
+ for (@a) {
+ $max = $_ if $max < $_;
+ }
+ return $max;
+}
+
+
say jaro_winkler_distance(@ARGV);
diff --git a/challenge-012/paulo-custodio/perl/ch-2.pl b/challenge-012/paulo-custodio/perl/ch-2.pl
index d3d39d2184..8aa3015ae9 100644
--- a/challenge-012/paulo-custodio/perl/ch-2.pl
+++ b/challenge-012/paulo-custodio/perl/ch-2.pl
@@ -17,8 +17,6 @@ use strict;
use warnings;
use 5.030;
-use Data::Dump 'dump';
-
# extract a common prefix, if one exists
sub extract_common_prefix {
my($paths) = @_;
diff --git a/challenge-014/paulo-custodio/perl/ch-2.pl b/challenge-014/paulo-custodio/perl/ch-2.pl
index 0586bf1282..11cacb2bfe 100644
--- a/challenge-014/paulo-custodio/perl/ch-2.pl
+++ b/challenge-014/paulo-custodio/perl/ch-2.pl
@@ -19,8 +19,6 @@ use warnings;
use 5.030;
use Locale::US;
-use Data::Dump 'dump';
-
my $u = Locale::US->new;
my @codes = $u->all_state_codes; # all states two letter codes
my $codes = join("|", @codes); # regex to match any codes
diff --git a/challenge-016/paulo-custodio/perl/ch-2.pl b/challenge-016/paulo-custodio/perl/ch-2.pl
index a497c3f127..6155424257 100644
--- a/challenge-016/paulo-custodio/perl/ch-2.pl
+++ b/challenge-016/paulo-custodio/perl/ch-2.pl
@@ -14,7 +14,6 @@
#
# 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
# 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
-use Data::Dump 'dump';
use strict;
use warnings;
diff --git a/challenge-018/paulo-custodio/perl/ch-1.pl b/challenge-018/paulo-custodio/perl/ch-1.pl
index a7c7d65c34..b79fbe788b 100644
--- a/challenge-018/paulo-custodio/perl/ch-1.pl
+++ b/challenge-018/paulo-custodio/perl/ch-1.pl
@@ -12,7 +12,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'all';
say "(", join(", ", map {$_=qq("$_")} longest_substr(@ARGV)), ")";
@@ -28,7 +27,7 @@ sub longest_substr {
next if $longest_len > $len; # prune search
my $substr = substr($str, $s, $len);
next if $longest{$str}; # prune search
- if (all {/$substr/} @strs) { # matches all
+ if (all(sub {/$substr/}, @strs)) { # matches all
if ($longest_len == $len) {
$longest{$substr}=1;
}
@@ -42,3 +41,9 @@ sub longest_substr {
}
return sort keys %longest;
}
+
+sub all {
+ my($sub, @a) = @_;
+ for (@a) { return if !$sub->($_); }
+ return 1;
+}
diff --git a/challenge-021/paulo-custodio/perl/ch-2.pl b/challenge-021/paulo-custodio/perl/ch-2.pl
index 9fc86e910d..9f4a0fc9aa 100644
--- a/challenge-021/paulo-custodio/perl/ch-2.pl
+++ b/challenge-021/paulo-custodio/perl/ch-2.pl
@@ -15,8 +15,6 @@ use strict;
use warnings;
use 5.030;
-use Data::Dump 'dump';
-
sub decode_triplets {
my($hex) = @_;
my $c = chr(hex($hex));
diff --git a/challenge-024/paulo-custodio/perl/ch-2.pl b/challenge-024/paulo-custodio/perl/ch-2.pl
index 5bd3c85fe5..6c85b9ba4d 100644
--- a/challenge-024/paulo-custodio/perl/ch-2.pl
+++ b/challenge-024/paulo-custodio/perl/ch-2.pl
@@ -25,8 +25,6 @@ use DBD::SQLite;
use Path::Tiny;
use constant DBFILE => "index.db3";
-use Data::Dump 'dump';
-
# Create database if index does not exist
BEGIN {
if (! -f DBFILE) {
diff --git a/challenge-026/paulo-custodio/perl/ch-2.pl b/challenge-026/paulo-custodio/perl/ch-2.pl
index 487024d364..e2a27e4736 100644
--- a/challenge-026/paulo-custodio/perl/ch-2.pl
+++ b/challenge-026/paulo-custodio/perl/ch-2.pl
@@ -10,7 +10,6 @@ use strict;
use warnings;
use 5.030;
use Math::Trig;
-use List::Util 'sum';
say mean(@ARGV);
@@ -31,3 +30,9 @@ sub mean {
$a = rad2deg($a);
return $a;
}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-076/paulo-custodio/perl/ch-1.pl b/challenge-076/paulo-custodio/perl/ch-1.pl
index 1eeef4b579..a3adbf928e 100644
--- a/challenge-076/paulo-custodio/perl/ch-1.pl
+++ b/challenge-076/paulo-custodio/perl/ch-1.pl
@@ -21,7 +21,6 @@ use strict;
use warnings;
use 5.030;
use Math::Combinatorics;
-use List::Util 'sum';
my($N) = shift;
@@ -94,3 +93,9 @@ sub find_set {
}
return @solution;
}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-077/paulo-custodio/perl/ch-1.pl b/challenge-077/paulo-custodio/perl/ch-1.pl
index 03544024a8..7939010631 100644
--- a/challenge-077/paulo-custodio/perl/ch-1.pl
+++ b/challenge-077/paulo-custodio/perl/ch-1.pl
@@ -28,7 +28,6 @@ use strict;
use warnings;
use 5.030;
use Math::Combinatorics;
-use List::Util 'sum';
my($N) = shift;
@@ -59,3 +58,9 @@ sub compute_fib {
push @fib, $fib[-1]+$fib[-2];
}
}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-079/paulo-custodio/perl/ch-1.pl b/challenge-079/paulo-custodio/perl/ch-1.pl
index 2b34fdff7b..dba39d1251 100644
--- a/challenge-079/paulo-custodio/perl/ch-1.pl
+++ b/challenge-079/paulo-custodio/perl/ch-1.pl
@@ -56,7 +56,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'sum';
@ARGV==1 or die "Usage: ch-1.pl N\n";
say(sum(map {bit_count($_)} 1..$ARGV[0]) % 1000000007);
@@ -70,3 +69,9 @@ sub bit_count {
}
return $count;
}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-079/paulo-custodio/perl/ch-2.pl b/challenge-079/paulo-custodio/perl/ch-2.pl
index 8caa2c0c95..1c4248898a 100644
--- a/challenge-079/paulo-custodio/perl/ch-2.pl
+++ b/challenge-079/paulo-custodio/perl/ch-2.pl
@@ -39,7 +39,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'max', 'sum';
@ARGV or die "Usage: ch-2.pl list\n";
my @N = @ARGV;
@@ -71,3 +70,17 @@ sub draw_hist {
}
return @hist;
}
+
+sub max {
+ my($max, @a) = @_;
+ for (@a) {
+ $max = $_ if $max < $_;
+ }
+ return $max;
+}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-080/paulo-custodio/perl/ch-2.pl b/challenge-080/paulo-custodio/perl/ch-2.pl
index b22a6edd3a..10061bdc95 100644
--- a/challenge-080/paulo-custodio/perl/ch-2.pl
+++ b/challenge-080/paulo-custodio/perl/ch-2.pl
@@ -26,7 +26,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'sum';
say candies(@ARGV);
@@ -40,3 +39,9 @@ sub candies {
}
return sum(@candy);
}
+
+sub sum {
+ my($sum, @a) = @_;
+ $sum += $_ for @a;
+ return $sum;
+}
diff --git a/challenge-095/paulo-custodio/perl/ch-2.pl b/challenge-095/paulo-custodio/perl/ch-2.pl
index c2cf2ae54c..b3eace4cb3 100644
--- a/challenge-095/paulo-custodio/perl/ch-2.pl
+++ b/challenge-095/paulo-custodio/perl/ch-2.pl
@@ -27,13 +27,20 @@ use 5.030;
{
package Stack;
- use List::Util;
sub new { my($class) = @_; return bless [], $class; }
sub push { my($self, $n) = @_; push @$self, $n; }
sub pop { my($self) = @_; pop @$self; }
sub top { my($self) = @_; return $self->[-1]; }
- sub min { my($self) = @_; return List::Util::min(@$self); }
+ sub min { my($self) = @_; return min_(@$self); }
+
+ sub min_ {
+ my($min, @a) = @_;
+ for (@a) {
+ $min = $_ if $min > $_;
+ }
+ return $min;
+ }
}
my $stack = Stack->new;
diff --git a/challenge-096/paulo-custodio/perl/ch-2.pl b/challenge-096/paulo-custodio/perl/ch-2.pl
index 5d1b0be743..f2733fc227 100644
--- a/challenge-096/paulo-custodio/perl/ch-2.pl
+++ b/challenge-096/paulo-custodio/perl/ch-2.pl
@@ -30,9 +30,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'min';
-
-use Data::Dump 'dump';
wag_fis_dist(@ARGV);
@@ -112,3 +109,11 @@ sub wag_fis_dist {
}
}
}
+
+sub min {
+ my($min, @a) = @_;
+ for (@a) {
+ $min = $_ if $min > $_;
+ }
+ return $min;
+}
diff --git a/challenge-096/paulo-custodio/perl/ch-2a.pl b/challenge-096/paulo-custodio/perl/ch-2a.pl
index fb0fe511fa..22294b7e03 100644
--- a/challenge-096/paulo-custodio/perl/ch-2a.pl
+++ b/challenge-096/paulo-custodio/perl/ch-2a.pl
@@ -30,7 +30,6 @@
use strict;
use warnings;
use 5.030;
-use List::Util 'min';
# avoid repeated recursive calls of lev_dist
# for the Example 1 reduces from 29737 to 56 calls!
@@ -58,3 +57,11 @@ sub lev_dist {
);
}
}
+
+sub min {
+ my($min, @a) = @_;
+ for (@a) {
+ $min = $_ if $min > $_;
+ }
+ return $min;
+}